示例#1
0
        /// <summary>
        /// Saves the given file.
        /// </summary>
        protected override void Save(string fileName)
        {
            DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult();

            global::pelsoft.FWK_Dsl.ModelRoot modelRoot = (global::pelsoft.FWK_Dsl.ModelRoot) this.RootElement;


            // Only save the diagrams if
            // a) There are any to save
            // b) This is NOT a SaveAs operation.  SaveAs should allow the subordinate document to control the save of its data as it is writing a new file.
            //    Except DO save the diagram on SaveAs if there isn't currently a diagram as there won't be a subordinate document yet to save it.

            bool saveAs = global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) != 0;

            global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement);
            if (diagrams.Count > 0 && (!saveAs || this.diagramDocumentLockHolder == null))
            {
                global::pelsoft.FWK_Dsl.ClassDiagram diagram = diagrams[0] as global::pelsoft.FWK_Dsl.ClassDiagram;
                if (diagram != null)
                {
                    string diagramFileName = fileName + this.DiagramExtension;
                    try
                    {
                        this.SuspendFileChangeNotification(diagramFileName);

                        global::pelsoft.FWK_Dsl.FWK_DslSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false);
                    }
                    finally
                    {
                        this.ResumeFileChangeNotification(diagramFileName);
                    }
                }
            }
            else
            {
                global::pelsoft.FWK_Dsl.FWK_DslSerializationHelper.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::pelsoft.FWK_Dsl.FWK_DslDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"));
            }
        }
示例#2
0
        /// <summary>
        /// Save the given document that is subordinate to this document.
        /// </summary>
        /// <param name="subordinateDocument"></param>
        /// <param name="fileName"></param>
        protected override void SaveSubordinateFile(DslShell::DocData subordinateDocument, string fileName)
        {
            // In this case, the only subordinate is the diagram.
            DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult();

            global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement);
            if (diagrams.Count > 0)
            {
                global::pelsoft.FWK_Dsl.ClassDiagram diagram = diagrams[0] as global::pelsoft.FWK_Dsl.ClassDiagram;
                if (diagram != null)
                {
                    try
                    {
                        this.SuspendFileChangeNotification(fileName);

                        global::pelsoft.FWK_Dsl.FWK_DslSerializationHelper.Instance.SaveDiagram(serializationResult, diagram, fileName, this.Encoding, false);
                    }
                    finally
                    {
                        this.ResumeFileChangeNotification(fileName);
                    }
                }
            }
            // 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)
            {
                // Notify the Running Document Table that the subordinate has been saved
                if (this.ServiceProvider != null)
                {
                    VSShellInterop::IVsRunningDocumentTable rdt = (VSShellInterop.IVsRunningDocumentTable) this.ServiceProvider.GetService(typeof(VSShellInterop::IVsRunningDocumentTable));
                    if (rdt != null && this.diagramDocumentLockHolder != null && this.diagramDocumentLockHolder.SubordinateDocData != null)
                    {
                        global::Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(rdt.NotifyOnAfterSave(this.diagramDocumentLockHolder.SubordinateDocData.Cookie));
                    }
                }
            }
            else
            {
                // Save failed.
                throw new global::System.InvalidOperationException(global::pelsoft.FWK_Dsl.FWK_DslDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"));
            }
        }
示例#3
0
 /// <summary>
 /// Called on both document load and reload.
 /// </summary>
 protected virtual void OnDocumentLoaded()
 {
     // Enable CompartmentItems events.
     global::pelsoft.FWK_Dsl.ModelRoot modelRoot = this.RootElement as global::pelsoft.FWK_Dsl.ModelRoot;
     if (modelRoot != null)
     {
         global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(modelRoot);
         if (diagrams.Count > 0)
         {
             global::pelsoft.FWK_Dsl.ClassDiagram diagram = diagrams[0] as global::pelsoft.FWK_Dsl.ClassDiagram;
             if (diagram != null)
             {
                 diagram.SubscribeCompartmentItemsEvents();
             }
         }
     }
 }