Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IApplicationService applicationService, IFileService fileService)
        {
            // Services
            this.fileService        = fileService;
            this.applicationService = applicationService;

            // Initial state
            this.scriptArgument   = "<Argument>";
            this.state            = MainViewModelState.Idle;
            this.mainAssembly     = Assembly.GetEntryAssembly();
            this.AssemblyPlatform = Environment.Is64BitProcess
                ? DiagnosticAssembyPlatform.x64
                : DiagnosticAssembyPlatform.x86;
            this.engine      = new DiagnosticEngine();
            this.engine.Log += UpdateLog;

            // Commands
            this.RunScriptCommand        = new RelayCommand(RunScript, CanRunScript);
            this.ExitCommand             = new RelayCommand(Exit);
            this.LoadExperimentCommand   = new RelayCommand(LoadExperiment);
            this.SaveExperimentCommand   = new RelayCommand(SaveExperiment, CanSaveExperiment);
            this.SaveExperimentAsCommand = new RelayCommand(SaveExperimentAs);
            this.GCDataClickCommand      = new RelayCommand <ChartPoint>(GCDataClick);

            // Self-register messages
            Messenger.Default.Register <PropertyChangedMessage <string> >(
                this, (e) =>
            {
                if (e.PropertyName == nameof(ScriptText))
                {
                    this.RunScriptCommand?.RaiseCanExecuteChanged();
                }
            });
            Messenger.Default.Register <PropertyChangedMessage <MainViewModelState> >(
                this, (e) =>
            {
                this.RunScriptCommand?.RaiseCanExecuteChanged();
            });
            Messenger.Default.Register <PropertyChangedMessage <IExperimentFile> >(
                this, e =>
            {
                this.SaveExperimentCommand?.RaiseCanExecuteChanged();
                RaisePropertyChanged(nameof(Title));
            });

            // LiveCharts customization
            this.mapper = Mappers.Xy <DateViewModel>()
                          .X(dayModel => dayModel.DateTime.Ticks)
                          .Y(dayModel => dayModel.Value);

            this.GraphDataGC      = new SeriesCollection();
            this.GCSections       = new SectionsCollection();
            this.GCSectionsLabels = new VisualElementsCollection();
        }
Ejemplo n.º 2
0
        public void SaveState(Dictionary <string, object> pageState)
        {
            var state = new MainViewModelState()
            {
                SearchText       = this.SearchText,
                FuelType         = this._selectedFuelType,
                SearchByLocation = this.SearchByLocation,
                SearchByGps      = this.SearchByGps
            };

            if (null != Results)
            {
                state.Results = Results.ToList();
            }

            string json = JsonConvert.SerializeObject(state);

            pageState[PageStateName] = json;
        }