/// <summary> /// Save document safely. "Safe" in the sense that all exceptions are caught (and reported via OnSaveException). /// The implementer of IDocumentClient is responsible for ensuring that existing data is not lost /// if the save fails.</summary> /// <param name="document">Document to save</param> /// <param name="kind">Kind of document event associated with save</param> /// <returns>True iff document is saved safely</returns> protected bool SafeSave(IDocument document, DocumentEventType kind) { IsSaving = true; bool success = false; try { if (OnDocumentSaving(document)) { DocumentSaving.Raise(this, new DocumentEventArgs(document, kind)); IDocumentClient client = GetClient(document); client.Save(document, document.Uri); success = OnDocumentSaved(document); if (success) { document.Dirty = false; m_newDocumentPaths.Remove(document.Uri.LocalPath); DocumentSaved.Raise(this, new DocumentEventArgs(document, kind)); } } } catch (Exception ex) { OnSaveException(ex); } IsSaving = false; return(success); }
public static void RaiseDocumentSaving(Document document) { DocumentSaving?.Invoke(document); }