| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- using CommonServiceLocator;
- using OHV.Common.Events;
- 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 ); }
- }
- IEventAggregator eventAggregator = null;
- VCSystem VCSystem = null;
- MessageController messageController;
- 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; }
- 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 );
- 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);
- 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 = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- this.LastBuildedTime = new Helpler.AssemblyInfo().Get_BuildDateTime();
- }
- private void OcsConnectCallBack( HostConnectedEventArgs obj )
- {
- this.State = obj.State;
- switch ( this.State )
- {
- case HostConnectedEventArgs.eConnectedState.Disconnected:
- this.OcsBrush = Brushes.Yellow;
- 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 );
- }
- private void UICallbackCommunication( GUIMessageEventArgs obj )
- {
- }
- 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);
- }
- }
- }
|