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 cmd = p.GetValue(this, null) as DelegateCommand; if (cmd != null) cmd.RaiseCanExecuteChanged(); } } FieldInfo[] fi = this.GetType().GetFields(); foreach (FieldInfo p in fi) { InvokePropertyChanged(p.Name); if (p.FieldType == typeof(ICommand)) { DelegateCommand cmd = p.GetValue(this) as DelegateCommand; 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 _keys = new List() { 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(SetConfig); SaveAsConfigCommand = new DelegateCommand(SaveAsConfig); LoadConfigCommand = new DelegateCommand(LoadConfig); SetAllConfigCommand = new DelegateCommand(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(@""); 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 data) { Dictionary configs = Triton160UiSystem.Instance.WCF.Query.PollConfig(_keys); foreach (KeyValuePair 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; } } } } }