|
|
|
@ -2,19 +2,17 @@ |
|
|
|
|
using System.Text; |
|
|
|
|
using System.Windows.Input; |
|
|
|
|
using HandyControl.Controls; |
|
|
|
|
using log4net; |
|
|
|
|
using Microsoft.Data.Sqlite; |
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using SparkClient.Model.Entity; |
|
|
|
|
using SparkClient.Model.Helper; |
|
|
|
|
using SparkClient.ViewModel.Configuration.SettingsPages; |
|
|
|
|
using MessageBox = SparkClient.Views.Dialog.MessageBox; |
|
|
|
|
|
|
|
|
|
namespace SparkClient.ViewModel.Configuration; |
|
|
|
|
|
|
|
|
|
public class AlgorithmConfigVM : BaseViewModel |
|
|
|
|
{ |
|
|
|
|
private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmConfigVM)); |
|
|
|
|
public ICommand SaveAlgorithmDataCommand { get; } |
|
|
|
|
public ICommand BeautifyJsonCommand { get; } |
|
|
|
|
public ICommand UglifyJsonCommand { get; } |
|
|
|
@ -63,62 +61,54 @@ public class AlgorithmConfigVM : BaseViewModel |
|
|
|
|
/// <param name="param"></param> |
|
|
|
|
public void SaveAlgorithmData(object param) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
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) |
|
|
|
|
AlgorithmConfigEntity entity = new AlgorithmConfigEntity() |
|
|
|
|
{ |
|
|
|
|
AlgorithmConfigEntity entity = new AlgorithmConfigEntity() |
|
|
|
|
{ |
|
|
|
|
GUID = Guid.NewGuid(), |
|
|
|
|
JsonOrder = order++, |
|
|
|
|
Json = temp.Substring(0, 2000), |
|
|
|
|
}; |
|
|
|
|
temp = temp.Substring(2000); |
|
|
|
|
string sql = entity.GenerateInsertSQL(); |
|
|
|
|
SqliteParameter[] sqliteParameters = { |
|
|
|
|
GUID = Guid.NewGuid(), |
|
|
|
|
JsonOrder = order++, |
|
|
|
|
Json = temp.Substring(0, 2000), |
|
|
|
|
}; |
|
|
|
|
temp = temp.Substring(2000); |
|
|
|
|
string sql = entity.GenerateInsertSQL(); |
|
|
|
|
SqliteParameter[] sqliteParameters = { |
|
|
|
|
new SqliteParameter("@Json", entity.Json), |
|
|
|
|
new SqliteParameter("@JsonOrder", entity.JsonOrder), |
|
|
|
|
new SqliteParameter("@GUID", entity.GUID), |
|
|
|
|
}; |
|
|
|
|
insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); |
|
|
|
|
} |
|
|
|
|
if (temp.Length > 0) |
|
|
|
|
insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); |
|
|
|
|
} |
|
|
|
|
if (temp.Length > 0) |
|
|
|
|
{ |
|
|
|
|
AlgorithmConfigEntity entity = new AlgorithmConfigEntity() |
|
|
|
|
{ |
|
|
|
|
AlgorithmConfigEntity entity = new AlgorithmConfigEntity() |
|
|
|
|
{ |
|
|
|
|
GUID = Guid.NewGuid(), |
|
|
|
|
JsonOrder = order++, |
|
|
|
|
Json = temp |
|
|
|
|
}; |
|
|
|
|
string sql = entity.GenerateInsertSQL(); |
|
|
|
|
SqliteParameter[] sqliteParameters = { |
|
|
|
|
GUID = Guid.NewGuid(), |
|
|
|
|
JsonOrder = order++, |
|
|
|
|
Json = temp |
|
|
|
|
}; |
|
|
|
|
string sql = entity.GenerateInsertSQL(); |
|
|
|
|
SqliteParameter[] sqliteParameters = { |
|
|
|
|
new SqliteParameter("@Json", entity.Json), |
|
|
|
|
new SqliteParameter("@JsonOrder", entity.JsonOrder), |
|
|
|
|
new SqliteParameter("@GUID", entity.GUID.ToString()), |
|
|
|
|
}; |
|
|
|
|
insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); |
|
|
|
|
} |
|
|
|
|
if (insertCount >= 0) |
|
|
|
|
{ |
|
|
|
|
Growl.Info(MultilingualHelper.getString("SaveSuccess")); |
|
|
|
|
DataBaseHelper.commit(); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
Growl.Error(MultilingualHelper.getString("SaveFail")); |
|
|
|
|
DataBaseHelper.rollback(); |
|
|
|
|
} |
|
|
|
|
insertCount += DataBaseHelper.ExecuteNonQuery(sql, sqliteParameters); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
if (insertCount >= 0) |
|
|
|
|
{ |
|
|
|
|
Growl.Info(MultilingualHelper.getString("SaveSuccess")); |
|
|
|
|
DataBaseHelper.commit(); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
Growl.Error(MultilingualHelper.getString("SaveFail")); |
|
|
|
|
Logger.Error(ex); |
|
|
|
|
DataBaseHelper.rollback(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
private void IsEnabledByRole (){ |
|
|
|
|