| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 | 
							- using Aitex.Core.UI.MVVM;
 
- using Aitex.Core.Util;
 
- using Aitex.Core.Utilities;
 
- using MECF.Framework.Common.DataCenter;
 
- using MECF.Framework.Common.Equipment;
 
- using MECF.Framework.Common.OperationCenter;
 
- using OpenSEMI.ClientBase;
 
- using System;
 
- using System.Collections.Concurrent;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Reflection;
 
- using System.Threading.Tasks;
 
- using System.Windows;
 
- using System.Windows.Input;
 
- using Aitex.Core.RT.Log;
 
- using MessageBox = Xceed.Wpf.Toolkit.MessageBox;
 
- using PageSCValue = MECF.Framework.UI.Core.View.Common.PageSCValue;
 
- using Prism.Mvvm;
 
- namespace PunkHPX8_MainPages.ViewModels
 
- {
 
-     public enum FACommunicationState
 
-     {
 
-         Disabled,
 
-         Enabled,
 
-         EnabledNotCommunicating,
 
-         EnabledCommunicating,
 
-         WaitCRA,
 
-         WaitDelay,
 
-         WaitCRFromHost,
 
-     }
 
-     public enum FAControlState
 
-     {
 
-         Unknown,
 
-         EquipmentOffline,
 
-         AttemptOnline,
 
-         HostOffline,
 
-         OnlineLocal,
 
-         OnlineRemote,
 
-     }
 
-     public enum FAControlSubState
 
-     {
 
-         Local,
 
-         Remote,
 
-     }
 
-     public enum FASpoolingState
 
-     {
 
-         Active = 1,
 
-         Inactive
 
-     }
 
-     public class FACommandName
 
-     {
 
-         public const string FAEnable = "FAEnable";
 
-         public const string FADisable = "FADisable";
 
-         public const string FAOnline = "FAOnline";
 
-         public const string FAOffline = "FAOffline";
 
-         public const string FALocal = "FALocal";
 
-         public const string FARemote = "FARemote";
 
-         public const string FAEnableSpooling = "FAEnableSpooling";
 
-         public const string FADisableSpooling = "FADisableSpooling";
 
-         public const string FASendTerminalMessage = "FASendTerminalMessage";
 
-     }
 
-     public class FAViewModel : BindableBase
 
-     {
 
-         protected ConcurrentBag<string> _subscribedKeys = new ConcurrentBag<string>();
 
-         protected Func<object, bool> _isSubscriptionAttribute;
 
-         protected Func<MemberInfo, bool> _hasSubscriptionAttribute;
 
-         private class DataName
 
-         {
 
-             public const string CommunicationStatus = "CommunicationStatus";
 
-             public const string ControlStatus = "ControlStatus";
 
-             public const string ControlSubStatus = "ControlSubStatus";
 
-             public const string SpoolingState = "SpoolingState";
 
-             public const string SpoolingActual = "SpoolingActual";
 
-             public const string SpoolingTotal = "SpoolingTotal";
 
-             public const string SpoolingFullTime = "SpoolingFullTime";
 
-             public const string SpoolingStartTime = "SpoolingStartTime";
 
-             public const string IsSpoolingEnable = "IsSpoolingEnable";
 
-             //EFEM
 
-         }
 
-         public FAViewModel()
 
-         {
 
-             ConfigFeedback = new PageSCFA();
 
-             ConfigSetPoint = new PageSCFA();
 
-             SetConfigCommand = new DelegateCommand<object>(SetConfig);
 
-             InvokeCommand = new DelegateCommand<object>(Invoke);
 
-             Initialize();
 
-         }
 
-         protected void Initialize()
 
-         {
 
-             _isSubscriptionAttribute = attribute => attribute is SubscriptionAttribute;
 
-             _hasSubscriptionAttribute = mi => mi.GetCustomAttributes(false).Any(_isSubscriptionAttribute);
 
-             Parallel.ForEach(this.GetType().GetProperties().Where(_hasSubscriptionAttribute),
 
-                 property =>
 
-                 {
 
-                     SubscriptionAttribute subscription = property.GetCustomAttributes(false).First(_isSubscriptionAttribute) as SubscriptionAttribute;
 
-                     string key = subscription.ModuleKey;
 
-                     if (!_subscribedKeys.Contains(key))
 
-                         _subscribedKeys.Add(key);
 
-                 });
 
-             _timer = new PeriodicJob(200, this.OnTimer, "UIUpdaterThread - " + GetType().Name, true);
 
-             ConfigSetPoint.Update(QueryDataClient.Instance.Service.PollConfig(ConfigSetPoint.GetKeys()));
 
-         }
 
-         #region subscrib
 
-         [Subscription(DataName.IsSpoolingEnable, ModuleNameString.System)]
 
-         public bool IsSpoolingEnable
 
-         {
 
-             get { return _isSpoolingEnable; }
 
-             set 
 
-             { 
 
-                 IsEnableSpoolingEnableButton = !value;
 
-                 IsEnableSpoolingDisableButton = value;
 
-                 _isSpoolingEnable = value;
 
-             }
 
-         }
 
-         private bool _isSpoolingEnable = false;
 
-         [Subscription("System.SpoolingState")]
 
-         public string SpoolingState
 
-         {
 
-             get;
 
-             set;
 
-         }
 
-         [Subscription(DataName.SpoolingActual, ModuleNameString.System)]
 
-         public string SpoolingActual
 
-         {
 
-             get;
 
-             set;
 
-         }
 
-         [Subscription(DataName.SpoolingTotal, ModuleNameString.System)]
 
-         public string SpoolingTotal
 
-         {
 
-             get;
 
-             set;
 
-         }
 
-         [Subscription(DataName.SpoolingFullTime, ModuleNameString.System)]
 
-         public string SpoolingFullTime
 
-         {
 
-             get;
 
-             set;
 
-         }
 
-         [Subscription(DataName.SpoolingStartTime, ModuleNameString.System)]
 
-         public string SpoolingStartTime
 
-         {
 
-             get;
 
-             set;
 
-         }
 
-         [Subscription(DataName.ControlStatus, ModuleNameString.System)]
 
-         public string HostControlStatus
 
-         {
 
-             get { return _hostControlStatus; }
 
-             set 
 
-             {
 
-                 IsEnableOnlineButton = FACommunicationState == FACommunicationState.EnabledCommunicating && (value == FAControlState.Unknown.ToString() || value == FAControlState.EquipmentOffline.ToString()); 
 
-                 IsEnableOfflineButton = FACommunicationState == FACommunicationState.EnabledCommunicating && (value == FAControlState.Unknown.ToString() || value != FAControlState.EquipmentOffline.ToString());
 
-                 IsEnableRemoteButton = FACommunicationState == FACommunicationState.EnabledCommunicating&&value==FAControlState.OnlineLocal.ToString();
 
-                 IsEnableLocalButton = FACommunicationState == FACommunicationState.EnabledCommunicating && value == FAControlState.OnlineRemote.ToString();
 
-                 _hostControlStatus = value; 
 
-             }
 
-         }
 
-         private string _hostControlStatus;
 
-         [Subscription(DataName.CommunicationStatus, ModuleNameString.System)]
 
-         public string HostCommunicationStatus
 
-         {
 
-             get { return _hostCommunicationStatus; }
 
-             set 
 
-             {
 
-                 if(_hostCommunicationStatus == FACommunicationState.Disabled.ToString())
 
-                 {
 
-                     IsEnableEnableButton = true;
 
-                     IsEnableDisableButton = false;
 
-                 }
 
-                 else
 
-                 {
 
-                     IsEnableEnableButton = false;
 
-                     IsEnableDisableButton = true;
 
-                 }
 
-                 _hostCommunicationStatus = value;
 
-             }
 
-         }
 
-         private string _hostCommunicationStatus;
 
-         #endregion
 
-         #region  logic
 
-         public FACommunicationState FACommunicationState
 
-         {
 
-             get
 
-             {
 
-                 return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
 
-               : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
 
-             }
 
-         }
 
-         public FAControlState FAControlState
 
-         {
 
-             get
 
-             {
 
-                 return string.IsNullOrEmpty(HostControlStatus) ? FAControlState.Unknown
 
-               : (FAControlState)Enum.Parse(typeof(FAControlState), HostControlStatus);
 
-             }
 
-         }
 
-         //Disabled,
 
-         //Enabled,
 
-         //EnabledNotCommunicating,
 
-         //EnabledCommunicating,
 
-         //WaitCRA,
 
-         //WaitDelay,
 
-         //WaitCRFromHost,
 
-         public bool IsEnableEnableButton
 
-         {
 
-             get { return _isEnableEnableButton; }
 
-             set { SetProperty(ref _isEnableEnableButton, value); }
 
-         }
 
-         private bool _isEnableEnableButton = false;
 
-         public bool IsEnableDisableButton
 
-         {
 
-             get { return _isEnableDisableButton; }
 
-             set { SetProperty(ref _isEnableDisableButton, value); }
 
-         }
 
-         private bool _isEnableDisableButton;
 
-         //Unknown,
 
-         //EquipmentOffline,
 
-         //AttemptOnline,
 
-         //HostOffline,
 
-         //OnlineLocal,
 
-         //OnlineRemote,
 
-         public bool IsEnableOnlineButton
 
-         {
 
-             get { return _isEnableOnlineButton; }
 
-             set { SetProperty(ref _isEnableOnlineButton, value); }
 
-         }
 
-         private bool _isEnableOnlineButton;
 
-         public bool IsEnableOfflineButton
 
-         {
 
-             get { return _isEnableOfflineButton; }
 
-             set { SetProperty(ref _isEnableOfflineButton, value); }
 
-         }
 
-         private bool _isEnableOfflineButton;
 
-         public bool IsEnableLocalButton
 
-         {
 
-             get { return _isEnableLocalButton; }
 
-             set { SetProperty(ref _isEnableLocalButton, value); }
 
-         }
 
-         private bool _isEnableLocalButton;
 
-         public bool IsEnableRemoteButton
 
-         {
 
-             get { return _isEnableRemoteButton; }
 
-             set { SetProperty(ref _isEnableRemoteButton,value); }
 
-         }
 
-         private bool _isEnableRemoteButton;
 
-         public bool IsEnableSpoolingEnableButton
 
-         {
 
-             get
 
-             {
 
-                 return _isEnableSpoolingEnableButton;//SpoolingState == FASpoolingState.Inactive.ToString();
 
-             }
 
-             set
 
-             {
 
-                 SetProperty(ref _isEnableSpoolingEnableButton, value);
 
-             }
 
-         }
 
-         private bool _isEnableSpoolingEnableButton;
 
-         public bool IsEnableSpoolingDisableButton
 
-         {
 
-             get
 
-             {
 
-                 return _isEnableSpoolingDisableButton;// SpoolingState == FASpoolingState.Active.ToString();
 
-             }
 
-             set
 
-             {
 
-                 SetProperty(ref _isEnableSpoolingDisableButton, value);
 
-             }
 
-         }
 
-         private bool _isEnableSpoolingDisableButton;
 
-         #endregion
 
-         [IgnorePropertyChange]
 
-         public PageSCFA ConfigFeedback
 
-         {
 
-             get;
 
-             set;
 
-         }
 
-         [IgnorePropertyChange]
 
-         public PageSCFA ConfigSetPoint
 
-         {
 
-             get;
 
-             set;
 
-         }
 
-         [IgnorePropertyChange]
 
-         public ICommand SetConfigCommand
 
-         {
 
-             get;
 
-             private set;
 
-         }
 
-         [IgnorePropertyChange]
 
-         public ICommand InvokeCommand
 
-         {
 
-             get;
 
-             private set;
 
-         }
 
-         PeriodicJob _timer;
 
-         //protected ConcurrentBag<string> _subscribedKeys = new ConcurrentBag<string>();
 
-         //protected Func<object, bool> _isSubscriptionAttribute;
 
-         //protected Func<MemberInfo, bool> _hasSubscriptionAttribute;
 
-         private void Invoke(object param)
 
-         {
 
-             InvokeClient.Instance.Service.DoOperation("FACommand", ((string)param).Split(',')[1]);
 
-         }
 
-         void SetConfig(object param)
 
-         {
 
-             object[] sc = (object[])param;
 
-             InvokeClient.Instance.Service.DoOperation("System.SetConfig", sc[0].ToString(), sc[1].ToString());
 
-             UpdateConfig();
 
-         }
 
-         public void UpdateConfig()
 
-         {
 
-             ConfigFeedback.Update(QueryDataClient.Instance.Service.PollConfig(ConfigFeedback.GetKeys()));
 
-             this.RaisePropertyChanged("ConfigFeedback");
 
-         }
 
-         private bool OnTimer()
 
-         {
 
-             try
 
-             {
 
-                 Poll();
 
-                 UpdateConfig();
 
-             }
 
-             catch
 
-             {
 
-             }
 
-             return true;
 
-         }
 
-         private void Poll()
 
-         {
 
-             if (_subscribedKeys.Count > 0)
 
-             {
 
-                 Dictionary<string, object> result = QueryDataClient.Instance.Service.PollData(_subscribedKeys);
 
-                 if (result == null)
 
-                 {
 
-                     return;
 
-                 }
 
-                 if (result.Count != _subscribedKeys.Count)
 
-                 {
 
-                     string unknowKeys = string.Empty;
 
-                     foreach (string key in _subscribedKeys)
 
-                     {
 
-                         if (!result.ContainsKey(key))
 
-                         {
 
-                             unknowKeys += key + "\r\n";
 
-                         }
 
-                     }
 
-                     //System.Diagnostics.Debug.Assert(false, unknowKeys);
 
-                 }
 
-                 UpdateValue(result);
 
-             }
 
-         }
 
-         void UpdateValue(Dictionary<string, object> data)
 
-         {
 
-             if (data == null)
 
-                 return;
 
-             UpdateSubscribe(data, this);
 
-         }
 
-         void UpdateSubscribe(Dictionary<string, object> data, object target, string module = null)
 
-         {
 
-             Parallel.ForEach(target.GetType().GetProperties().Where(_hasSubscriptionAttribute),
 
-                 property =>
 
-                 {
 
-                     PropertyInfo pi = (PropertyInfo)property;
 
-                     SubscriptionAttribute subscription = property.GetCustomAttributes(false).First(_isSubscriptionAttribute) as SubscriptionAttribute;
 
-                     string key = subscription.ModuleKey;
 
-                     key = module == null ? key : string.Format("{0}.{1}", module, key);
 
-                     if (_subscribedKeys.Contains(key) && data.ContainsKey(key))
 
-                     {
 
-                         try
 
-                         {
 
-                             var convertedValue = Convert.ChangeType(data[key], pi.PropertyType);
 
-                             var originValue = Convert.ChangeType(pi.GetValue(target, null), pi.PropertyType);
 
-                             if (originValue != convertedValue)
 
-                             {
 
-                                 pi.SetValue(target, convertedValue, null);
 
-                                 RaisePropertyChanged(pi.Name);
 
-                             }
 
-                         }
 
-                         catch
 
-                         {
 
-                         }
 
-                     }
 
-                 });
 
-         }
 
-     }
 
-     public class PageSCFA : PageSCValue
 
-     {
 
-         public string Fa_ConnectionMode { get; set; }
 
-         public string FA_LocalIpAddress { get; set; }
 
-         public int FA_LocalPortNumber { get; set; }
 
-         public string FA_RemoteIpAddress { get; set; }
 
-         public int FA_RemotePortNumber { get; set; }
 
-         public int FA_T3Timeout { get; set; }
 
-         public int FA_T5Timeout { get; set; }
 
-         public int FA_T6Timeout { get; set; }
 
-         public int FA_T7Timeout { get; set; }
 
-         public int FA_T8Timeout { get; set; }
 
-         public bool FA_EnableSpooling { get; set; }
 
-         public int FA_LinkTestInterval { get; set; }
 
-         public string FA_DefaultCommunicationState { get; set; }
 
-         public string FA_DefaultControlState { get; set; }
 
-         public string FA_DefaultControlSubState { get; set; }
 
-         public string FA_DeviceId { get; set; }
 
-         public int FA_SpoolingCapability { get; set; }
 
-         public int FA_SpoolingMaxTransmit { get; set; }
 
-         public string FA_SpoolingFullOverWrite { get; set; }
 
-         public List<string> FA_SpoolingFullOverWriteLst
 
-         {
 
-             get { return new List<string>() { "True", "False" }; }
 
-         }
 
-         public List<string> FA_CommunicateStateLst
 
-         {
 
-             get { return new List<string>() {"Enabled","Disabled" };}
 
-         }
 
-         public List<string> FA_ControlStateLst
 
-         {
 
-             get { return new List<string>() { "Online", "Offline" }; }
 
-         }
 
-         public List<string> FA_ControlSubStateLst
 
-         {
 
-             get { return new List<string>() { "Local", "Remote" }; }
 
-         }
 
-         public PageSCFA()
 
-         {
 
-             UpdateKeys(typeof(PageSCFA).GetProperties());
 
-         }
 
-     }
 
- }
 
 
  |