/// <summary>
		/// Helper method to create and initialize a new ExampleModel.
		/// </summary>
		internal protected virtual ExampleModel CreateModelHelper(DslModeling::Partition modelPartition)
		{
			ExampleModel model = new ExampleModel(modelPartition);
			return model;
		}
		/// <summary>
		/// Saves the given diagram to the given file, with default encoding (UTF-8), and optional properties with default value will not
		/// be written out.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">ExampleModel instance to be saved.</param>
		/// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param>
		/// <param name="diagram">AsyncDslDiagram to be saved.</param>
		/// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param>
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, ExampleModel modelRoot, string modelFileName, AsyncDslDiagram diagram, string diagramFileName)
		{
			this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, false);
		}
		/// <summary>
		/// Saves the given model to the given file, with default encoding (UTF-8).
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">ExampleModel instance to be saved.</param>
		/// <param name="fileName">Name of the file in which the ExampleModel instance will be saved.</param>
		/// <param name="writeOptionalPropertiesWithDefaultValue">Whether optional properties with default value will be saved.</param>
		public virtual void SaveModel(DslModeling::SerializationResult serializationResult, ExampleModel modelRoot, string fileName, bool writeOptionalPropertiesWithDefaultValue)
		{
			this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue);
		}
		private global::System.IO.MemoryStream InternalSaveModel(DslModeling::SerializationResult serializationResult, ExampleModel modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			global::System.Diagnostics.Debug.Assert(serializationResult != null);
			global::System.Diagnostics.Debug.Assert(modelRoot != null);
			global::System.Diagnostics.Debug.Assert(!serializationResult.Failed);
			#endregion
			
			global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
			
			DslModeling::DomainClassXmlSerializer modelRootSerializer = this.Directory.GetSerializer(modelRoot.GetDomainClass().Id);
			global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for " + modelRoot.GetDomainClass().Name + "!");
			if (modelRootSerializer != null)
			{
				DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, fileName, serializationResult);
				// MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
				serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
				global::System.Xml.XmlWriterSettings settings = new global::System.Xml.XmlWriterSettings();
				settings.Indent = true;
				settings.Encoding = encoding;
				using (global::System.IO.StreamWriter streamWriter = new global::System.IO.StreamWriter(newFileContent, encoding))
				{
					using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(streamWriter, settings))
					{
						modelRootSerializer.WriteRootElement(serializationContext, modelRoot, writer);
					}
				}
			}
			return newFileContent;
		}
		public static DslModeling::LinkedElementCollection<Comment> GetComments(ExampleModel element)
		{
			return new DslModeling::LinkedElementCollection<Comment>(element, ExampleModelDomainRoleId);
		}
		/// <summary>
		/// Saves the given model root to the given file, with default encoding (UTF-8), and optional properties with default value will not
		/// be written out.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">ExampleModel instance to be saved.</param>
		/// <param name="fileName">Name of the file in which the ExampleModel instance will be saved.</param>
		public virtual void SaveModel(DslModeling::SerializationResult serializationResult, ExampleModel modelRoot, string fileName)
		{
			this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, false);
		}
		/// <summary>
		/// Constructor
		/// Creates a ExampleModelHasComments link in the same Partition as the given ExampleModel
		/// </summary>
		/// <param name="source">ExampleModel to use as the source of the relationship.</param>
		/// <param name="target">Comment to use as the target of the relationship.</param>
		public ExampleModelHasComments(ExampleModel source, Comment target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ExampleModelHasComments.ExampleModelDomainRoleId, source), new DslModeling::RoleAssignment(ExampleModelHasComments.CommentDomainRoleId, target)}, null)
		{
		}
		/// <summary>
		/// This method deserializes all child model elements.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first child XML element to deserialized.
		/// This method will read as many child elements as it can. It returns under three circumstances:
		/// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the 
		///    open tag of the unknown element. This implies the if the first child XML element is unknown, this method 
		///    should return immediately and do nothing.
		/// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element.
		/// 3) EOF.
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		/// <param name="element">In-memory ExampleModel instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, ExampleModel element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "processes":	// Relationship "ExampleModelHasProcesses"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <processes>
							ReadExampleModelHasProcessesInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </processes>
						}
						break;
					case "comments":	// Relationship "ExampleModelHasComments"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <comments>
							ReadExampleModelHasCommentsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </comments>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}
		public static DslModeling::LinkedElementCollection<Process> GetProcesses(ExampleModel element)
		{
			return new DslModeling::LinkedElementCollection<Process>(element, ExampleModelDomainRoleId);
		}
		/// <summary>
		/// Constructor
		/// Creates a ExampleModelHasProcesses link in the same Partition as the given ExampleModel
		/// </summary>
		/// <param name="source">ExampleModel to use as the source of the relationship.</param>
		/// <param name="target">Process to use as the target of the relationship.</param>
		public ExampleModelHasProcesses(ExampleModel source, Process target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ExampleModelHasProcesses.ExampleModelDomainRoleId, source), new DslModeling::RoleAssignment(ExampleModelHasProcesses.ProcessDomainRoleId, target)}, null)
		{
		}
		public static void SetExampleModel(Process element, ExampleModel newExampleModel)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ProcessDomainRoleId, newExampleModel);
		}
