using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.Event; using Aitex.Core.UI.Control; using Aitex.Core.UI.Dialog; using Aitex.Core.UI.MVVM; using Aitex.Core.Util; using Aitex.Core.WCF; using Aitex.Sorter.Common; using Aitex.Sorter.UI.ViewModel; using Hardcodet.Wpf.TaskbarNotification; using MECF.Framework.Common.OperationCenter; using MECF.Framework.UI.Core.Accounts; using MECF.Framework.UI.Core.Applications; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Input; namespace Sorter.UI.ViewModel { public class TopViewModel2 : UIViewModelBase { public string SoftwareVersion { get; set; } [Subscription(ParamName.RTStatus, SystemStateModule)] public int RoutManagerState { get; set; } public string SystemStatus { get { return ((RtState)RoutManagerState).ToString(); } } public string SystemStatusBackground { get { switch (RoutManagerState) { case (int)RtState.Init: return "Yellow"; case (int)RtState.Initializing: case (int)RtState.ManualTransfer: case (int)RtState.Transfer: case (int)RtState.Cycle: case (int)RtState.PrepareCycle: case (int)RtState.PostCycle: case (int)RtState.Reset: case (int)RtState.Processing: case (int)RtState.PostProcess: case (int)RtState.PauseProcess: case (int)RtState.SetSpeed: return "LawnGreen"; case (int)RtState.Error: case (int)RtState.Maintenance: return "Red"; case (int)RtState.Idle: return "Transparent"; default: return "Goldenrod"; } } } [Subscription("Status", "LP1")] public string LoadPort1Status { get; set; } public string LoadPort1StatusBackground { get { return GetUnitStatusBackground(LoadPort1Status); } } [Subscription("Status", "LP2")] public string LoadPort2Status { get; set; } public string LoadPort2StatusBackground { get { return GetUnitStatusBackground(LoadPort2Status); } } [Subscription("LoadportState", "LP3")] public string LoadPort3Status { get; set; } public string LoadPort3StatusBackground { get { return GetUnitStatusBackground(LoadPort3Status); } } [Subscription("LoadportState", "LP4")] public string LoadPort4Status { get; set; } public string LoadPort4StatusBackground { get { return GetUnitStatusBackground(LoadPort4Status); } } [Subscription("Robot.State")] public string RobotStatus { get; set; } public string RobotStatusBackground { get { return GetUnitStatusBackground(RobotStatus); } } [Subscription("System.SignalTower.DeviceData")] public AITSignalTowerData SignalTower { get; set; } [Subscription("System.IsOnlineMode")] public bool IsOnlineMode { get; set; } public string OnlineStatus { get { return IsOnlineMode ? "Online" : "Offline"; } } private bool _simulatorMode = false; [Subscription("System.ServerStatus")] public string ServerStatus { get; set; } public R_TRIG _trig = new R_TRIG(); public bool _clearEventLogEnable; [Subscription("System.ClearEventLogEnable")] public bool ClearEventLogEnable { get; set; //get // { // return _clearEventLogEnable; //} //set //{ // _clearEventLogEnable = value; // if (value) // { // _trig.CLK = value; // if (_trig.Q) // EventLogList.Clear(); // } // else // { // _trig.RST = true; // } //} } [Subscription("CoolingBuffer1.CoolingBuffer1.Status")] public string CoolingBuffer1Status { get; set; } public string _CoolingBuffer1Status => CoolingBuffer1Status == "Disable" ? "" : CoolingBuffer1Status; public string CoolingBuffer1Background { get { return GetUnitStatusBackground(CoolingBuffer1Status); } } [Subscription("CoolingBuffer2.CoolingBuffer2.Status")] public string CoolingBuffer2Status { get; set; } public string _CoolingBuffer2Status => CoolingBuffer2Status == "Disable" ? "" : CoolingBuffer2Status; public string CoolingBuffer2Background { get { return GetUnitStatusBackground(CoolingBuffer2Status); } } [Subscription("Aligner1.Aligner1.Status")] public string Aligner1Status { get; set; } public string _Aligner1Status => Aligner1Status == "Disable" ? "" : Aligner1Status; public string Aligner1Background { get { return GetUnitStatusBackground(Aligner1Status); } } [Subscription("Aligner2.Aligner2.Status")] public string Aligner2Status { get; set; } public string _Aligner2Status => Aligner2Status == "Disable" ? "" : Aligner2Status; public string Aligner2Background { get { return GetUnitStatusBackground(Aligner2Status); } } [Subscription("Status", "Flipper")] public string FlipperStatus { get; set; } public string FlipperBackground { get { return GetUnitStatusBackground(FlipperStatus); } } public string ServerStatusBackground { get { return GetServerStatusBackground(ServerStatus); } } public string GetServerStatusBackground(string status) { return "Transparent"; // if (status != null) // status = status.Trim().ToLower(); //switch (status) //{ // case "unknown": // return "Yellow"; // case "idle": // return "Transparent"; // case "busy": // return "LawnGreen"; // default: // return "Yellow"; //} } public string GetUnitStatusBackground(string status) { if (status != null) status = status.Trim().ToLower(); switch (status) { case "unknown": return "Yellow"; case "idle": return "Transparent"; case "busy": return "LawnGreen"; //case "disable": // return "DarkOrange"; default: return "Yellow"; } } public string TopBackground { get { return ServerStatus == "Connected" ? "ForestGreen" : "Yellow"; } } public string OnlineStatusBackground { get { return IsOnlineMode ? "Transparent" : "Yellow"; } } public string TopViewBackground { get { return _simulatorMode ? "Goldenrod" : "Transparent"; } } public string User { get { return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.AccountId; } } public string Role { get { return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.Role; } } #region Moudle Enable Flag [Subscription("LP1.IsEnable")] public bool LP1Enable { get; set; } [Subscription("LP2.IsEnable")] public bool LP2Enable { get; set; } [Subscription("Aligner1.IsEnable")] public bool Aligner1Enable { get; set; } [Subscription("Aligner2.IsEnable")] public bool Aligner2Enable { get; set; } [Subscription("Buffer.IsEnable")] public bool BufferEnable { get; set; } [Subscription("Buffer1.IsEnable")] public bool Buffer1Enable { get; set; } [Subscription("Buffer2.IsEnable")] public bool Buffer2Enable { get; set; } [Subscription("PMA.IsEnable")] public bool PMAEnable { get; set; } [Subscription("PMB.IsEnable")] public bool PMBEnable { get; set; } [Subscription("CoolingBuffer1.IsEnable")] public bool CoolingBuffer1Enable { get; set; } [Subscription("CoolingBuffer2.IsEnable")] public bool CoolingBuffer2Enable { get; set; } [Subscription("Flipper.IsEnable")] public bool FlipperEnable { get; set; } #endregion Moudle Enable Flag public ICommand SwitchOffBuzzerCommand { get; set; } public ICommand ResetCommand { get; set; } public ICommand LogoffCommand { get; set; } public bool IsEnableOnline { get { return !IsOnlineMode; } } public bool IsEnableOffline { get { return IsOnlineMode; } } private MessageControl _balloonControl; private bool _logoff; public ObservableCollection EventLogList { get; set; } public TopViewModel2() : base("TopViewModel2") { SwitchOffBuzzerCommand = new DelegateCommand(OnSwitchOffBuzzer); ResetCommand = new DelegateCommand(DoReset); LogoffCommand = new DelegateCommand(DoLogoff); SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); InvokePropertyChanged("SoftwareVersion"); EventLogList = new ObservableCollection(); _balloonControl = new MessageControl(); EventClient.Instance.OnEvent += Instance_OnEvent; EventClient.Instance.Start(); } private void Instance_OnEvent(EventItem obj) { if (_logoff) return; switch (obj.Type) { case EventType.EventUI_Notify: LogEvent(obj); break; case EventType.Dialog_Nofity: PopDialog(obj); break; case EventType.KickOut_Notify: break; case EventType.Sound_Notify: break; case EventType.UIMessage_Notify: PopUIMessage(obj); break; } } private void DoLogoff(object obj) { _logoff = true; UiApplication.Instance.Logoff(); } private void DoReset(object obj) { InvokeClient.Instance.Service.DoOperation("System.Reset"); EventLogList.Clear(); if(LP1Enable) InvokeClient.Instance.Service.DoOperation("LP1.LPReset"); if(LP2Enable) InvokeClient.Instance.Service.DoOperation("LP2.LPReset"); } public void Reset() { InvokeClient.Instance.Service.DoOperation(OperationName.ResetAlarm); InvokeClient.Instance.Service.DoOperation(OperationName.ResetDevice); InvokeClient.Instance.Service.DoOperation(OperationName.ResetRouteManager); } private void OnSwitchOffBuzzer(object param) { InvokeClient.Instance.Service.DoOperation("System.SignalTower.SwitchOffBuzzer1"); InvokeClient.Instance.Service.DoOperation("System.SignalTower.SwitchOffBuzzer2"); } private void PopUIMessage(EventItem obj) { Application.Current.Dispatcher.Invoke(new Action(() => { _balloonControl.SetMessage(MessageType.Info, obj.Description); ShowNotifyIcon(2000); })); } private void LogEvent(EventItem obj) { if (obj.Type != EventType.EventUI_Notify) return; Application.Current.Dispatcher.Invoke(new Action(() => { while (EventLogList.Count > 100) { EventLogList.RemoveAt(0); } EventLogList.Add(obj); })); } private void ShowNotifyIcon(int time) { TaskbarIcon icon = new TaskbarIcon(); icon.ShowCustomBalloon(_balloonControl, global::System.Windows.Controls.Primitives.PopupAnimation.Slide, time); } private void PopDialog(EventItem item) { Application.Current.Dispatcher.Invoke(new Action(() => { switch (item.Level) { case EventLevel.Alarm: MessageBoxEx.ShowError(item.Description, item.Explaination); break; case EventLevel.Warning: MessageBoxEx.ShowWarning(item.Description, item.Explaination); break; case EventLevel.Information: MessageBoxEx.ShowInfo(item.Description, item.Explaination); break; } })); } protected override void InvokeBeforeUpdateProperty(Dictionary data) { Application.Current.Dispatcher.Invoke(new Action(() => { _trig.CLK = ClearEventLogEnable; if (_trig.Q) { InvokeClient.Instance.Service.DoOperation("System.Reset"); EventLogList.Clear(); if(LP1Enable) InvokeClient.Instance.Service.DoOperation("LP1.LPReset"); if(LP2Enable) InvokeClient.Instance.Service.DoOperation("LP2.LPReset"); InvokeClient.Instance.Service.DoOperation("System.ClearEventLogEnable"); } })); } } }