| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- using CommonServiceLocator;
- using GSG.NET.Utils;
- using OHV.Common.Events;
- using OHV.Common.Model;
- using OHV.Common.Shareds;
- using OHV.Module.Interactivity;
- using OHV.SqliteDAL;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Threading;
- using VehicleControlSystem;
- namespace OHV.Vehicle.Concept
- {
- class D_MainWindowViewModel : BindableBase
- {
- private string _title = "Prism Unity Application";
- public string Title
- {
- get { return _title; }
- set { SetProperty(ref _title, value); }
- }
- private double _cpu;
- public double CPU
- {
- get { return this._cpu; }
- set { this.SetProperty(ref this._cpu, value); }
- }
- private double _totalCPU;
- public double TotalCPU
- {
- get { return this._totalCPU; }
- set
- {
- //this._totalCPU = dti.cpuResult.ToString();
- this.SetProperty(ref this._totalCPU, value);
- }
- }
- public int UsageCPU { get; set; }
- private double _ram;
- public double RAM
- {
- get { return this._ram; }
- set { this.SetProperty(ref this._ram, value); }
- }
- private double _cDrive;
- public double CDrive
- {
- get { return this._cDrive; }
- set { this.SetProperty(ref this._cDrive, value); }
- }
- DateTime _dateTime;
- public DateTime DateTime
- {
- get { return _dateTime; }
- set
- {
- this.SetProperty(ref _dateTime, value);
- }
- }
- private string _vehicleID;
- public string VehicleID
- {
- get { return this._vehicleID; }
- set { this.SetProperty(ref this._vehicleID, value); }
- }
- private string _vehicleIP = "127.0.0.1";
- public string VehicleIP
- {
- get { return this._vehicleIP; }
- set { this.SetProperty( ref this._vehicleIP , value ); }
- }
- private string _ocsIP;
- public string OcsIP
- {
- get { return this._ocsIP; }
- set { this.SetProperty( ref this._ocsIP , value ); }
- }
- private Brush _ocsBrush;// = Brushes.Gray;
- private Brush _batteryBrush;// = Brushes.Gray;
- private Brush _laserBrush;// = Brushes.Gray;
- public Brush OcsBrush
- {
- get { return _ocsBrush; }
- set
- {
- SetProperty(ref _ocsBrush, value);
- }
- }
- public Brush BatteryBrush
- {
- get { return _batteryBrush; }
- set
- {
- SetProperty(ref _batteryBrush, value);
- }
- }
- public Brush LaserBrush
- {
- get { return this._laserBrush; }
- set
- {
- SetProperty(ref _laserBrush, value);
- }
- }
- private string _swVersion;
- public string SwVersion
- {
- get { return this._swVersion; }
- set { this.SetProperty(ref this._swVersion, value); }
- }
- private DateTime _lastBuildedTime;
- public DateTime LastBuildedTime
- {
- get { return this._lastBuildedTime; }
- set { this.SetProperty(ref this._lastBuildedTime, value); }
- }
- bool _startEnable = true;
- public bool StartEnable
- {
- get { return this._startEnable; }
- set { this.SetProperty( ref this._startEnable , value ); }
- }
- bool _stopEnable = false;
- public bool StopEnable
- {
- get { return this._stopEnable; }
- set { this.SetProperty( ref this._stopEnable , value ); }
- }
- IEventAggregator eventAggregator = null;
- VCSystem VCSystem = null;
- MessageController messageController;
- VCSMessagePubSubEvent vcsMessagePublisher;
- public ICommand TestCommand { get; set; }
- public ICommand NavigateCommand { get; set; }
- public ICommand SystemOffCommand { get; set; }
- public ICommand BuzzerStopCommand { get; set; }
- public ICommand EmergencyStopCommand { get; set; }
- public ICommand StartCommand { get; set; }
- public ICommand StopCommand { get; set; }
- public ICommand AlarmResetCommand { get; set; }
- IRegionManager regionManager;
- public Common.Events.HostConnectedEventArgs.eConnectedState State { get; set; }
- private DeskTopInfo dti = new DeskTopInfo();
- public ICommand ChangeLanguage { get; set; }
- private void Execte_ChangeLanguage()
- {
- //LanguageHalper.LanguagesSelcter.ChangLanguage(LanguageHalper.eLanguageType.Chinese);
- }
- SqliteManager sql;
- public D_MainWindowViewModel( IEventAggregator _ea , VCSystem cSystem , IRegionManager _regionManager , MessageController _msgController, SqliteManager _sql )
- {
- this.regionManager = _regionManager;
- this.eventAggregator = _ea;
- this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Subscribe( UICallbackCommunication , ThreadOption.UIThread );
- this.eventAggregator.GetEvent<HostConnectedPubSubEvent>().Subscribe( OcsConnectCallBack , ThreadOption.UIThread , false );
- vcsMessagePublisher = this.eventAggregator.GetEvent<VCSMessagePubSubEvent>();
- this.VCSystem = cSystem;
- this.messageController = _msgController;
- this.sql = _sql;
- this.VehicleID = sql.ConfigDal.GetK( ConstString.VehicleID ).Value;
- //this.VehicleIP = sql.ConfigDal.GetK( ConstString.Addr ).Value;
- this.OcsIP = sql.ConfigDal.GetK( ConstString.Addr ).Value;
- //this.TestCommand = new DelegateCommand( ExecuteTextCommand );
- this.NavigateCommand = new DelegateCommand<object>(this.Navigate);
- this.SystemOffCommand = new DelegateCommand(ExecuteSystemOffCommand);
- this.ChangeLanguage = new DelegateCommand(Execte_ChangeLanguage);
- this.StartCommand = new DelegateCommand(ExecuteStartCommand);
- this.StopCommand = new DelegateCommand(ExecuteStopCommand);
- this.AlarmResetCommand = new DelegateCommand( ExecuteAlarmResetCommand);
- this.EmergencyStopCommand = new DelegateCommand(ExecuteEStop);
- DispatcherTimer dateTimer = new DispatcherTimer();
- dateTimer.Tick += (object sender, EventArgs e) =>
- {
- this.DateTime = DateTime.Now;
- };
- dateTimer.Interval = TimeSpan.FromMilliseconds(500);
- dateTimer.Start();
- //DispatcherTimer deskTopTimer = new DispatcherTimer();
- //deskTopTimer.Tick += (object sender, EventArgs e) =>
- //{
- // this.CPU = dti.GetCpuUsage();
- // this.UsageCPU = (int)dti.GetCpuUsage();
- // this.RAM = dti.GetRamUsage();
- //};
- //deskTopTimer.Interval = TimeSpan.FromMilliseconds(1000);
- //deskTopTimer.Start();
- //this._totalCPU = dti.cpuResult;
- //this._cDrive = dti.GetCDrive();
- this.SwVersion = AssemblyUtils.GetVersion();
- this.LastBuildedTime = new Helpler.AssemblyInfo().Get_BuildDateTime();
- GSG.NET.Quartz.QuartzUtils.Invoke("RESOURCE_CHECK", GSG.NET.Quartz.QuartzUtils.GetExpnSecond(1), QuzOnResourceUsage);
- }
- private void ExecuteEStop()
- {
- var msg = new VCSMessageEventArgs
- {
- Kind = VCSMessageEventArgs.eVCSMessageKind.ReqEStop,
- };
- vcsMessagePublisher.Publish(msg);
- }
- void QuzOnResourceUsage()
- {
- this.CPU = GSG.NET.OSView.Mgnt.CpuUseRate();
- this.RAM = GSG.NET.OSView.Mgnt.MemPhysicalUseRate();
- var ll = GSG.NET.OSView.Mgnt.HddList();
- this.CDrive = ll.FirstOrDefault().AvailableFreeSpace / ConstUtils.ONE_GIGA_BYTES;
- }
- private void ExecuteAlarmResetCommand( )
- {
- }
- private void ExecuteStopCommand()
- {
- this.messageController.ShowConfirmationPopupView(" Vehicle Stop ? ", r =>
- {
- if (r.Result == ButtonResult.OK)
- {
- var msg = new VCSMessageEventArgs
- {
- Kind = VCSMessageEventArgs.eVCSMessageKind.ReqVehicleModeChange,
- MessageKey = MessageKey.ManualMode,
- };
- vcsMessagePublisher.Publish(msg);
- }
- });
- }
- private void ExecuteStartCommand()
- {
- this.messageController.ShowConfirmationPopupView("Request Vehicle Auto Mode ?", r =>
- {
- if (r.Result == ButtonResult.OK)
- {
- var msg = new VCSMessageEventArgs
- {
- Kind = VCSMessageEventArgs.eVCSMessageKind.ReqVehicleModeChange,
- MessageKey = MessageKey.AutoMode,
- };
- vcsMessagePublisher.Publish(msg);
- }
- });
- }
- private void OcsConnectCallBack(HostConnectedEventArgs obj)
- {
- this.State = obj.State;
- switch (this.State)
- {
- case HostConnectedEventArgs.eConnectedState.Disconnected:
- this.OcsBrush = Brushes.Transparent;
- break;
- case HostConnectedEventArgs.eConnectedState.Connected:
- this.OcsBrush = Brushes.LimeGreen;
- break;
- }
- }
- private void ExecuteSystemOffCommand()
- {
- this.messageController.ShowConfirmationPopupView("System ShutDown ?", r =>
- {
- if (r.Result == ButtonResult.OK)
- App.Current.Shutdown();
- });
- }
- private void Navigate(object obj)
- {
- var selectItem = obj.ToString();
- if (!string.IsNullOrEmpty(selectItem))
- regionManager.RequestNavigate("MainView", selectItem);
- }
- void VehicleModeChang(bool isAutoMode)
- {
- if (isAutoMode)
- {
- this.StartEnable = false;
- this.StopEnable = true;
- }
- else
- {
- this.StartEnable = true;
- this.StopEnable = false;
- }
- }
- private void UICallbackCommunication(GUIMessageEventArgs obj)
- {
- switch (obj.Kind)
- {
- case GUIMessageEventArgs.eGUIMessageKind.ModelPropertyChange:
- this.UICallBackModelPropertyChange(obj);
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspIOObject:
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspIOMapList:
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspCommandList:
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspAutoModeChange:
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspManualModeChange:
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspAlarmReset:
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspVehicleModeChange:
- this.RspVehicleModeChange(obj);
- break;
- default:
- break;
- }
- }
- private void RspVehicleModeChange(GUIMessageEventArgs obj)
- {
- if ( obj.Result.IsSuccess)
- {
- if (obj.MessageKey.Equals(MessageKey.AutoMode)) { this.VehicleModeChang(true); }
- if (obj.MessageKey.Equals(MessageKey.ManualMode)) { this.VehicleModeChang(false); }
- }
- else
- {
- }
- }
- void UICallBackModelPropertyChange(GUIMessageEventArgs args)
- {
- if (args.MessageKey.Equals(MessageKey.Alarm))
- {
- var hisAlarm = args.Args as HisAlarm;
- this.messageController.ShowNotificationView(args.MessageText);
- }
- }
- private void ExecuteTextCommand()
- {
- //var m = new VCSMessageEventArgs();
- //m.MessageKey = 1234;
- //m.MessageText = "Test Message";
- //m.Command = new Common.Model.Command() { CommandID = "TestCommand123", Type = Common.Shareds.eCommandType.Move };
- //this.eventAggregator.GetEvent<VCSMessagePubSubEvent>().Publish(m);
- }
- public void InitViewModel()
- {
- //VCSystem.Instance.Init();
- //var containerRegistry = ServiceLocator.Current.GetInstance<VCSystem>();
- //if ( containerRegistry.Equals( this.VCSystem ) )
- //{
- // Console.WriteLine( "==" );
- //}
- //var vsys = containerRegistry.GetContainer().Resolve<IContainerProvider>();
- regionManager.RequestNavigate(RegionNames.MainView, "AutoView");
- }
- public void Dispose()
- {
- //VCSystem.Instance.Dispose();
- }
- public static void SelectCulture(string culture)
- {
- if (String.IsNullOrEmpty(culture))
- return;
- //Copy all MergedDictionarys into a auxiliar list.
- var dictionaryList = Application.Current.Resources.MergedDictionaries.ToList();
- //Search for the specified culture.
- string requestedCulture = string.Format("StringResources.{0}.xaml", culture);
- var resourceDictionary = dictionaryList.
- FirstOrDefault(d => d.Source.OriginalString == "/OHV.ResourceDic;component/Resources/StringResource.en-US.xaml");
- if (resourceDictionary == null)
- {
- //If not found, select our default language.
- requestedCulture = "StringResources.xaml";
- resourceDictionary = dictionaryList.
- FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
- }
- //If we have the requested resource, remove it from the list and place at the end.
- //Then this language will be our string table to use.
- if (resourceDictionary != null)
- {
- Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
- Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
- }
- //Inform the threads of the new culture.
- Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
- Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
- }
- }
- }
|