| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- using CommonServiceLocator;
- using GSG.NET.Extensions;
- using GSG.NET.Logging;
- 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
- {
- #region Properties
- 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 string _swVersion;
- public string SwVersion
- {
- get { return this._swVersion; }
- set { this.SetProperty( ref this._swVersion, 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 ); }
- }
- private DateTime _lastBuildedTime;
- public DateTime LastBuildedTime
- {
- get { return this._lastBuildedTime; }
- set { this.SetProperty( ref this._lastBuildedTime, value ); }
- }
- private bool isManualMode = true;
- public bool IsManualMode
- {
- get { return isManualMode; }
- set { SetProperty( ref isManualMode, value ); }
- }
- private bool isVehicleAlarm = false;
- public bool IsVehicleAlarm
- {
- get { return isVehicleAlarm; }
- set { SetProperty( ref this.isVehicleAlarm, value ); }
- }
- private eMachineMode machineMode = eMachineMode.LocalMode;
- public eMachineMode MachineMode
- {
- get { return machineMode; }
- set { SetProperty( ref this.machineMode, value ); }
- }
- //HostConnectedEventArgs.eConnectedState ocsState = HostConnectedEventArgs.eConnectedState.Disconnected;
- //public HostConnectedEventArgs.eConnectedState OcsState
- //{
- // get { return this.ocsState; }
- // set { this.SetProperty( ref this.ocsState , value ); }
- //}
- eOcsState ocsState = eOcsState.DisConnect;
- public eOcsState OcsState
- {
- get { return this.ocsState; }
- set { this.SetProperty( ref this.ocsState, value ); }
- }
- eBatteryConnect batteryConnectState = eBatteryConnect.DisConnect;
- public eBatteryConnect BatteryConnectState
- {
- get { return this.batteryConnectState; }
- set { this.SetProperty( ref this.batteryConnectState, value ); }
- }
- #endregion
- #region Brushes
- private Brush _ocsBrush;
- public Brush OcsBrush
- {
- get { return _ocsBrush; }
- set
- {
- SetProperty( ref _ocsBrush, value );
- }
- }
- private Brush batteryBrush;
- public Brush BatteryBrush
- {
- get { return batteryBrush; }
- set
- {
- SetProperty( ref batteryBrush, value );
- }
- }
- double soc;
- public double SOC
- {
- get { return this.soc; }
- set { this.SetProperty( ref this.soc, value ); }
- }
- #endregion
- #region Commands
- 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; }
- public ICommand ChangeLanguage { get; set; }
- public ICommand MachineModeChgCommand { get; set; }
- #endregion
- IEventAggregator eventAggregator = null;
- VCSystem VCSystem = null;
- MessageController messageController;
- VCSMessagePubSubEvent vcsMessagePublisher;
- IRegionManager regionManager;
- DeskTopInfo dti = new DeskTopInfo();
- 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 );
- this.BuzzerStopCommand = new DelegateCommand( ExecuteBuzzerStop );
- this.MachineModeChgCommand = new DelegateCommand<string>( ExecuteMachineModeChgCommand );
- DispatcherTimer dateTimer = new DispatcherTimer();
- dateTimer.Tick += ( object sender, EventArgs e ) =>
- {
- this.DateTime = DateTime.Now;
- };
- dateTimer.Interval = TimeSpan.FromMilliseconds( 500 );
- dateTimer.Start();
- 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 );
- }
- 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 ExecuteMachineModeChgCommand( string obj )
- {
- var msg = new VCSMessageEventArgs
- {
- Kind = VCSMessageEventArgs.eVCSMessageKind.ReqMachineModeChg,
- };
- if ( this.MachineMode == eMachineMode.LocalMode )
- msg.Arg = eMachineMode.HostMode;
- else
- msg.Arg = eMachineMode.LocalMode;
- this.messageController.ShowConfirmationPopupView( $"Change to {msg.Arg} ?", r =>
- {
- if ( r.Result == ButtonResult.OK )
- vcsMessagePublisher.Publish( msg );
- } );
- }
- private void ExecuteBuzzerStop()
- {
- var msg = new VCSMessageEventArgs
- {
- Kind = VCSMessageEventArgs.eVCSMessageKind.ReqBuzzerStop,
- };
- vcsMessagePublisher.Publish( msg );
- this.ExecuteTextCommand();
- }
- private void Execte_ChangeLanguage()
- {
- //LanguageHalper.LanguagesSelcter.ChangLanguage(LanguageHalper.eLanguageType.Chinese);
- }
- private void ExecuteEStop()
- {
- var msg = new VCSMessageEventArgs
- {
- Kind = VCSMessageEventArgs.eVCSMessageKind.ReqEStop,
- };
- vcsMessagePublisher.Publish( msg );
- }
- private void ExecuteAlarmResetCommand()
- {
- this.messageController.ShowConfirmationPopupView( " Alarm Reset ? ", r =>
- {
- if ( r.Result == ButtonResult.OK )
- {
- var msg = new VCSMessageEventArgs
- {
- Kind = VCSMessageEventArgs.eVCSMessageKind.ReqAlarmReset,
- };
- vcsMessagePublisher.Publish( msg );
- }
- } );
- }
- 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 )
- {
- var state = obj.State;
- switch ( state )
- {
- case HostConnectedEventArgs.eConnectedState.Disconnected:
- this.OcsState = eOcsState.DisConnect;
- break;
- case HostConnectedEventArgs.eConnectedState.Connected:
- this.OcsState = eOcsState.Connect;
- 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 VehicleModeChange( bool isAutoMode )
- {
- if ( isAutoMode )
- {
- this.StartEnable = false;
- this.StopEnable = true;
- this.IsManualMode = false;
- regionManager.RequestNavigate( RegionNames.MainView, "AutoView" );
- }
- else
- {
- this.StartEnable = true;
- this.StopEnable = false;
- this.IsManualMode = true;
- }
- }
- 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;
- case GUIMessageEventArgs.eGUIMessageKind.RspEStop:
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspVihicleState:
- break;
- case GUIMessageEventArgs.eGUIMessageKind.RspMachineModeChg:
- RspMachineModeChg( obj );
- break;
- default:
- break;
- }
- }
- void RspBatteryConnected( GUIMessageEventArgs obj )
- {
- var connected = CastTo<bool>.From<object>( obj.Args );
- if ( connected )
- {
- this.BatteryBrush = Brushes.LimeGreen;
- BatteryConnectState = eBatteryConnect.Connect;
- }
- else
- {
- this.BatteryBrush = Brushes.Gray;
- BatteryConnectState = eBatteryConnect.DisConnect;
- }
- }
- private void RspMachineModeChg( GUIMessageEventArgs obj )
- {
- string reason = string.Empty;
- FluentResults.Result result = obj.Result;
- if ( obj.Result.IsFailed )
- {
- reason = result.Errors.FirstOrDefault().Message;
- }
- else
- {
- var mode = CastTo<eMachineMode>.From<object>( obj.Args );
- reason = $"Change To {mode} Successes";
- }
- this.messageController.ShowNotificationView( reason );
- }
- private void RspVehicleModeChange( GUIMessageEventArgs obj )
- {
- if ( obj.Result.IsSuccess )
- {
- if ( obj.MessageKey.Equals( MessageKey.AutoMode ) ) { this.VehicleModeChange( true ); }
- if ( obj.MessageKey.Equals( MessageKey.ManualMode ) ) { this.VehicleModeChange( false ); }
- }
- else
- {
- }
- }
- void UICallBackModelPropertyChange( GUIMessageEventArgs args )
- {
- if ( args.MessageKey.Equals( MessageKey.Alarm ) )
- {
- var hisAlarm = args.Args as HisAlarm;
- this.messageController.ShowNotificationView( args.MessageText );
- this.VehicleModeChange( false );//알람이 발생하면 자동으로 Manual Mode 로 변경됨
- this.IsVehicleAlarm = true;
- }
- if ( args.MessageKey.Equals( MessageKey.Vehicle ) )
- {
- switch ( args.ModelPropertyName )
- {
- case "VehicleStateProperty":
- {
- var vehicleState = CastTo<eVehicleState>.From<object>( args.Args );
- if ( vehicleState == eVehicleState.Abnormal )
- this.IsVehicleAlarm = true;
- else
- this.IsVehicleAlarm = false;
- }
- break;
- case "MachineMode":
- this.MachineMode = CastTo<eMachineMode>.From<object>( args.Args );
- break;
- case "BatteryIsConnect":
- this.RspBatteryConnected( args );
- break;
- case "BatteryStateOfCharge":
- this.SOC = CastTo<double>.From<object>( args.Args );
- break;
- default:
- break;
- }
- }
- }
- private void ExecuteTextCommand()
- {
- var m = new VCSMessageEventArgs();
- m.MessageKey = "";
- m.MessageText = "Test Message";
- m.Kind = VCSMessageEventArgs.eVCSMessageKind.ReqTest;
- 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 );
- }
- }
- }
|