示例#1
0
        /// <summary>
        /// Method to invoke when the Edit command is executed.
        /// </summary>
        private async Task OnConfigCommandExecuteAsync()
        {
            var viewModel = new PlotConfigurationViewModel(PlotModel.PlotConfiguration);

            if (await _uiVisualizerService.ShowDialogAsync(viewModel) ?? false)
            {
                if (PlotModel.PlotConfiguration != viewModel.Config)
                {
                    PlotModel.PlotConfiguration = viewModel.Config;//this triggers OnPlotConfigurationChanged()
                }
                else
                {
                    UpdatePlotConfiguration();
                }
                ViewModelCommandManager.InvalidateCommands(true);
            }
        }
示例#2
0
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        protected ViewModelBase()
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            UniqueIdentifier          = UniqueIdentifierHelper.GetUniqueIdentifier(GetType());
            ViewModelConstructionTime = DateTime.Now;

            AuditingHelper.RegisterViewModel(this);

            _viewModelCommandManager = ViewModelCommandManager.Create(this);
            _viewModelCommandManager.AddHandler((viewModel, propertyName, command, commandParameter) =>
                                                _catelCommandExecuted.SafeInvoke(this, new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName)));

            ViewModelManager.RegisterViewModelInstance(this);
        }
示例#3
0
        public void OnSelectedCProgramPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            ThreadCProgram cp = sender as ThreadCProgram;

            if (cp == null)
            {
                return;
            }
            if (e.PropertyName == "ThreadID")
            {
                ListCollectionView list = (ListCollectionView)FreeThreads;
                //this always returns 'null' (for no thread id) plus the unused ids
                //list.Filter = new Predicate<object>(x => !((int?)x).HasValue || ThreadCPrograms.FirstOrDefault(c=>c.ThreadID == (int?)x) == null || (int?)x==SelectedCProgram.ThreadID);
                list.Filter = new Predicate <object>(x => (!((int?)x).HasValue || ThreadCPrograms.FirstOrDefault(c => c.ThreadID == (int?)x) == null) && (int?)x != SelectedCProgram.ThreadID);
                list.Refresh();

                ViewModelCommandManager.InvalidateCommands(true);
            }
        }
示例#4
0
 /// <summary>
 /// Method to invoke when the Edit command is executed.
 /// </summary>
 private async Task OnClearExecute()
 {
     lock (_lockObject)
     {
         Messages.Clear();
         _dataLog.Clear();
         foreach (OxyPlot.Series.LineSeries series in OxyPlotModel.Series)
         {
             series.Points.Clear();
         }
         foreach (var ax in OxyPlotModel.Axes)
         {
             ax.Maximum = ax.Minimum = Double.NaN;
         }
         OxyPlotModel.ResetAllAxes();
         OxyPlotModel.InvalidatePlot(true);
         ViewModelCommandManager.InvalidateCommands(true);
     }
 }
示例#5
0
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        protected ViewModelBase()
        {
            if (Catel.Environment.IsInDesignMode)
            {
                return;
            }

            UniqueIdentifier          = UniqueIdentifierHelper.GetUniqueIdentifier(GetType());
            ViewModelConstructionTime = DateTime.Now;

            AuditingHelper.RegisterViewModel(this);

            _viewModelCommandManager = ViewModelCommandManager.Create(this);
            _viewModelCommandManager.AddHandler((viewModel, propertyName, command, commandParameter) =>
                                                _catelCommandExecuted.SafeInvoke(this, new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName)));

            ServiceLocator     = IoCConfiguration.DefaultServiceLocator;
            DependencyResolver = ServiceLocator.ResolveType <IDependencyResolver>();
            RegisterViewModelServices(ServiceLocator);

            ViewModelManager.RegisterViewModelInstance(this);
        }
示例#6
0
        private async Task OnLoadConfigurationExecuteAsync()
        {
            try
            {
                _openFileService.Filter = "Kflop Plot File|*.kfp";
                if (!string.IsNullOrEmpty(Config.SavePath))
                {
                    _openFileService.InitialDirectory = Path.GetDirectoryName(Config.SavePath);
                    _saveFileService.FileName         = Path.GetFileNameWithoutExtension(Config.SavePath);
                }
                else
                {
                    _openFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data"));
                }

                if (_openFileService.DetermineFile())
                {
                    using (var fileStream = File.Open(_openFileService.FileName, FileMode.Open))
                    {
                        var configuration = new SerializationConfiguration
                        {
                            Culture = new System.Globalization.CultureInfo("en-US")
                        };
                        Config = PlotConfigurationModel.Load(fileStream, SerializationMode.Xml, configuration);
                    }
                    Config.SavePath = _openFileService.FileName;
                    this.ClearIsDirtyOnAllChilds();
                    this.IsDirty = false;
                    ViewModelCommandManager.InvalidateCommands(true);
                    LogTo.Info("Loaded Plot configuration from: {0}", Config.SavePath);
                }
            }
            catch (Exception ex)
            {
                string errmsg = string.Format("Error loading Plot configuration: {0}", ex.Message);
                LogTo.Error(errmsg);
                await Shared.Utility.ShowErrorMsgAsync(this, errmsg);
            }
        }