예제 #12
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, ExampleModel element, global::System.Xml.XmlWriter writer)
		{
			// ExampleModelHasProcesses
			global::System.Collections.ObjectModel.ReadOnlyCollection<ExampleModelHasProcesses> allExampleModelHasProcessesInstances = ExampleModelHasProcesses.GetLinksToProcesses(element);
			if (!serializationContext.Result.Failed && allExampleModelHasProcessesInstances.Count > 0)
			{
				writer.WriteStartElement("processes");
				global::System.Type typeofExampleModelHasProcesses = typeof(ExampleModelHasProcesses);
				foreach (ExampleModelHasProcesses eachExampleModelHasProcessesInstance in allExampleModelHasProcessesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachExampleModelHasProcessesInstance.GetType() != typeofExampleModelHasProcesses)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachExampleModelHasProcessesInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachExampleModelHasProcessesInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachExampleModelHasProcessesInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachExampleModelHasProcessesInstance.Process;
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");			
						targetSerializer.Write(serializationContext, targetElement, writer);
					}
				}
				writer.WriteEndElement();
			}
	
			// ExampleModelHasComments
			global::System.Collections.ObjectModel.ReadOnlyCollection<ExampleModelHasComments> allExampleModelHasCommentsInstances = ExampleModelHasComments.GetLinksToComments(element);
			if (!serializationContext.Result.Failed && allExampleModelHasCommentsInstances.Count > 0)
			{
				writer.WriteStartElement("comments");
				global::System.Type typeofExampleModelHasComments = typeof(ExampleModelHasComments);
				foreach (ExampleModelHasComments eachExampleModelHasCommentsInstance in allExampleModelHasCommentsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachExampleModelHasCommentsInstance.GetType() != typeofExampleModelHasComments)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachExampleModelHasCommentsInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachExampleModelHasCommentsInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachExampleModelHasCommentsInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachExampleModelHasCommentsInstance.Comment;
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");			
						targetSerializer.Write(serializationContext, targetElement, writer);
					}
				}
				writer.WriteEndElement();
			}
	
		}
