123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Text;
- using System.Windows;
- using System.Windows.Forms;
- using System.Windows.Input;
- using System.Xml;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Device.Common;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Utilities;
- using Aitex.Triton160.Common;
- using MessageBox = System.Windows.MessageBox;
- namespace Aitex.Triton160.UI.ViewModel
- {
- public class ProcessConfigData : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public void InvokePropertyChanged(string propertyName)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- public void InvokePropertyChanged()
- {
- PropertyInfo[] ps = this.GetType().GetProperties();
- foreach (PropertyInfo p in ps)
- {
- InvokePropertyChanged(p.Name);
- if (p.PropertyType == typeof(ICommand))
- {
- DelegateCommand<string> cmd = p.GetValue(this, null) as DelegateCommand<string>;
- if (cmd != null)
- cmd.RaiseCanExecuteChanged();
- }
- }
- FieldInfo[] fi = this.GetType().GetFields();
- foreach (FieldInfo p in fi)
- {
- InvokePropertyChanged(p.Name);
- if (p.FieldType == typeof(ICommand))
- {
- DelegateCommand<string> cmd = p.GetValue(this) as DelegateCommand<string>;
- if (cmd != null)
- cmd.RaiseCanExecuteChanged();
- }
- }
- }
- public string VentTimeLimit
- {
- get;
- set;
- }
- public string VentTime
- {
- get;
- set;
- }
- public string PurgePumpTimeLimit
- {
- get;
- set;
- }
- public string PurgePumpStableTime
- {
- get;
- set;
- }
- public string PurgePumpPressure
- {
- get;
- set;
- }
- public string PurgeVentTimeLimit
- {
- get;
- set;
- }
- public string PurgeVentStableTime
- {
- get;
- set;
- }
- public string PurgeVentPressure
- {
- get;
- set;
- }
- public string PurgeCycleCount
- {
- get;
- set;
- }
- public string GasFlowPressureAlarmTime
- {
- get;
- set;
- }
- public string GasFlowPressureAlarmRange
- {
- get;
- set;
- }
- public string RfPowerAlarmRange
- {
- get;
- set;
- }
- public string RfPowerAlarmTime
- {
- get;
- set;
- }
- public string RfReflectPowerAlarmRange
- {
- get;
- set;
- }
- public string RfReflectPowerAlarmTime
- {
- get;
- set;
- }
- public string RfMatchModeDuringProcess
- {
- get;
- set;
- }
- }
- class ProcessConfigViewModel : UIViewModelBase
- {
- private List<string> _keys = new List<string>()
- {
- SCName.System_VentTimeLimit,
- SCName.ProcessConfig_PurgePumpTimeLimit,
- SCName.ProcessConfig_PurgePumpStableTime,
- SCName.ProcessConfig_PurgePumpPressure,
- SCName.ProcessConfig_PurgeVentTimeLimit,
- SCName.ProcessConfig_PurgeVentStableTime,
- SCName.ProcessConfig_PurgeVentPressure,
- SCName.ProcessConfig_PurgeCycleCount,
- SCName.System_GasFlowPressureAlarmTime,
- SCName.System_GasFlowPressureAlarmRange,
- SCName.System_RfPowerAlarmRange,
- SCName.System_RfPowerAlarmTime,
- SCName.System_RfReflectPowerAlarmRange,
- SCName.System_RfReflectPowerAlarmTime,
- SCName.System_VentTime,
-
- SCName.System_RfMatchModeDuringProcess,
- };
- public ProcessConfigData Feedback
- {
- get;
- set;
- }
- [IgnorePropertyChange]
- public ProcessConfigData SetPoint
- {
- get;
- set;
- }
- public ICommand SetConfigCommand
- {
- get;
- private set;
- }
- public ICommand SaveAsConfigCommand
- {
- get;
- private set;
- }
- public ICommand LoadConfigCommand
- {
- get;
- private set;
- }
- public ICommand SetAllConfigCommand
- {
- get;
- private set;
- }
- public ProcessConfigViewModel()
- : base("ProcessConfigViewModel")
- {
- SetConfigCommand = new DelegateCommand<object>(SetConfig);
- SaveAsConfigCommand = new DelegateCommand<object>(SaveAsConfig);
- LoadConfigCommand = new DelegateCommand<object>(LoadConfig);
- SetAllConfigCommand = new DelegateCommand<object>(SetAllConfig);
- Feedback = new ProcessConfigData();
- SetPoint = new ProcessConfigData();
- }
- private void SaveAsConfig(object param)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.DefaultExt = ".cfg";
- sfd.Filter = ".cfg|*.*";
- sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- sfd.FileName = string.Format("process_config_{0}.cfg", DateTime.Now.ToString("yyyyMMdd_HHmmssfff"));
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(@"<?xml version='1.0' encoding='utf-8'?><Aitex><ProcessConfigs></ProcessConfigs></Aitex>");
- CreateNode(xml, "GasFlowPressureAlarmRange", Feedback.GasFlowPressureAlarmRange);
- CreateNode(xml, "GasFlowPressureAlarmTime", Feedback.GasFlowPressureAlarmTime);
- CreateNode(xml, "RfMatchModeDuringProcess", Feedback.RfMatchModeDuringProcess);
- CreateNode(xml, "PurgeCycleCount", Feedback.PurgeCycleCount);
- CreateNode(xml, "PurgePumpPressure", Feedback.PurgePumpPressure);
- CreateNode(xml, "PurgePumpStableTime", Feedback.PurgePumpStableTime);
- CreateNode(xml, "PurgePumpTimeLimit", Feedback.PurgePumpTimeLimit);
- CreateNode(xml, "PurgeVentPressure", Feedback.PurgeVentPressure);
- CreateNode(xml, "PurgeVentStableTime", Feedback.PurgeVentStableTime);
- CreateNode(xml, "PurgeVentTimeLimit", Feedback.PurgeVentTimeLimit);
- CreateNode(xml, "RfPowerAlarmRange", Feedback.RfPowerAlarmRange);
- CreateNode(xml, "RfPowerAlarmTime", Feedback.RfPowerAlarmTime);
- CreateNode(xml, "RfReflectPowerAlarmRange", Feedback.RfReflectPowerAlarmRange);
- CreateNode(xml, "RfReflectPowerAlarmTime", Feedback.RfReflectPowerAlarmTime);
- CreateNode(xml, "VentTime", Feedback.VentTime);
- CreateNode(xml, "VentTimeLimit", Feedback.VentTimeLimit);
- try
- {
- xml.Save(sfd.FileName);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Save Error", MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- }
- void CreateNode(XmlDocument xmlDoc, string name, string value)
- {
- XmlNode node = xmlDoc.CreateElement("ProcessConfig");
- XmlAttribute attrName = xmlDoc.CreateAttribute("Name");
- attrName.Value = name;
- node.Attributes.Append(attrName);
- XmlAttribute attrValue = xmlDoc.CreateAttribute("Value");
- attrValue.Value = value;
- node.Attributes.Append(attrValue);
- xmlDoc.SelectSingleNode("Aitex/ProcessConfigs").AppendChild(node);
- }
- private void LoadConfig(object param)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.DefaultExt = ".cfg";
- ofd.Filter = ".cfg|*.*";
- ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- XmlDocument xml = new XmlDocument();
- try
- {
- xml.Load(ofd.FileName);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Open Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
- return;
- }
- SetPoint.GasFlowPressureAlarmRange = GetNodeValue(xml, "GasFlowPressureAlarmRange", SetPoint.GasFlowPressureAlarmRange);
- SetPoint.InvokePropertyChanged("GasFlowPressureAlarmRange");
- SetPoint.GasFlowPressureAlarmTime = GetNodeValue(xml, "GasFlowPressureAlarmTime", SetPoint.GasFlowPressureAlarmTime);
- SetPoint.InvokePropertyChanged("GasFlowPressureAlarmTime");
- SetPoint.RfMatchModeDuringProcess = GetNodeValue(xml, "RfMatchModeDuringProcess", SetPoint.RfMatchModeDuringProcess);
- SetPoint.InvokePropertyChanged("RfMatchModeDuringProcess");
- SetPoint.PurgeCycleCount = GetNodeValue(xml, "PurgeCycleCount", SetPoint.PurgeCycleCount);
- SetPoint.InvokePropertyChanged("PurgeCycleCount");
- SetPoint.PurgePumpPressure = GetNodeValue(xml, "PurgePumpPressure", SetPoint.PurgePumpPressure);
- SetPoint.InvokePropertyChanged("PurgePumpPressure");
- SetPoint.PurgePumpStableTime = GetNodeValue(xml, "PurgePumpStableTime", SetPoint.PurgePumpStableTime);
- SetPoint.InvokePropertyChanged("PurgePumpStableTime");
- SetPoint.PurgePumpTimeLimit = GetNodeValue(xml, "PurgePumpTimeLimit", SetPoint.PurgePumpTimeLimit);
- SetPoint.InvokePropertyChanged("PurgePumpTimeLimit");
- SetPoint.PurgeVentPressure = GetNodeValue(xml, "PurgeVentPressure", SetPoint.PurgeVentPressure);
- SetPoint.InvokePropertyChanged("PurgeVentPressure");
- SetPoint.PurgeVentStableTime = GetNodeValue(xml, "PurgeVentStableTime", SetPoint.PurgeVentStableTime);
- SetPoint.InvokePropertyChanged("PurgeVentStableTime");
- SetPoint.PurgeVentTimeLimit = GetNodeValue(xml, "PurgeVentTimeLimit", SetPoint.PurgeVentTimeLimit);
- SetPoint.InvokePropertyChanged("PurgeVentTimeLimit");
- SetPoint.RfPowerAlarmRange = GetNodeValue(xml, "RfPowerAlarmRange", SetPoint.RfPowerAlarmRange);
- SetPoint.InvokePropertyChanged("RfPowerAlarmRange");
- SetPoint.RfPowerAlarmTime = GetNodeValue(xml, "RfPowerAlarmTime", SetPoint.RfPowerAlarmTime);
- SetPoint.InvokePropertyChanged("RfPowerAlarmTime");
- SetPoint.RfReflectPowerAlarmRange = GetNodeValue(xml, "RfReflectPowerAlarmRange", SetPoint.RfReflectPowerAlarmRange);
- SetPoint.InvokePropertyChanged("RfReflectPowerAlarmRange");
- SetPoint.RfReflectPowerAlarmTime = GetNodeValue(xml, "RfReflectPowerAlarmTime", SetPoint.RfReflectPowerAlarmTime);
- SetPoint.InvokePropertyChanged("RfReflectPowerAlarmTime");
- SetPoint.VentTime = GetNodeValue(xml, "VentTime", SetPoint.VentTime);
- SetPoint.InvokePropertyChanged("VentTime");
- SetPoint.VentTimeLimit = GetNodeValue(xml, "VentTimeLimit", SetPoint.VentTimeLimit);
- SetPoint.InvokePropertyChanged("VentTimeLimit");
- }
- }
- string GetNodeValue(XmlDocument xmlDoc, string configItem, string defaultValue)
- {
- try
- {
- XmlNode node = xmlDoc.SelectSingleNode(string.Format("Aitex/ProcessConfigs/ProcessConfig[@Name='{0}']", configItem));
- if (node != null)
- {
- return node.Attributes["Value"].InnerText;
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- return defaultValue;
- }
- private void SetAllConfig(object param)
- {
- if (SetPoint.GasFlowPressureAlarmRange != Feedback.GasFlowPressureAlarmRange)
- SetConfig("GasFlowPressureAlarmRange");
- if (SetPoint.GasFlowPressureAlarmTime != Feedback.GasFlowPressureAlarmTime)
- SetConfig("GasFlowPressureAlarmTime");
- if (SetPoint.RfMatchModeDuringProcess != Feedback.RfMatchModeDuringProcess)
- SetConfig("RfMatchModeDuringProcess");
- if (SetPoint.PurgeCycleCount != Feedback.PurgeCycleCount)
- SetConfig("PurgeCycleCount");
- if (SetPoint.PurgePumpPressure != Feedback.PurgePumpPressure)
- SetConfig("PurgePumpPressure");
- if (SetPoint.PurgePumpStableTime != Feedback.PurgePumpStableTime)
- SetConfig("PurgePumpStableTime");
- if (SetPoint.PurgePumpTimeLimit != Feedback.PurgePumpTimeLimit)
- SetConfig("PurgePumpTimeLimit");
- if (SetPoint.PurgeVentPressure != Feedback.PurgeVentPressure)
- SetConfig("PurgeVentPressure");
- if (SetPoint.PurgeVentStableTime != Feedback.PurgeVentStableTime)
- SetConfig("PurgeVentStableTime");
- if (SetPoint.PurgeVentTimeLimit != Feedback.PurgeVentTimeLimit)
- SetConfig("PurgeVentTimeLimit");
- if (SetPoint.RfPowerAlarmRange != Feedback.RfPowerAlarmRange)
- SetConfig("RfPowerAlarmRange");
- if (SetPoint.RfPowerAlarmTime != Feedback.RfPowerAlarmTime)
- SetConfig("RfPowerAlarmTime");
- if (SetPoint.RfReflectPowerAlarmRange != Feedback.RfReflectPowerAlarmRange)
- SetConfig("RfReflectPowerAlarmRange");
- if (SetPoint.RfReflectPowerAlarmTime != Feedback.RfReflectPowerAlarmTime)
- SetConfig("RfReflectPowerAlarmTime");
- if (SetPoint.VentTime != Feedback.VentTime)
- SetConfig("VentTime");
- if (SetPoint.VentTimeLimit != Feedback.VentTimeLimit)
- SetConfig("VentTimeLimit");
- }
- void SetConfig(object param)
- {
- string config = param.ToString();
- string value = "";
- string scName = "";
- switch (config)
- {
- case "VentTimeLimit":
- value = SetPoint.VentTimeLimit;
- scName = SCName.System_VentTimeLimit;
- break;
- case "VentTime":
- value = SetPoint.VentTime;
- scName = SCName.System_VentTime;
- break;
- case "PurgePumpTimeLimit":
- value = SetPoint.PurgePumpTimeLimit;
- scName = SCName.ProcessConfig_PurgePumpTimeLimit;
- break;
- case "PurgePumpStableTime":
- value = SetPoint.PurgePumpStableTime;
- scName = SCName.ProcessConfig_PurgePumpStableTime;
- break;
- case "PurgePumpPressure":
- value = SetPoint.PurgePumpPressure;
- scName = SCName.ProcessConfig_PurgePumpPressure;
- break;
- case "PurgeVentTimeLimit":
- value = SetPoint.PurgeVentTimeLimit;
- scName = SCName.ProcessConfig_PurgeVentTimeLimit;
- break;
- case "PurgeVentStableTime":
- value = SetPoint.PurgeVentStableTime;
- scName = SCName.ProcessConfig_PurgeVentStableTime;
- break;
- case "PurgeVentPressure":
- value = SetPoint.PurgeVentPressure;
- scName = SCName.ProcessConfig_PurgeVentPressure;
- break;
- case "PurgeCycleCount":
- value = SetPoint.PurgeCycleCount;
- scName = SCName.ProcessConfig_PurgeCycleCount;
- break;
- case "GasFlowPressureAlarmTime":
- value = SetPoint.GasFlowPressureAlarmTime;
- scName = SCName.System_GasFlowPressureAlarmTime;
- break;
- case "GasFlowPressureAlarmRange":
- value = SetPoint.GasFlowPressureAlarmRange;
- scName = SCName.System_GasFlowPressureAlarmRange;
- break;
- case "RfPowerAlarmRange":
- value = SetPoint.RfPowerAlarmRange;
- scName = SCName.System_RfPowerAlarmRange;
- break;
- case "RfPowerAlarmTime":
- value = SetPoint.RfPowerAlarmTime;
- scName = SCName.System_RfPowerAlarmTime;
- break;
- case "RfReflectPowerAlarmRange":
- value = SetPoint.RfReflectPowerAlarmRange;
- scName = SCName.System_RfReflectPowerAlarmRange;
- break;
- case "RfReflectPowerAlarmTime":
- value = SetPoint.RfReflectPowerAlarmTime;
- scName = SCName.System_RfReflectPowerAlarmTime;
- break;
- case "RfMatchModeDuringProcess":
- value = SetPoint.RfMatchModeDuringProcess == "Manual" ? "0" : "1";
- scName = SCName.System_RfMatchModeDuringProcess;
- break;
- }
- if (string.IsNullOrEmpty(value))
- {
- MessageBox.Show(string.Format(Aitex.Triton160.UI.Properties.Resources.ProcessConfigViewModel_SetConfig_SetPoint0IsNotValid, value));
- return;
- }
- Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.SetConfig.ToString(), scName, value);
- }
- protected override void Poll()
- //protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
- {
- Dictionary<string, object> configs = Triton160UiSystem.Instance.WCF.Query.PollConfig(_keys);
- foreach (KeyValuePair<string, object> config in configs)
- {
- switch (config.Key)
- {
- case SCName.System_VentTime:
- Feedback.VentTime = config.Value.ToString();
- break;
- case SCName.System_VentTimeLimit:
- Feedback.VentTimeLimit = config.Value.ToString();
- break;
- case SCName.ProcessConfig_PurgePumpTimeLimit:
- Feedback.PurgePumpTimeLimit = config.Value.ToString();
- break;
- case SCName.ProcessConfig_PurgePumpStableTime:
- Feedback.PurgePumpStableTime = config.Value.ToString();
- break;
- case SCName.ProcessConfig_PurgePumpPressure:
- Feedback.PurgePumpPressure = config.Value.ToString();
- break;
- case SCName.ProcessConfig_PurgeVentTimeLimit:
- Feedback.PurgeVentTimeLimit = config.Value.ToString();
- break;
- case SCName.ProcessConfig_PurgeVentStableTime:
- Feedback.PurgeVentStableTime = config.Value.ToString();
- break;
- case SCName.ProcessConfig_PurgeVentPressure:
- Feedback.PurgeVentPressure = config.Value.ToString();
- break;
- case SCName.ProcessConfig_PurgeCycleCount:
- Feedback.PurgeCycleCount = config.Value.ToString();
- break;
- case SCName.System_GasFlowPressureAlarmTime:
- Feedback.GasFlowPressureAlarmTime = config.Value.ToString();
- break;
- case SCName.System_GasFlowPressureAlarmRange:
- Feedback.GasFlowPressureAlarmRange = config.Value.ToString();
- break;
- case SCName.System_RfPowerAlarmRange:
- Feedback.RfPowerAlarmRange = config.Value.ToString();
- break;
- case SCName.System_RfPowerAlarmTime:
- Feedback.RfPowerAlarmTime = config.Value.ToString();
- break;
- case SCName.System_RfReflectPowerAlarmRange:
- Feedback.RfReflectPowerAlarmRange = config.Value.ToString();
- break;
- case SCName.System_RfReflectPowerAlarmTime:
- Feedback.RfReflectPowerAlarmTime = config.Value.ToString();
- break;
- case SCName.System_RfMatchModeDuringProcess:
- Feedback.RfMatchModeDuringProcess = config.Value.ToString() == "0" ? "Manual" : "Auto";
- break;
- }
- }
- }
- }
- }
|