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

            global::Sawczyn.EFDesigner.EFModel.ModelRoot modelRoot = (global::Sawczyn.EFDesigner.EFModel.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::Sawczyn.EFDesigner.EFModel.EFModelDiagram diagram = diagrams[0] as global::Sawczyn.EFDesigner.EFModel.EFModelDiagram;
                if (diagram != null)
                {
                    string diagramFileName = fileName + this.DiagramExtension;
                    try
                    {
                        this.SuspendFileChangeNotification(diagramFileName);

                        global::Sawczyn.EFDesigner.EFModel.EFModelSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false);
                    }
                    finally
                    {
                        this.ResumeFileChangeNotification(diagramFileName);
                    }
                }
            }
            else
            {
                global::Sawczyn.EFDesigner.EFModel.EFModelSerializationHelper.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::Sawczyn.EFDesigner.EFModel.EFModelDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"));
            }
        }
Beispiel #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::Sawczyn.EFDesigner.EFModel.EFModelDiagram diagram = diagrams[0] as global::Sawczyn.EFDesigner.EFModel.EFModelDiagram;
                if (diagram != null)
                {
                    try
                    {
                        this.SuspendFileChangeNotification(fileName);

                        global::Sawczyn.EFDesigner.EFModel.EFModelSerializationHelper.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)
            {
                this.NotifySubordinateDocumentSaved(subordinateDocument.FileName, fileName);
            }
            else
            {
                // Save failed.
                throw new global::System.InvalidOperationException(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Called to initialize the view after the corresponding document has been loaded.
        /// </summary>
        protected override bool LoadView()
        {
            base.LoadView();

            global::System.Diagnostics.Debug.Assert(this.DocData.RootElement != null);
            if (this.DocData.RootElement == null)
            {
                return(false);
            }


            // The diagram should exist in the diagram partition by now, just need to find it and connect it to this view.
            EFModelDocDataBase docData = this.DocData as EFModelDocDataBase;

            global::System.Diagnostics.Debug.Assert(docData != null, "DocData for EFModelDocViewBase should be an EFModelDocDataBase!");
            string dgmName = string.IsNullOrEmpty(this.diagramName) ? global::System.IO.Path.GetFileNameWithoutExtension(docData.FileName) : this.diagramName;
            DslModeling::Partition diagramPartition = docData.GetDiagramPartition();

            if (diagramPartition != null)
            {
                global::System.Collections.ObjectModel.ReadOnlyCollection <global::Sawczyn.EFDesigner.EFModel.EFModelDiagram> diagrams = docData.GetDiagramPartition().ElementDirectory.FindElements <global::Sawczyn.EFDesigner.EFModel.EFModelDiagram>();
                if (diagrams.Any())
                {
                    global::Sawczyn.EFDesigner.EFModel.EFModelDiagram dgm = diagrams.FirstOrDefault(diagram => diagram.Name.Equals(dgmName, global::System.StringComparison.Ordinal));
                    if (null == dgm && !string.IsNullOrEmpty(this.diagramName))
                    {
                        return(false);
                    }
                    this.Diagram = dgm ?? diagrams[0];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }


            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Called on both document load and reload.
        /// </summary>
        protected virtual void OnDocumentLoaded()
        {
            // Validate the document
            this.ValidationController.Validate(this.GetAllElementsForValidation(), DslValidation::ValidationCategories.Open);

            // Enable CompartmentItems events.
            global::Sawczyn.EFDesigner.EFModel.ModelRoot modelRoot = this.RootElement as global::Sawczyn.EFDesigner.EFModel.ModelRoot;
            if (modelRoot != null)
            {
                global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(modelRoot);
                if (diagrams.Count > 0)
                {
                    global::Sawczyn.EFDesigner.EFModel.EFModelDiagram diagram = diagrams[0] as global::Sawczyn.EFDesigner.EFModel.EFModelDiagram;
                    if (diagram != null)
                    {
                        diagram.SubscribeCompartmentItemsEvents();
                    }
                }
            }
        }
Beispiel #5
0
        internal static void FixUp(global::Sawczyn.EFDesigner.EFModel.EFModelDiagram diagram)
        {
            // 300010
            Guid[] l_300010_domainClassesIds =
            {
            };
            using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddShapeRulePriority:Core"))
            {
                foreach (Guid domainClassId in l_300010_domainClassesIds)
                {
                    ReadOnlyCollection <ModelElement> modelElements = diagram.Store.ElementDirectory.FindElements(domainClassId);
                    foreach (ModelElement modelElement in modelElements.Where(diagram.ShouldSupport))
                    {
                        FixUpAllDiagrams.FixUp(diagram, modelElement);
                    }
                }
                transaction.Commit();
            }

            // 300020
            Guid[] l_300020_domainClassesIds =
            {
                global::Sawczyn.EFDesigner.EFModel.Comment.DomainClassId,
                global::Sawczyn.EFDesigner.EFModel.ModelEnum.DomainClassId,
                global::Sawczyn.EFDesigner.EFModel.ModelClass.DomainClassId,
            };
            using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddShapeRulePriority:Core"))
            {
                foreach (Guid domainClassId in l_300020_domainClassesIds)
                {
                    ReadOnlyCollection <ModelElement> modelElements = diagram.Store.ElementDirectory.FindElements(domainClassId);
                    foreach (ModelElement modelElement in modelElements.Where(diagram.ShouldSupport))
                    {
                        FixUpAllDiagrams.FixUp(diagram, modelElement);
                    }
                }
                transaction.Commit();
            }

            // 300021
            Guid[] l_300021_domainClassesIds =
            {
            };
            using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddShapeRulePriority:Core"))
            {
                foreach (Guid domainClassId in l_300021_domainClassesIds)
                {
                    ReadOnlyCollection <ModelElement> modelElements = diagram.Store.ElementDirectory.FindElements(domainClassId);
                    foreach (ModelElement modelElement in modelElements.Where(diagram.ShouldSupport))
                    {
                        FixUpAllDiagrams.FixUp(diagram, modelElement);
                    }
                }
                transaction.Commit();
            }

            // 300100
            Guid[] l_300100_domainClassesIds =
            {
                global::Sawczyn.EFDesigner.EFModel.CommentReferencesSubjects.DomainClassId,
                global::Sawczyn.EFDesigner.EFModel.UnidirectionalAssociation.DomainClassId,
                global::Sawczyn.EFDesigner.EFModel.Generalization.DomainClassId,
                global::Sawczyn.EFDesigner.EFModel.BidirectionalAssociation.DomainClassId,
            };
            using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddConnectionRulePriority:AutoLayout"))
            {
                diagram.AutoLayoutShapeElements(diagram.NestedChildShapes,
                                                Microsoft.VisualStudio.Modeling.Diagrams.GraphObject.VGRoutingStyle.VGRouteTreeNS,
                                                Microsoft.VisualStudio.Modeling.Diagrams.GraphObject.PlacementValueStyle.VGPlaceSN, true);
                transaction.Commit();
            }

            using (Transaction transaction = diagram.Store.TransactionManager.BeginTransaction("FixUp:AddConnectionRulePriority:Core"))
            {
                foreach (Guid domainClassId in l_300100_domainClassesIds)
                {
                    ReadOnlyCollection <ModelElement> modelElements = diagram.Store.ElementDirectory.FindElements(domainClassId);

                    foreach (ModelElement modelElement in modelElements.Where(diagram.ShouldSupport))
                    {
                        FixUpAllDiagrams.FixUp(diagram, modelElement);
                    }
                }
                transaction.Commit();
            }

            diagram.OnSynchronized();
        }