예제 #13
0
		/// <summary>
		/// Reads all instances of relationship ExampleModelHasComments.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be
		/// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the
		/// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens).
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="element">In-memory ExampleModel instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadExampleModelHasCommentsInstances(DslModeling::SerializationContext serializationContext, ExampleModel element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newCommentOfExampleModelHasCommentsSerializer = serializationContext.Directory.GetSerializer(Comment.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newCommentOfExampleModelHasCommentsSerializer != null, "Cannot find serializer for Comment!");
				Comment newCommentOfExampleModelHasComments = newCommentOfExampleModelHasCommentsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as Comment;
				if (newCommentOfExampleModelHasComments != null)
				{
					element.Comments.Add(newCommentOfExampleModelHasComments);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newCommentOfExampleModelHasComments.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newCommentOfExampleModelHasComments.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newCommentOfExampleModelHasComments, reader);
				}
				else
				{
					global::System.Type typeofExampleModelHasComments = typeof(ExampleModelHasComments);
					DslModeling::DomainRelationshipXmlSerializer newExampleModelHasCommentsSerializer = serializationContext.Directory.GetSerializer(ExampleModelHasComments.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newExampleModelHasCommentsSerializer != null, "Cannot find serializer for ExampleModelHasComments!");
					ExampleModelHasComments newExampleModelHasComments = newExampleModelHasCommentsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as ExampleModelHasComments;
					if (newExampleModelHasComments != null)
					{
						if (newExampleModelHasComments.GetType() == typeofExampleModelHasComments)
						{	// The relationship should be serialized in short-form.
							AsyncDslSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(ExampleModelHasComments));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newExampleModelHasComments, ExampleModelHasComments.ExampleModelDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newExampleModelHasComments.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newExampleModelHasComments.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newExampleModelHasComments, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
		/// <summary>
		/// Saves the given diagram to the given file, with default encoding (UTF-8).
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">ExampleModel instance to be saved.</param>
		/// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param>
		/// <param name="diagram">AsyncDslDiagram to be saved.</param>
		/// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param>
		/// <param name="writeOptionalPropertiesWithDefaultValue">Whether optional properties with default value will be saved.</param>
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, ExampleModel modelRoot, string modelFileName, AsyncDslDiagram diagram, string diagramFileName, bool writeOptionalPropertiesWithDefaultValue)
		{
			this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue);
		}
		public static void SetExampleModel(Comment element, ExampleModel newExampleModel)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, CommentDomainRoleId, newExampleModel);
		}
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, ExampleModel modelRoot, string modelFileName, AsyncDslDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (string.IsNullOrEmpty(modelFileName))
				throw new global::System.ArgumentNullException("modelFileName");
			if (diagram == null)
				throw new global::System.ArgumentNullException("diagram");
			if (string.IsNullOrEmpty(diagramFileName))
				throw new global::System.ArgumentNullException("diagramFileName");
			#endregion
	
			if (serializationResult.Failed)
				return;
	
			// Save the model file first
			using (global::System.IO.MemoryStream modelFileContent = this.InternalSaveModel(serializationResult, modelRoot, modelFileName, encoding, writeOptionalPropertiesWithDefaultValue))
			{
				if (serializationResult.Failed)
					return;
	
				using (global::System.IO.MemoryStream diagramFileContent = this.InternalSaveDiagram(serializationResult, diagram, diagramFileName, encoding, writeOptionalPropertiesWithDefaultValue))
				{
					if (!serializationResult.Failed)
					{
						// Only write the contents if there's no error encountered during serialization.
						if (modelFileContent != null)
						{
							using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(modelFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
							{
								using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
								{
									writer.Write(modelFileContent.ToArray());
								}
							}
						}
						if (diagramFileContent != null)
						{
							using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(diagramFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
							{
								using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
								{
									writer.Write(diagramFileContent.ToArray());
								}
							}
						}
					}
				}
			}
		}
		internal global::System.IO.MemoryStream InternalSaveModel(DslModeling::SerializationResult serializationResult, ExampleModel modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			global::System.Diagnostics.Debug.Assert(serializationResult != null);
			global::System.Diagnostics.Debug.Assert(modelRoot != null);
			global::System.Diagnostics.Debug.Assert(!serializationResult.Failed);
			#endregion
	
			serializationResult.Encoding = encoding;
	
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store);
	
			
			global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
			
			DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileName, serializationResult);
			this.InitializeSerializationContext(modelRoot.Partition, serializationContext, false);
			// MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
			serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
			global::System.Xml.XmlWriterSettings settings = AsyncDslSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
			using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
			{
				this.WriteRootElement(serializationContext, modelRoot, writer);
			}
				
			return newFileContent;
		}