/// <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">Design instance to be saved.</param>
		/// <param name="fileName">Name of the file in which the Design instance will be saved.</param>
		/// <param name="writeOptionalPropertiesWithDefaultValue">Whether optional properties with default value will be saved.</param>
		internal virtual void SaveModel(DslModeling::SerializationResult serializationResult, Design modelRoot, string fileName, bool writeOptionalPropertiesWithDefaultValue)
		{
			this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue);
		}
		internal global::System.IO.MemoryStream InternalSaveModel(DslModeling::SerializationResult serializationResult, Design 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 = WorkflowDesignSerializationHelper.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;
		}
		internal static DslModeling::LinkedElementCollection<VariabilityRequirement> GetVariabilityRequirements(Design element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<VariabilityRequirement>, VariabilityRequirement>(element, DesignDomainRoleId);
		}
		/// <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">Design instance to be saved.</param>
		/// <param name="fileName">Name of the file in which the Design instance will be saved.</param>
		internal virtual void SaveModel(DslModeling::SerializationResult serializationResult, Design modelRoot, string fileName)
		{
			this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, false);
		}
Пример #5
0
		/// <summary>
		/// Reads all instances of relationship DesignHasVariabilityRequirements.
		/// </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 Design instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadDesignHasVariabilityRequirementsInstances(DslModeling::SerializationContext serializationContext, Design element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newDesignHasVariabilityRequirementsSerializer = serializationContext.Directory.GetSerializer(DesignHasVariabilityRequirements.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newDesignHasVariabilityRequirementsSerializer != null, "Cannot find serializer for DesignHasVariabilityRequirements!");
				DesignHasVariabilityRequirements newDesignHasVariabilityRequirements = newDesignHasVariabilityRequirementsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as DesignHasVariabilityRequirements;
				if (newDesignHasVariabilityRequirements != null)
				{
					DslModeling::DomainRoleInfo.SetRolePlayer (newDesignHasVariabilityRequirements, DesignHasVariabilityRequirements.DesignDomainRoleId, element);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDesignHasVariabilityRequirements.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDesignHasVariabilityRequirements.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newDesignHasVariabilityRequirements, reader);
				}
				else
				{	// Maybe the relationship is serialized in short-form by mistake.
					DslModeling::DomainClassXmlSerializer newVariabilityRequirementOfDesignHasVariabilityRequirementsSerializer = serializationContext.Directory.GetSerializer(VariabilityRequirement.DomainClassId);
					global::System.Diagnostics.Debug.Assert(newVariabilityRequirementOfDesignHasVariabilityRequirementsSerializer != null, "Cannot find serializer for VariabilityRequirement!");
					VariabilityRequirement newVariabilityRequirementOfDesignHasVariabilityRequirements = newVariabilityRequirementOfDesignHasVariabilityRequirementsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as VariabilityRequirement;
					if (newVariabilityRequirementOfDesignHasVariabilityRequirements != null)
					{
						WorkflowDesignSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(DesignHasVariabilityRequirements));
						element.VariabilityRequirements.Add(newVariabilityRequirementOfDesignHasVariabilityRequirements);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newVariabilityRequirementOfDesignHasVariabilityRequirements.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newVariabilityRequirementOfDesignHasVariabilityRequirements.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newVariabilityRequirementOfDesignHasVariabilityRequirements, reader);
					}
					else
					{	// Unknown element, skip.
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
		internal static void SetDesign(VariabilityRequirement element, Design newDesign)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, VariabilityRequirementDomainRoleId, newDesign);
		}
		internal static void SetDesign(Asset element, Design newDesign)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, AssetDomainRoleId, newDesign);
		}
		/// <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">Design instance to be saved.</param>
		/// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param>
		/// <param name="diagram">WorkflowDesignDiagram 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>
		internal virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, Design modelRoot, string modelFileName, WorkflowDesignDiagram diagram, string diagramFileName, bool writeOptionalPropertiesWithDefaultValue)
		{
			this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue);
		}
		internal static DslModeling::LinkedElementCollection<ProductionTool> GetProductionTools(Design element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<ProductionTool>, ProductionTool>(element, DesignDomainRoleId);
		}
Пример #10
0
		/// <summary>
		/// Constructor
		/// Creates a DesignHasAssets link in the same Partition as the given Design
		/// </summary>
		/// <param name="source">Design to use as the source of the relationship.</param>
		/// <param name="target">Asset to use as the target of the relationship.</param>
		internal DesignHasAssets(Design source, Asset target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DesignHasAssets.DesignDomainRoleId, source), new DslModeling::RoleAssignment(DesignHasAssets.AssetDomainRoleId, target)}, null)
		{
		}
Пример #11
0
		internal static void SetDesign(ProductionTool element, Design newDesign)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ProductionToolDomainRoleId, newDesign);
		}
