示例#1
0
 /// <summary>
 /// Method to invoke when the Remove command is executed.
 /// </summary>
 private async Task OnRemoveSeriesExecuteAsync()
 {
     if (await _messageService.ShowAsync("Are you sure you want to remove this series?", "Are you sure?", MessageButton.YesNo) == MessageResult.Yes)
     {
         Config.Series.Remove(SelectedSeries);
         ViewModelCommandManager.InvalidateCommands(true);
     }
 }
示例#2
0
 private void OnLocationChanged()
 {
     if (!string.IsNullOrWhiteSpace(this.Location) &&
         this.Location.ValidateUrl())
     {
         _baseUri = new Uri(this.Location);
         this.CanChangeLocation = false;
         ViewModelCommandManager.InvalidateCommands(true);
     }
 }
示例#3
0
        /// <summary>
        /// Method to invoke when the Add command is executed.
        /// </summary>
        private async Task OnAddAxisExecuteAsync()
        {
            var viewModel = new AxisDefinitionViewModel(new AxisDefinitionModel());

            if (await _uiVisualizerService.ShowDialogAsync(viewModel) ?? false)
            {
                Axes.Add(viewModel.AxisDefinitionModel);
                ViewModelCommandManager.InvalidateCommands(true);
            }
        }
示例#4
0
        /// <summary>
        /// Method to invoke when the AddCFile command is executed.
        /// </summary>
        private async Task OnAddCFileExecuteAsync()
        {
            try
            {
                var openFileService = ServiceLocator.Default.ResolveType <IOpenFileService>();
                openFileService.Filter = "Kflop C Program File| *.c";
                if (!string.IsNullOrEmpty(LastCProgramPath))
                {
                    openFileService.InitialDirectory = Path.GetDirectoryName(LastCProgramPath);
                    openFileService.FileName         = Path.GetFileNameWithoutExtension(LastCProgramPath);
                }
                else
                {
                    openFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\C Programs"));
                }

                if (openFileService.DetermineFile())
                {
                    List <int> freeThreads = new List <int>()
                    {
                        1, 2, 3, 4, 5, 6, 7
                    };
                    freeThreads.DefaultIfEmpty(-1);
                    foreach (ThreadCProgram cp in ThreadCPrograms)
                    {
                        if (cp.ThreadID != null)
                        {
                            freeThreads.Remove(cp.ThreadID.Value);
                        }
                    }
                    int id = freeThreads.FirstOrDefault();
                    if (id == -1)
                    {
                        LogTo.Warning("All threads in use, resuing thread ID 1 for C Program {1}.", openFileService.FileName);
                    }
                    ThreadCProgram cprog = new ThreadCProgram()
                    {
                        FilePath = openFileService.FileName, ThreadID = id
                    };
                    this.ThreadCPrograms.Add(cprog);

                    LastCProgramPath = openFileService.FileName;
                    ViewModelCommandManager.InvalidateCommands(true);
                    LogTo.Info("Loaded C Program from: {0}", LastCProgramPath);
                }
            }
            catch (Exception ex)
            {
                string errmsg = string.Format("Error loading C program: {0}", ex.Message);
                LogTo.Error(errmsg);
                await Shared.Utility.ShowErrorMsgAsync(this, errmsg);
            }
        }
示例#5
0
        private async Task OnSaveConfigurationExecuteAsync()
        {
            try
            {
                _saveFileService.Filter = "Kflop Plot File|*.kfp";
                if (!string.IsNullOrEmpty(Config.SavePath))
                {
                    _saveFileService.InitialDirectory = Path.GetDirectoryName(Config.SavePath);
                    if (!Directory.Exists(_saveFileService.InitialDirectory))
                    {
                        _saveFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data"));
                    }
                    _saveFileService.FileName = Path.GetFileNameWithoutExtension(Config.SavePath);
                }
                else
                {
                    _saveFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data"));
                }
                if (_saveFileService.DetermineFile())
                {
                    if (Config.SavePath != _saveFileService.FileName)
                    {
                        Config.SavePath = _saveFileService.FileName;
                    }
                    using (var fileStream = File.Create(_saveFileService.FileName))
                    {
                        var configuration = new SerializationConfiguration
                        {
                            Culture = new System.Globalization.CultureInfo("en-US")
                        };
                        Config.Save(fileStream, Catel.Data.SerializationMode.Xml, configuration);
                    }

                    this.ClearIsDirtyOnAllChilds();
                    this.IsDirty = false;
                    ViewModelCommandManager.InvalidateCommands(true);
                    LogTo.Info("Saved Plot configuration to: {0}", Config.SavePath);
                }
            }
            catch (Exception ex)
            {
                string errmsg = string.Format("Error saving Plot configuration: {0}", ex.Message);
                LogTo.Error(errmsg);
                await Shared.Utility.ShowErrorMsgAsync(this, errmsg);
            }
        }
示例#6
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);
            }
        }
示例#7
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);
            }
        }
示例#8
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);
     }
 }
示例#9
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);
 }
示例#10
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);
        }
示例#11
0
 private void WorkModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     ViewModelCommandManager.InvalidateCommands(true);
 }
示例#12
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);
 }
示例#13
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);
            }
        }