You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.7 KiB
72 lines
1.7 KiB
using System.Windows.Input; |
|
using HandyControl.Controls; |
|
using Newtonsoft.Json; |
|
using Newtonsoft.Json.Linq; |
|
|
|
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) |
|
{ |
|
AlgorithmConfigJson = "{}"; |
|
} |
|
|
|
|
|
/// <summary> |
|
/// 保存数据 |
|
/// </summary> |
|
/// <param name="param"></param> |
|
public void SaveAlgorithmData(object param) |
|
{ |
|
Growl.Info("Saving Algorithm Data"); |
|
} |
|
|
|
/// <summary> |
|
/// 梅花JSON |
|
/// </summary> |
|
/// <param name="param"></param> |
|
public void BeautifyJson(object param) |
|
{ |
|
try |
|
{ |
|
AlgorithmConfigJson = JToken.Parse(AlgorithmConfigJson).ToString(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
Growl.Error(ex.Message); |
|
} |
|
|
|
|
|
} |
|
|
|
/// <summary> |
|
/// 压缩JSON |
|
/// </summary> |
|
/// <param name="param"></param> |
|
public void UglifyJson(object param) |
|
{ |
|
AlgorithmConfigJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(AlgorithmConfigJson)); |
|
} |
|
|
|
|
|
} |