示例#7
0
 private void OpenConfiguration(string path)
 {
     using (var fileStream = File.Open(path, FileMode.Open))
     {
         var configuration = new SerializationConfiguration
         {
             Culture = new System.Globalization.CultureInfo("en-US")
         };
         WindowModel = MainWindowModel.Load(fileStream, SerializationMode.Xml, configuration);
     }
     //open the plots
     foreach (PlotModel pm in Plots)
     {
         var viewModel = new PlotViewModel(pm);
         viewModel.ClosedAsync += PlotViewModel_ClosedAsync;
         ServiceLocator.Default.ResolveType <IUIVisualizerService>().Show(viewModel);
     }
     SaveConfigPath = path;
     this.ClearIsDirtyOnAllChilds();
     this.IsDirty = false;
     ViewModelCommandManager.InvalidateCommands(true);
     LogTo.Info("Loaded Plot configuration from: {0}", SaveConfigPath);
 }
示例#8
0
        private void OnMementoServiceUpdated(object sender, MementoEventArgs e)
        {
            UndoRedoEvents.Clear();

            var allEvents = _mementoService.UndoBatches.Where(ev => !ev.IsEmptyBatch);

            foreach (var mementoEvent in allEvents.Reverse())
            {
                if (mementoEvent.IsSingleActionBatch)
                {
                    var propertyChangeAction = mementoEvent.Actions.First() as PropertyChangeUndo;
                    if (propertyChangeAction is not null)
                    {
                        var message = $"changed {propertyChangeAction.Target}.{propertyChangeAction.PropertyName}";
                        UndoRedoEvents.Add(message);
                        continue;
                    }

                    var collectionChangedAction = mementoEvent.Actions.First() as CollectionChangeUndo;
                    if (collectionChangedAction is not null)
                    {
                        var message = $"{collectionChangedAction.ChangeType} {mementoEvent.Title} {mementoEvent.Description}";
                        UndoRedoEvents.Add(message);
                        continue;
                    }

                    UndoRedoEvents.Add("unknown action type");
                }
                else
                {
                    var message = $"{mementoEvent.Title} {mementoEvent.Description}";
                    UndoRedoEvents.Add(message);
                }
            }

            ViewModelCommandManager.InvalidateCommands(true);
        }
示例#9
0
 private void WorkModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     ViewModelCommandManager.InvalidateCommands(true);
 }
示例#10
0
 public void ThrowsArgumentNullExceptionForNullViewModel()
 {
     ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => ViewModelCommandManager.Create(null));
 }
示例#11
0
 /// <summary>
 /// Method to invoke when the SetThreadIDCommand command is executed.
 /// </summary>
 private void OnSetThreadIDCommandExecuteAsync(int?value)
 {
     // TODO: Handle command logic here
     SelectedCProgram.ThreadID = value;
     ViewModelCommandManager.InvalidateCommands(true);
 }
示例#12
0
        /// <summary>
        /// Method to invoke when the LoadCommand command is executed.
        /// </summary>
        private async Task OnLoadCommandExecuteAsync()
        {
            try
            {
                var openFileService = ServiceLocator.Default.ResolveType <IOpenFileService>();
                openFileService.Filter = "Plot Data| *.csv";
                if (!string.IsNullOrEmpty(PlotModel.SaveCsvPath))
                {
                    openFileService.InitialDirectory = Path.GetDirectoryName(PlotModel.SaveCsvPath);
                    openFileService.FileName         = Path.GetFileNameWithoutExtension(PlotModel.SaveCsvPath);
                }
                else
                {
                    openFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data"));
                }

                if (openFileService.DetermineFile())
                {
                    using (var reader = new StreamReader(openFileService.FileName))
                    {
                        lock (_lockObject)
                        {
                            string   headers    = reader.ReadLine();
                            string[] delheaders = headers.Split(',');
                            //count unquie indexes in configured plot
                            List <int> uindexes = GetUnquieIndexesInSeries(PlotModel.PlotConfiguration.Series);

                            if (uindexes.DefaultIfEmpty(0).Max() != delheaders.Length)//+1 for log identifier and time
                            {
                                throw new Exception("Current Plot Configuration does not match CSV file columns");
                            }
                            FromHex = false;
                            string line  = reader.ReadLine();
                            int    count = 0;
                            while (line != null)
                            {
                                string   strwithid = line.Insert(0, "@F,");
                                string[] delline   = strwithid.Split(',');
                                Messages.Add(delline);
                                count++;
                                if (count % 1000 == 0)
                                {
                                    if (!PlotMessages())
                                    {
                                        throw new Exception("Unable to plot messages, see log for details.");
                                    }
                                }
                                line = reader.ReadLine();
                            }
                            if (!PlotMessages())
                            {
                                throw new Exception("Unable to plot messages, see log for details.");
                            }
                            FromHex = true;
                            LogTo.Info("Plotted {0} points.", count.ToString());
                        }
                    }

                    PlotModel.SaveCsvPath = openFileService.FileName;
                    LogTo.Info("Loaded Plot data from: {0}", PlotModel.SaveCsvPath);
                    ViewModelCommandManager.InvalidateCommands(true);
                }
            }
            catch (Exception ex)
            {
                string errmsg = string.Format("Error loading Plot data: {0}", ex.Message);
                LogTo.Error(errmsg);
                await Shared.Utility.ShowErrorMsgAsync(this, errmsg);
            }
        }