public virtual void SaveDiagram(DslModeling::SerializationResult serializationResult, OrmLanguageDiagram 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()); } } } } } }
/// <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">OrmLanguageDiagram 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, OrmLanguageDiagram diagram, string diagramFileName, bool writeOptionalPropertiesWithDefaultValue) { this.SaveDiagram(serializationResult, diagram, diagramFileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue); }
/// <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">OrmLanguageDiagram 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, OrmLanguageDiagram diagram, string diagramFileName) { this.SaveDiagram(serializationResult, diagram, diagramFileName, global::System.Text.Encoding.UTF8, false); }
/// <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">SampleOrmModel instance to be saved.</param> /// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param> /// <param name="diagram">OrmLanguageDiagram 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, SampleOrmModel modelRoot, string modelFileName, OrmLanguageDiagram diagram, string diagramFileName) { this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, false); }
internal protected virtual OrmLanguageDiagram CreateDiagramHelper(DslModeling::Partition diagramPartition, DslModeling::ModelElement modelRoot) { OrmLanguageDiagram diagram = new OrmLanguageDiagram(diagramPartition); return diagram; }
internal global::System.IO.MemoryStream InternalSaveDiagram(DslModeling::SerializationResult serializationResult, OrmLanguageDiagram 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 = OrmLanguageSerializationHelper.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; }