Пример #12
0
		/// <summary>
		/// Constructor
		/// Creates a DesignHasProductionTools link in the same Partition as the given Design
		/// </summary>
		/// <param name="source">Design to use as the source of the relationship.</param>
		/// <param name="target">ProductionTool to use as the target of the relationship.</param>
		internal DesignHasProductionTools(Design source, ProductionTool target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DesignHasProductionTools.DesignDomainRoleId, source), new DslModeling::RoleAssignment(DesignHasProductionTools.ProductionToolDomainRoleId, target)}, null)
		{
		}
Пример #13
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, Design element, global::System.Xml.XmlWriter writer)
		{
			// DesignHasProductionTools
			global::System.Collections.ObjectModel.ReadOnlyCollection<DesignHasProductionTools> allDesignHasProductionToolsInstances = DesignHasProductionTools.GetLinksToProductionTools(element);
			if (!serializationContext.Result.Failed && allDesignHasProductionToolsInstances.Count > 0)
			{
				writer.WriteStartElement("productionTools");
				foreach (DesignHasProductionTools eachDesignHasProductionToolsInstance in allDesignHasProductionToolsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachDesignHasProductionToolsInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachDesignHasProductionToolsInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachDesignHasProductionToolsInstance, writer);
				}
				writer.WriteEndElement();
			}
	
			// DesignHasAssets
			global::System.Collections.ObjectModel.ReadOnlyCollection<DesignHasAssets> allDesignHasAssetsInstances = DesignHasAssets.GetLinksToAssets(element);
			if (!serializationContext.Result.Failed && allDesignHasAssetsInstances.Count > 0)
			{
				writer.WriteStartElement("assets");
				foreach (DesignHasAssets eachDesignHasAssetsInstance in allDesignHasAssetsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachDesignHasAssetsInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachDesignHasAssetsInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachDesignHasAssetsInstance, writer);
				}
				writer.WriteEndElement();
			}
	
			// DesignHasVariabilityRequirements
			global::System.Collections.ObjectModel.ReadOnlyCollection<DesignHasVariabilityRequirements> allDesignHasVariabilityRequirementsInstances = DesignHasVariabilityRequirements.GetLinksToVariabilityRequirements(element);
			if (!serializationContext.Result.Failed && allDesignHasVariabilityRequirementsInstances.Count > 0)
			{
				writer.WriteStartElement("variabilityRequirements");
				foreach (DesignHasVariabilityRequirements eachDesignHasVariabilityRequirementsInstance in allDesignHasVariabilityRequirementsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachDesignHasVariabilityRequirementsInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachDesignHasVariabilityRequirementsInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachDesignHasVariabilityRequirementsInstance, writer);
				}
				writer.WriteEndElement();
			}
	
		}
Пример #14
0
		/// <summary>
		/// Helper method to create and initialize a new Design.
		/// </summary>
		internal virtual Design CreateModelHelper(DslModeling::Partition modelPartition)
		{
			Design model = new Design(modelPartition);
			return model;
		}
Пример #15
0
		internal static DslModeling::LinkedElementCollection<Asset> GetAssets(Design element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<Asset>, Asset>(element, DesignDomainRoleId);
		}
Пример #16
0
		/// <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">Design instance to be saved.</param>
		/// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param>
		/// <param name="diagram">WorkflowDesignDiagram to be saved.</param>
		/// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param>
		internal virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, Design modelRoot, string modelFileName, WorkflowDesignDiagram diagram, string diagramFileName)
		{
			this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, false);
		}
Пример #17
0
		/// <summary>
		/// Constructor
		/// Creates a DesignHasVariabilityRequirements link in the same Partition as the given Design
		/// </summary>
		/// <param name="source">Design to use as the source of the relationship.</param>
		/// <param name="target">VariabilityRequirement to use as the target of the relationship.</param>
		internal DesignHasVariabilityRequirements(Design source, VariabilityRequirement target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DesignHasVariabilityRequirements.DesignDomainRoleId, source), new DslModeling::RoleAssignment(DesignHasVariabilityRequirements.VariabilityRequirementDomainRoleId, target)}, null)
		{
		}
Пример #18
0
		internal virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, Design modelRoot, string modelFileName, WorkflowDesignDiagram 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());
								}
							}
						}
					}
				}
			}
		}
Пример #19
0
		/// <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 that 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 Design instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, Design element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "productionTools":	// Relationship "DesignHasProductionTools"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <productionTools>
							ReadDesignHasProductionToolsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </productionTools>
						}
						break;
					case "assets":	// Relationship "DesignHasAssets"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <assets>
							ReadDesignHasAssetsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </assets>
						}
						break;
					case "variabilityRequirements":	// Relationship "DesignHasVariabilityRequirements"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <variabilityRequirements>
							ReadDesignHasVariabilityRequirementsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </variabilityRequirements>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}