Exemple #1
0
		public virtual void SaveDiagram(DslModeling::SerializationResult serializationResult, SqlMapperMappingDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (diagram == null)
				throw new global::System.ArgumentNullException("diagram");
			if (string.IsNullOrEmpty(diagramFileName))
				throw new global::System.ArgumentNullException("diagramFileName");
			#endregion
	
			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 (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());
							}
						}
					}
				}
			}
		}
Exemple #2
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="diagram">SqlMapperMappingDiagram to be saved.</param>
		/// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param>
		public virtual void SaveDiagram(DslModeling::SerializationResult serializationResult, SqlMapperMappingDiagram diagram, string diagramFileName)
		{
			this.SaveDiagram(serializationResult, diagram, diagramFileName, global::System.Text.Encoding.UTF8, false);
		}
Exemple #3
0
		/// <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="diagram">SqlMapperMappingDiagram 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 SaveDiagram(DslModeling::SerializationResult serializationResult, SqlMapperMappingDiagram diagram, string diagramFileName, bool writeOptionalPropertiesWithDefaultValue)
		{
			this.SaveDiagram(serializationResult, diagram, diagramFileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue);
		}
Exemple #4
0
		internal global::System.IO.MemoryStream InternalSaveDiagram(DslModeling::SerializationResult serializationResult, SqlMapperMappingDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			global::System.Diagnostics.Debug.Assert(serializationResult != null);
			global::System.Diagnostics.Debug.Assert(diagram != null);
			global::System.Diagnostics.Debug.Assert(!serializationResult.Failed);
			#endregion
	
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(diagram.Store);
	
			
			global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
			
			DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, diagramFileName, serializationResult);
			this.InitializeSerializationContext(diagram.Partition, serializationContext, false);
			// MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
			serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
			global::System.Xml.XmlWriterSettings settings = SqlMapperMappingSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, true, encoding);
			using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
			{
				this.WriteRootElement(serializationContext, diagram, writer);
			}
	
			return newFileContent;
		}
Exemple #5
0
		internal protected virtual SqlMapperMappingDiagram CreateDiagramHelper(DslModeling::Partition diagramPartition, DslModeling::ModelElement modelRoot)
		{
			SqlMapperMappingDiagram diagram = new SqlMapperMappingDiagram(diagramPartition);
			return diagram;
		}
Exemple #6
0
		public static DslModeling::LinkedElementCollection<EntityShape> GetEntityShapes(SqlMapperMappingDiagram element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<EntityShape>, EntityShape>(element, SqlMapperMappingDiagramDomainRoleId);
		}
Exemple #7
0
		/// <summary>
		/// Constructor
		/// Creates a SqlMapperMappingDiagramReferencesEntityShapes link in the same Partition as the given SqlMapperMappingDiagram
		/// </summary>
		/// <param name="source">SqlMapperMappingDiagram to use as the source of the relationship.</param>
		/// <param name="target">EntityShape to use as the target of the relationship.</param>
		public SqlMapperMappingDiagramReferencesEntityShapes(SqlMapperMappingDiagram source, EntityShape target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(SqlMapperMappingDiagramReferencesEntityShapes.SqlMapperMappingDiagramDomainRoleId, source), new DslModeling::RoleAssignment(SqlMapperMappingDiagramReferencesEntityShapes.EntityShapeDomainRoleId, target)}, null)
		{
		}
Exemple #8
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, SqlMapperMappingDiagram element, global::System.Xml.XmlWriter writer)
		{
			// SqlMapperMappingDiagramReferencesEntityShapes
			global::System.Collections.ObjectModel.ReadOnlyCollection<SqlMapperMappingDiagramReferencesEntityShapes> allSqlMapperMappingDiagramReferencesEntityShapesInstances = SqlMapperMappingDiagramReferencesEntityShapes.GetLinksToEntityShapes(element);
			if (!serializationContext.Result.Failed && allSqlMapperMappingDiagramReferencesEntityShapesInstances.Count > 0)
			{
				writer.WriteStartElement("entityShapes");
				foreach (SqlMapperMappingDiagramReferencesEntityShapes eachSqlMapperMappingDiagramReferencesEntityShapesInstance in allSqlMapperMappingDiagramReferencesEntityShapesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachSqlMapperMappingDiagramReferencesEntityShapesInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachSqlMapperMappingDiagramReferencesEntityShapesInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachSqlMapperMappingDiagramReferencesEntityShapesInstance, writer);
				}
				writer.WriteEndElement();
			}
	
		}
