/// <summary> /// Saves the train set in the last specified file. /// </summary> public async Task SaveTrainSetAsync() { using (Stream stream = this._fileService.Save()) { if (stream == null) { ShowErrorDialog(new IOException(), Resources.UnableToSave); return; } try { using (this._busyWatcher.GetTicket()) { await TrainSetSerializer.SaveToAsync(this._trainSetViewModel.TrainSet, stream); IsModelDirty = false; } } catch (Exception exception) { ShowErrorDialog(exception, Resources.UnableToSave); } } }
/// <summary> /// Opens a train set. /// </summary> public async void OpenTrainSetAsync() { bool isCurrentTrainSetClosable = false; await CloseTrainSetAsync(canClose => isCurrentTrainSetClosable = canClose); if (!isCurrentTrainSetClosable) { return; } using (Stream stream = this._fileService.Open()) { if (stream == null) { return; } try { using (this._busyWatcher.GetTicket()) { TrainSet trainSet = await TrainSetSerializer.LoadFromAsync(stream); this._trainSetViewModel.TrainSet = trainSet; CurrentFileName = this._fileService.LastFile; IsModelDirty = false; } } catch (Exception exception) { ShowErrorDialog(exception, Resources.UnableToOpen); } } }