123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using System;
- using System.Collections.Generic;
- using MECF.Framework.Common.OperationCenter;
- using OpenSEMI.ClientBase;
- using OpenSEMI.ClientBase.Command;
- namespace Virgo_DUI.Client.Models.Utility.SystemConfig
- {
- public class SystemConfigViewModel : BaseModel
- {
- #region Properties
- private List<ConfigNode> _ConfigNodes = new List<ConfigNode>();
- public List<ConfigNode> ConfigNodes
- {
- get { return _ConfigNodes; }
- set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); }
- }
- private List<ConfigItem> _configItems = null;
- public List<ConfigItem> ConfigItems
- {
- get { return _configItems; }
- set { _configItems = value; NotifyOfPropertyChange("ConfigItems"); }
- }
- string _CurrentNodeName = string.Empty;
- public BaseCommand<ConfigNode> TreeViewSelectedItemChangedCmd { private set; get; }
- #endregion
- #region Functions
- public SystemConfigViewModel()
- {
- this.DisplayName = "System Config";
- TreeViewSelectedItemChangedCmd = new BaseCommand<ConfigNode>(TreeViewSelectedItemChanged);
- }
-
- protected override void OnInitialize()
- {
- base.OnInitialize();
- ConfigNodes = SystemConfigProvider.Instance.GetConfigTree().SubNodes;
- }
- private void TreeViewSelectedItemChanged(ConfigNode node)
- {
- _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{node.Name}";
- ConfigItems = node.Items;
- GetDataOfConfigItems();
- }
- private void GetDataOfConfigItems()
- {
- if (ConfigItems == null)
- return;
- for (int i = 0; i < ConfigItems.Count; i++)
- {
- string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", ConfigItems[i].Name);
- ConfigItems[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(key);
- if (ConfigItems[i].Type == DataType.Bool)
- {
- bool value;
- if (bool.TryParse(ConfigItems[i].CurrentValue, out value))
- ConfigItems[i].BoolValue = value;
- }
- else
- ConfigItems[i].StringValue = ConfigItems[i].CurrentValue;
- }
- }
- public void SetValue(ConfigItem item)
- {
- //key :System.IsSimulatorMode
- //value: true or false 都是字符串
- //input check
- string value;
- if (item.Type == DataType.Bool)
- {
- value = item.BoolValue.ToString().ToLower();
- }
- else
- {
- if (item.TextSaved)
- return;
- if (item.Type == DataType.Int)
- {
- int iValue;
- if (int.TryParse(item.StringValue, out iValue))
- {
- if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
- {
- if (iValue > item.Max || iValue < item.Min)
- {
- DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", ((int)item.Min).ToString(), ((int)item.Max).ToString()));
- return;
- }
- }
- }
- else
- {
- DialogBox.ShowWarning("Please input valid data.");
- return;
- }
- value = item.StringValue;
- }
- else if (item.Type == DataType.Double)
- {
- double fValue;
- if (double.TryParse(item.StringValue, out fValue))
- {
- if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
- {
- if (fValue > item.Max || fValue < item.Min)
- {
- DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", item.Min.ToString(), item.Max.ToString()));
- return;
- }
- }
- }
- else
- {
- DialogBox.ShowWarning("Please input valid data.");
- return;
- }
- value = item.StringValue;
- }
- else
- value = item.StringValue;
- }
- string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", item.Name);
- InvokeClient.Instance.Service.DoOperation("System.SetConfig", key, value);
- item.TextSaved = true;
- Reload();
- }
- public void Reload()
- {
- GetDataOfConfigItems();
- }
- public void SaveAll()
- {
- if (ConfigItems == null)
- return;
- ConfigItems.ForEach(item => SetValue(item));
- }
- #endregion
- }
- }
|