/// <summary> /// Saves the given file. /// </summary> protected override void Save(string fileName) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Altinoren.ActiveWriter.Model modelRoot = (global::Altinoren.ActiveWriter.Model) this.RootElement; global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0) { global::Altinoren.ActiveWriter.ActiveRecordMapping diagram = diagrams[0] as global::Altinoren.ActiveWriter.ActiveRecordMapping; if (diagram != null) { string diagramFileName = fileName + this.DiagramExtension; try { this.SuspendFileChangeNotification(diagramFileName); global::Altinoren.ActiveWriter.ActiveWriterSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false); if (!serializationResult.Failed) { // fileName != this.FileName is false in the case of Save As. Allow OnFileNameChanged() below to handle this case. if (global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) == 0 && global::System.IO.File.Exists(diagramFileName)) { DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName); } } } finally { this.ResumeFileChangeNotification(diagramFileName); } } } if (!serializationResult.Failed) { global::Altinoren.ActiveWriter.ActiveWriterSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, false); } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::Altinoren.ActiveWriter.ActiveWriterDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
/// <summary> /// Called on both document load and reload. /// </summary> protected virtual void OnDocumentLoaded() { // Validate the document this.ValidationController.Validate(this.Store, DslValidation::ValidationCategories.Open); // Enable CompartmentItems events. global::Altinoren.ActiveWriter.Model modelRoot = this.RootElement as global::Altinoren.ActiveWriter.Model; if (modelRoot != null) { global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(modelRoot); if (diagrams.Count > 0) { global::Altinoren.ActiveWriter.ActiveRecordMapping diagram = diagrams[0] as global::Altinoren.ActiveWriter.ActiveRecordMapping; if (diagram != null) { diagram.SubscribeCompartmentItemsEvents(); } } } }
/// <summary> /// Loads the given file. /// </summary> protected override void Load(string fileName, bool isReload) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Altinoren.ActiveWriter.Model modelRoot = null; DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider); // Enable diagram fixup rules in our store, because we will load diagram data. global::Altinoren.ActiveWriter.ActiveWriterDomainModel.EnableDiagramRules(this.Store); string diagramFileName = fileName + this.DiagramExtension; // Ensure that subordinate diagram file is named properly; handles the case where a rename occurs while the designer was closed. if (this.Hierarchy != null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); if (itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL) { global::System.Diagnostics.Debug.Assert(!this.IsLoaded); // Make sure the name is right before we lock the item in the RDT. DslShell::SubordinateFileHelper.EnsureChildFileName(this.ServiceProvider, this.Hierarchy, itemId, diagramFileName); // Found the diagram file, lock it in the running documents table. this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(global::Altinoren.ActiveWriter.ActiveWriterDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } } } try { modelRoot = global::Altinoren.ActiveWriter.ActiveWriterSerializationHelper.Instance.LoadModelAndDiagram(serializationResult, this.Store, fileName, diagramFileName, schemaResolver, null /* no load-time validation */); } finally { if (this.diagramDocumentLockHolder != null && (modelRoot == null || serializationResult.Failed)) { // Load failed, release the document lock if we added one above. this.diagramDocumentLockHolder.UnregisterSubordinateDocument(); this.diagramDocumentLockHolder = null; } } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::Altinoren.ActiveWriter.ActiveWriterDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } else { this.SetRootElement(modelRoot); if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName)) { DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName); // Should have a subordinate diagram file now. If we didn't add a lock above, add one now. if (this.diagramDocumentLockHolder == null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(global::Altinoren.ActiveWriter.ActiveWriterDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } } // Connect to events on the RDT in order to allow delayed rename handling. this.eventsCookie = DslShell::SubordinateFileHelper.AdviseRunningDocumentTableEvents(this.ServiceProvider, this); } } }