/// <summary> /// Saves the dossier in the last specified file. /// </summary> public IEnumerable <IResult> SaveDossierAsync() { using (Stream stream = this._fileService.Save()) { if (stream == null) { ShowErrorDialog(new IOException(), Resources.UnableToSave); yield break; } using (this._busyWatcher.GetTicket()) { yield return (DossierSerializer.SaveToAsync(this._currentDossier, stream, exception => ShowErrorDialog(exception, Resources.UnableToSave))); IsModelDirty = false; } } }
/// <summary> /// Opens a dossier. /// </summary> public IEnumerable <IResult> OpenDossierAsync() { bool isCurrentDossierClosable = false; yield return(CloseDossierAsync(canClose => isCurrentDossierClosable = canClose).AsSequentialResult()); if (!isCurrentDossierClosable) { yield break; } using (Stream stream = this._fileService.Open()) { if (stream == null) { yield break; } using (this._busyWatcher.GetTicket()) { IResult <Dossier> dossierOp = DossierSerializer.LoadFromAsync(stream, exception => ShowErrorDialog(exception, Resources.UnableToOpen)); yield return(dossierOp); var decoratedDossierOp = new AsyncResult <DossierDecorator>(() => this._decoratorService.Decorate(dossierOp.Result)); yield return(decoratedDossierOp); this._currentDossier = decoratedDossierOp.Result; this._dossierViewModel.Dossier = this._currentDossier; CurrentFileName = this._fileService.LastFile; IsModelDirty = false; } } }