123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- 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.Utilities;
- using Aitex.Core.WCF;
- using Aitex.Sorter.Common;
- using Hardcodet.Wpf.TaskbarNotification;
- using MECF.Framework.Common.CommonData;
- 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.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- namespace Aitex.Sorter.UI.ViewModel
- {
- public class TerminalMessageItem : NotifiableItem
- {
- public string MessageTime { get; set; }
- public string Type { get; set; }
- public string Content { get; set; }
- public string Title
- {
- get { return MessageTime + " (" + Type + ")"; }
- }
- }
- public class TopViewSubModel : UIViewModelBase
- {
- private int loadPortCount = 10;
- public string SoftwareVersion
- {
- get;
- set;
- }
- private string companyName;
- public string CompanyName
- {
- get { return companyName; }
- set {
- companyName=value;
- InvokePropertyChanged("CompanyName");
- }
- }
- private string showDateTime;
- public string ShowDateTime
- {
- get { return showDateTime; }
- set
- {
- showDateTime = value;
- InvokePropertyChanged("ShowDateTime");
- }
- }
- [Subscription(ParamName.ControlStatus, SystemStateModule)]
- public string HostControlStatus
- {
- get;
- set;
- }
- public string HostControlStatusBackground
- {
- get
- {
- switch (HostControlStatus)
- {
- case "Unknown":
- return "Yellow";
- case "EquipmentOffline":
- case "AttemptOnline":
- case "HostOffline":
- return "Transparent";
- case "OnlineLocal":
- case "OnlineRemote":
- return "LawnGreen";
- default:
- return "Yellow";
- }
- }
- }
- [Subscription(ParamName.CommunicationStatus, SystemStateModule)]
- public string HostCommunicationStatus
- {
- get;
- set;
- }
- /// Disabled = 0,
- /// Enabled = 1,
- /// EnabledNotCommunicating = 2,
- /// EnabledCommunicating = 3,
- /// WaitCRA = 4,
- /// WaitDelay = 5,
- /// WaitCRFromHost = 6,
- public string HostCommunicationStatusBackground
- {
- get
- {
- switch (HostCommunicationStatus)
- {
- case "Disabled":
- return "Yellow";
- case "Enabled":
- case "EnabledNotCommunicating":
- case "WaitCRA":
- case "WaitDelay":
- case "WaitCRFromHost":
- return "Transparent";
- case "EnabledCommunicating":
- return "LawnGreen";
- default:
- return "Yellow";
- }
- }
- }
- [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";
- }
- }
- }
- protected override void Poll()
- {
- for (int i = 0; i < loadPortCount; i++)
- {
- Subscribe($"LP{i+1}.LoadportState");
- }
- ShowDateTime = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
- base.Poll();
- }
- public string TerminalBackground
- {
- get { return _notifyTerminalMessageArrive ? "LawnGreen" : "#0086cd"; }
- }
- [Subscription(ParamName.AlignerState, DeviceName.Aligner)]
- public string AlignerStatus
- {
- get;
- set;
- }
- public string AlignerStatusBackground
- {
- get { return GetUnitStatusBackground(AlignerStatus); }
- }
- [Subscription(ParamName.RobotState, DeviceName.Robot)]
- public string RobotStatus
- {
- get;
- set;
- }
- public string RobotStatusBackground
- {
- get { return GetUnitStatusBackground(RobotStatus); }
- }
- [Subscription("System.TurnoverStation.State")]
- public string TurnoverStatus
- {
- get;
- set;
- }
- public string TurnoverStatusBackground
- {
- get { return GetUnitStatusBackground(TurnoverStatus); }
- }
- [Subscription("System.SignalTower.DeviceData")]
- public AITSignalTowerData SignalTower
- {
- get;
- set;
- }
- [Subscription(ParamName.IsAutoMode, SystemStateModule)]
- public bool IsAutoMode { get; set; }
- private bool _simulatorMode = false;
- public bool IsManualButtonEnabled
- {
- get
- {
- return IsAutoMode;
- }
- }
- public bool IsAutoButtonEnabled
- {
- get
- {
- return !IsAutoMode;
- }
- }
- 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";
- default:
- return "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;
- }
- }
- public ICommand SwitchOffBuzzerCommand { get; set; }
- public ICommand ResetCommand { get; set; }
- public ICommand LogoffCommand { get; set; }
- public ICommand TerminalCommand { get; set; }
- public ICommand TerminalSendCommand { get; set; }
- public ICommand TerminalClearCommand { get; set; }
- public bool IsManualMode
- {
- get
- {
- return !IsAutoMode;
- }
- }
- public FACommunicationState FACommunicationState
- {
- get
- {
- return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
- : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
- }
- }
- public bool IsFAEnableButtonEnabled
- {
- get { return FACommunicationState == FACommunicationState.Disabled; }
- }
- public bool IsFADisableButtonEnabled
- {
- get { return FACommunicationState != FACommunicationState.Disabled; }
- }
- MessageControl _balloonControl;
- private bool _logoff;
- public ObservableCollection<EventItem> EventLogList { get; set; }
- public ObservableCollection<TerminalMessageItem> TerminalMessageList { get; set; }
- public object _lockMessage = new object();
- private TerminalDialog _terminalDialog;
- [IgnorePropertyChange]
- public string TerminalMessageSetPoint { get; set; }
- private bool _notifyTerminalMessageArrive = false;
- public TopViewSubModel()
- : base("TopViewModelSub")
- {
- //this.loadPortCount = loadPortCount;
- SwitchOffBuzzerCommand = new DelegateCommand<object>(OnSwitchOffBuzzer);
- ResetCommand = new DelegateCommand<object>(DoReset);
- LogoffCommand = new DelegateCommand<object>(DoLogoff);
- TerminalCommand = new DelegateCommand<object>(ShowTerminalWindow);
- TerminalClearCommand = new DelegateCommand<object>(ClearTerminal);
- TerminalSendCommand = new DelegateCommand<object>(SendTerminal);
- SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- InvokePropertyChanged("SoftwareVersion");
- EventLogList = new ObservableCollection<EventItem>();
- TerminalMessageList = new ObservableCollection<TerminalMessageItem>();
- _balloonControl = new MessageControl();
- LPStatus = new ObservableCollection<TopViewLPStatus>();
- //LPStatus = new ObservableCollection<TopViewLPStatus>(Enumerable.Range(1, 4).Select(x => new TopViewLPStatus()
- //{
- // LPName = $"LP{x}",
- // LoadPortStatus = "unknown",
- //}).ToList());
- EventClient.Instance.OnEvent += Instance_OnEvent;
- EventClient.Instance.Start();
- }
- private ObservableCollection<TopViewLPStatus> lpStatus;
- public ObservableCollection<TopViewLPStatus> LPStatus
- {
- get { return lpStatus; }
- set
- {
- lpStatus = value;
- InvokePropertyChanged("LPStatus");
- }
- }
- private void SendTerminal(object obj)
- {
- if (string.IsNullOrEmpty(TerminalMessageSetPoint))
- return;
- InvokeClient.Instance.Service.DoOperation("FACommand", "FASendTerminalMessage", TerminalMessageSetPoint);
- lock (_lockMessage)
- {
- while (TerminalMessageList.Count > 200)
- {
- TerminalMessageList.RemoveAt(0);
- }
- TerminalMessageItem item = new TerminalMessageItem
- {
- Content = TerminalMessageSetPoint,
- Type = "E->H",
- MessageTime = DateTime.Now.ToString("yyyy-MM-dd HH: mm:ss")
- };
- TerminalMessageList.Add(item);
- }
- TerminalMessageSetPoint = "";
- InvokePropertyChanged("TerminalMessageSetPoint");
- }
- private void ClearTerminal(object obj)
- {
- lock (_lockMessage)
- {
- TerminalMessageList.Clear();
- }
- }
- private void ShowTerminalWindow(object obj)
- {
- _notifyTerminalMessageArrive = false;
- _terminalDialog = new TerminalDialog()
- {
- DataContext = this,
- };
- _terminalDialog.Topmost = true;
- _terminalDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
- _terminalDialog.ShowDialog();
- _terminalDialog = null;
- }
- private void Instance_OnEvent(EventItem obj)
- {
- if (_logoff)
- return;
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- if (obj.Source == "Host" && obj.EventEnum == "TerminalMessage")
- {
- lock (_lockMessage)
- {
- while (TerminalMessageList.Count > 200)
- {
- TerminalMessageList.RemoveAt(0);
- }
- TerminalMessageItem item = new TerminalMessageItem
- {
- Content = obj.Description,
- Type = "H->E",
- MessageTime = obj.OccuringTime.ToString("yyyy-MM-dd HH: mm:ss")
- };
- TerminalMessageList.Add(item);
- }
- if (_terminalDialog == null)
- _notifyTerminalMessageArrive = true;
- }
- }));
- 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();
- }
- public void Reset()
- {
- InvokeClient.Instance.Service.DoOperation(OperationName.ResetAlarm);
- InvokeClient.Instance.Service.DoOperation(OperationName.ResetDevice);
- InvokeClient.Instance.Service.DoOperation(OperationName.ResetRouteManager);
- }
- void OnSwitchOffBuzzer(object param)
- {
- InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), new object[] { DeviceName.SignalTower.ToString(), AITSignalTowerOperation.SwitchOffBuzzer.ToString() });
- }
- void PopUIMessage(EventItem obj)
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- _balloonControl.SetMessage(MessageType.Info, obj.Description);
- ShowNotifyIcon(2000);
- }));
- }
- 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);
- }));
- }
- void ShowNotifyIcon(int time)
- {
- TaskbarIcon icon = new TaskbarIcon();
- icon.ShowCustomBalloon(_balloonControl, global::System.Windows.Controls.Primitives.PopupAnimation.Slide, time);
- }
- 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<string, object> data)
- {
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- var tempLPStatus = new List<TopViewLPStatus>();
- foreach (var item in data.Keys)
- {
- if (item.Substring(0, 2) == "LP")
- {
- tempLPStatus.Add(new TopViewLPStatus()
- {
- LPName = item.Split('.')[0],
- LoadPortStatus = data[item].ToString(),
- }); //.Substring(0, 3),
- }
- }
- lpStatus.Clear();
- tempLPStatus = tempLPStatus.OrderBy(x => x.LPName).ToList();
- foreach (var item in tempLPStatus)
- {
- lpStatus.Add(item);
- }
- }));
- }
- }
- public class TopViewLPStatus : INotifyPropertyChanged
- {
- public string LPName { get; set; }
- public string LoadPortStatus { get; set; }
- public event PropertyChangedEventHandler PropertyChanged;
- }
- }
|