Exemple #9
0
		private static void ReadSqlMapperMappingDiagramReferencesEntityShapesInstances(DslModeling::SerializationContext serializationContext, SqlMapperMappingDiagram element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newSqlMapperMappingDiagramReferencesEntityShapesSerializer = serializationContext.Directory.GetSerializer(SqlMapperMappingDiagramReferencesEntityShapes.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newSqlMapperMappingDiagramReferencesEntityShapesSerializer != null, "Cannot find serializer for SqlMapperMappingDiagramReferencesEntityShapes!");
				SqlMapperMappingDiagramReferencesEntityShapes newSqlMapperMappingDiagramReferencesEntityShapes = newSqlMapperMappingDiagramReferencesEntityShapesSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as SqlMapperMappingDiagramReferencesEntityShapes;
				if (newSqlMapperMappingDiagramReferencesEntityShapes != null)
				{
					DslModeling::DomainRoleInfo.SetRolePlayer (newSqlMapperMappingDiagramReferencesEntityShapes, SqlMapperMappingDiagramReferencesEntityShapes.SqlMapperMappingDiagramDomainRoleId, element);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newSqlMapperMappingDiagramReferencesEntityShapes.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newSqlMapperMappingDiagramReferencesEntityShapes.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newSqlMapperMappingDiagramReferencesEntityShapes, reader);
				}
				else
				{	// Maybe the relationship is serialized in short-form by mistake.
					DslModeling::DomainClassXmlSerializer newEntityShapeMonikerOfSqlMapperMappingDiagramReferencesEntityShapesSerializer = serializationContext.Directory.GetSerializer(EntityShape.DomainClassId);
					global::System.Diagnostics.Debug.Assert(newEntityShapeMonikerOfSqlMapperMappingDiagramReferencesEntityShapesSerializer != null, "Cannot find serializer for EntityShape!");
					DslModeling::Moniker newEntityShapeMonikerOfSqlMapperMappingDiagramReferencesEntityShapes = newEntityShapeMonikerOfSqlMapperMappingDiagramReferencesEntityShapesSerializer.TryCreateMonikerInstance(serializationContext, reader, element, SqlMapperMappingDiagramReferencesEntityShapes.DomainClassId, element.Partition);
					if (newEntityShapeMonikerOfSqlMapperMappingDiagramReferencesEntityShapes != null)
					{
						SqlMapperMappingSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(SqlMapperMappingDiagramReferencesEntityShapes));
						new SqlMapperMappingDiagramReferencesEntityShapes(element.Partition, new DslModeling::RoleAssignment(SqlMapperMappingDiagramReferencesEntityShapes.SqlMapperMappingDiagramDomainRoleId, element), new DslModeling::RoleAssignment(SqlMapperMappingDiagramReferencesEntityShapes.EntityShapeDomainRoleId, newEntityShapeMonikerOfSqlMapperMappingDiagramReferencesEntityShapes));
						DslModeling::SerializationUtilities.Skip(reader);	// Moniker contains no child XML elements, so just skip.
					}
					else
					{	// Unknown element, skip.
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
Exemple #10
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 SqlMapperMappingDiagram instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, SqlMapperMappingDiagram element, global::System.Xml.XmlReader reader)
		{
			if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				if (string.Compare(reader.LocalName, "entityShapes", global::System.StringComparison.CurrentCulture) == 0)
				{
					if (reader.IsEmptyElement)
					{	// No instance of this relationship, just skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
					else
					{
						DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <entityShapes>
						ReadSqlMapperMappingDiagramReferencesEntityShapesInstances(serializationContext, element, reader);
						DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </entityShapes>
					}
				}
			}
		}