|
|
|
@ -7,32 +7,35 @@ using Newtonsoft.Json; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using SparkClient.Model.Entity; |
|
|
|
|
using SparkClient.Model.Helper; |
|
|
|
|
using SparkClient.ViewModel.Configuration.SettingsPages; |
|
|
|
|
|
|
|
|
|
namespace SparkClient.ViewModel.Configuration; |
|
|
|
|
|
|
|
|
|
public class AlgorithmConfigVM : BaseViewModel |
|
|
|
|
{ |
|
|
|
|
public ICommand SaveAlgorithmDataCommand { get; } |
|
|
|
|
public ICommand BeautifyJsonCommand { get; } |
|
|
|
|
public ICommand UglifyJsonCommand { get; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string _AlgorithmConfigJson; |
|
|
|
|
public string AlgorithmConfigJson { get { return _AlgorithmConfigJson; } set { _AlgorithmConfigJson = value; OnPropertyChanged("AlgorithmConfigJson"); } } |
|
|
|
|
public AlgorithmConfigVM() |
|
|
|
|
{ |
|
|
|
|
SaveAlgorithmDataCommand = new RelayCommand(SaveAlgorithmData); |
|
|
|
|
BeautifyJsonCommand = new RelayCommand(BeautifyJson); |
|
|
|
|
UglifyJsonCommand = new RelayCommand(UglifyJson); |
|
|
|
|
InitAlgorithmData(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 初始化算法数据 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="param"></param> |
|
|
|
|
public void InitAlgorithmData(object param) |
|
|
|
|
{ |
|
|
|
|
public ICommand SaveAlgorithmDataCommand { get; } |
|
|
|
|
public ICommand BeautifyJsonCommand { get; } |
|
|
|
|
public ICommand UglifyJsonCommand { get; } |
|
|
|
|
|
|
|
|
|
private bool _isEnabled; |
|
|
|
|
public bool IsEnabled { get { return _isEnabled; } set { _isEnabled = value; OnPropertyChanged(nameof(IsEnabled)); } } |
|
|
|
|
|
|
|
|
|
private string _AlgorithmConfigJson; |
|
|
|
|
public string AlgorithmConfigJson { get { return _AlgorithmConfigJson; } set { _AlgorithmConfigJson = value; OnPropertyChanged("AlgorithmConfigJson"); } } |
|
|
|
|
public AlgorithmConfigVM() |
|
|
|
|
{ |
|
|
|
|
SaveAlgorithmDataCommand = new RelayCommand(SaveAlgorithmData); |
|
|
|
|
BeautifyJsonCommand = new RelayCommand(BeautifyJson); |
|
|
|
|
UglifyJsonCommand = new RelayCommand(UglifyJson); |
|
|
|
|
InitAlgorithmData(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 初始化算法数据 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="param"></param> |
|
|
|
|
public void InitAlgorithmData(object param) |
|
|
|
|
{ |
|
|
|
|
AlgorithmConfigJson = "{}"; |
|
|
|
|
string sql = @"SELECT JSON as json FROM ALGORITHM_CONFIG ORDER BY JSON_ORDER"; |
|
|
|
|
DataTable dataTable = DataBaseHelper.ExecuteQuery(sql); |
|
|
|
@ -44,26 +47,26 @@ public class AlgorithmConfigVM : BaseViewModel |
|
|
|
|
sb.Append(row["json"].ToString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(sb.Length>0) |
|
|
|
|
if (sb.Length > 0) |
|
|
|
|
{ |
|
|
|
|
AlgorithmConfigJson = JToken.Parse(sb.ToString()).ToString(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 保存数据 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="param"></param> |
|
|
|
|
public void SaveAlgorithmData(object param) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 保存数据 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="param"></param> |
|
|
|
|
public void SaveAlgorithmData(object param) |
|
|
|
|
{ |
|
|
|
|
DataBaseHelper.BeginTransaction(); |
|
|
|
|
string temp = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(AlgorithmConfigJson)); |
|
|
|
|
string deleteSql = @"DELETE FROM ALGORITHM_CONFIG"; |
|
|
|
|
DataBaseHelper.ExecuteNonQuery(deleteSql); |
|
|
|
|
int order = 0; |
|
|
|
|
int insertCount = 0; |
|
|
|
|
while (temp.Length>2000) |
|
|
|
|
while (temp.Length > 2000) |
|
|
|
|
{ |
|
|
|
|
AlgorithmConfigEntity entity = new AlgorithmConfigEntity() |
|
|
|
|
{ |
|
|
|
@ -80,7 +83,7 @@ public class AlgorithmConfigVM : BaseViewModel |
|
|
|
|
}; |
|
|
|
|
insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); |
|
|
|
|
} |
|
|
|
|
if (temp.Length>0) |
|
|
|
|
if (temp.Length > 0) |
|
|
|
|
{ |
|
|
|
|
AlgorithmConfigEntity entity = new AlgorithmConfigEntity() |
|
|
|
|
{ |
|
|
|
@ -106,8 +109,18 @@ public class AlgorithmConfigVM : BaseViewModel |
|
|
|
|
Growl.Error(MultilingualHelper.getString("SaveFail")); |
|
|
|
|
DataBaseHelper.rollback(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
private void IsEnabledByRole (){ |
|
|
|
|
string PERMISSIONS = Settings.SelectValueByName("PERMISSIONS"); |
|
|
|
|
if ("admin".Equals(PERMISSIONS)) |
|
|
|
|
{ |
|
|
|
|
IsEnabled = true; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
IsEnabled = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// <summary> |
|
|
|
|
/// 美化JSON |
|
|
|
|
/// </summary> |
|
|
|
@ -122,8 +135,6 @@ public class AlgorithmConfigVM : BaseViewModel |
|
|
|
|
{ |
|
|
|
|
Growl.ErrorGlobal(ex.Message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|