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

            global::Company.OrmLanguage.SampleOrmModel modelRoot = (global::Company.OrmLanguage.SampleOrmModel) 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::Company.OrmLanguage.OrmLanguageDiagram diagram = diagrams[0] as global::Company.OrmLanguage.OrmLanguageDiagram;
                if (diagram != null)
                {
                    string diagramFileName = fileName + this.DiagramExtension;
                    try
                    {
                        this.SuspendFileChangeNotification(diagramFileName);

                        global::Company.OrmLanguage.OrmLanguageSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false);
                    }
                    finally
                    {
                        this.ResumeFileChangeNotification(diagramFileName);
                    }
                }
            }
            else
            {
                global::Company.OrmLanguage.OrmLanguageSerializationHelper.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::Company.OrmLanguage.OrmLanguageDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"));
            }
        }
Ejemplo n.º 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::Company.OrmLanguage.OrmLanguageDiagram diagram = diagrams[0] as global::Company.OrmLanguage.OrmLanguageDiagram;
                if (diagram != null)
                {
                    try
                    {
                        this.SuspendFileChangeNotification(fileName);

                        global::Company.OrmLanguage.OrmLanguageSerializationHelper.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::Company.OrmLanguage.OrmLanguageDomainModel.SingletonResourceManager.GetString("CannotSaveDocument"));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Called on both document load and reload.
 /// </summary>
 protected virtual void OnDocumentLoaded()
 {
     // Enable CompartmentItems events.
     global::Company.OrmLanguage.SampleOrmModel modelRoot = this.RootElement as global::Company.OrmLanguage.SampleOrmModel;
     if (modelRoot != null)
     {
         global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(modelRoot);
         if (diagrams.Count > 0)
         {
             global::Company.OrmLanguage.OrmLanguageDiagram diagram = diagrams[0] as global::Company.OrmLanguage.OrmLanguageDiagram;
             if (diagram != null)
             {
                 diagram.SubscribeCompartmentItemsEvents();
             }
         }
     }
 }
Ejemplo n.º 4
0
			/// <summary>
			/// Reroute a connector when the role players of its underlying relationship change
			/// </summary>
			public override void RolePlayerChanged(DslModeling::RolePlayerChangedEventArgs e)
			{
				if (e == null) throw new global::System.ArgumentNullException("e");
	
				global::System.Collections.ObjectModel.ReadOnlyCollection<DslDiagrams::PresentationViewsSubject> connectorLinks = DslDiagrams::PresentationViewsSubject.GetLinksToPresentation(e.ElementLink);
				foreach (DslDiagrams::PresentationViewsSubject connectorLink in connectorLinks)
				{
					// Fix up any binary link shapes attached to the element link.
					DslDiagrams::BinaryLinkShape linkShape = connectorLink.Presentation as DslDiagrams::BinaryLinkShape;
					if (linkShape != null)
					{
						global::Company.OrmLanguage.OrmLanguageDiagram diagram = linkShape.Diagram as global::Company.OrmLanguage.OrmLanguageDiagram;
						if (diagram != null)
						{
							if (e.NewRolePlayer != null)
							{
								DslDiagrams::NodeShape fromShape;
								DslDiagrams::NodeShape toShape;
								diagram.GetSourceAndTargetForConnector(linkShape, out fromShape, out toShape);
								if (fromShape != null && toShape != null)
								{
									if (!object.Equals(fromShape, linkShape.FromShape))
									{
										linkShape.FromShape = fromShape;
									}
									if (!object.Equals(linkShape.ToShape, toShape))
									{
										linkShape.ToShape = toShape;
									}
								}
								else
								{
									// delete the connector if we cannot find an appropriate target shape.
									linkShape.Delete();
								}
							}
							else
							{
								// delete the connector if the new role player is null.
								linkShape.Delete();
							}
						}
					}
				}
			}