public PlotConfigurationViewModel(PlotConfigurationModel config) { Argument.IsNotNull("config", config); _uiVisualizerService = ServiceLocator.Default.ResolveType <IUIVisualizerService>(); _messageService = ServiceLocator.Default.ResolveType <IMessageService>(); _saveFileService = ServiceLocator.Default.ResolveType <ISaveFileService>(); _openFileService = ServiceLocator.Default.ResolveType <IOpenFileService>(); Config = config; AddAxis = new TaskCommand(OnAddAxisExecuteAsync); EditAxis = new TaskCommand(OnEditAxisExecuteAsync, OnEditAxisCanExecute); RemoveAxis = new TaskCommand(OnRemoveAxisExecuteAsync, OnRemoveAxisCanExecute); AddSeries = new TaskCommand(OnAddSeriesExecuteAsync, OnAddSeriesCanExecute); EditSeries = new TaskCommand(OnEditSeriesExecuteAsync, OnEditSeriesCanExecute); RemoveSeries = new TaskCommand(OnRemoveSeriesExecuteAsync, OnRemoveSeriesCanExecute); SaveConfiguration = new TaskCommand(OnSaveConfigurationExecuteAsync, OnSaveConfigurationCanExecute); LoadConfiguration = new TaskCommand(OnLoadConfigurationExecuteAsync); IsDirty = false; }
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); } }