private global::System.IO.MemoryStream InternalSaveDiagram2(DslModeling::SerializationResult serializationResult, PatternModelSchemaDiagram 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 = PatternModelSerializationHelper.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; }
/// <summary> /// Creates a new view digram for the pattern model. /// </summary> /// <param name="patternModel">The pattern model</param> /// <param name="docData">The document window data</param> /// <returns></returns> public static Guid CreateNewViewDiagram(PatternModelSchema patternModel, ModelingDocData docData) { Guard.NotNull(() => patternModel, patternModel); Guard.NotNull(() => docData, docData); // Create a new diagram file var docView = docData.DocViews.FirstOrDefault() as SingleDiagramDocView; PatternModelSchemaDiagram diagram = null; patternModel.Store.TransactionManager.DoWithinTransaction(() => { diagram = PatternModelSerializationHelper.CreatePatternModelSchemaDiagram( new SerializationResult(), patternModel.Store.DefaultPartition, patternModel.Store.GetRootElement(), string.Empty); }); if (diagram != null) { SetCurrentDiagram(docView, diagram, patternModel.Pattern); FixUpDiagram(patternModel, patternModel.Pattern, diagram.Id.ToString(), PresentationViewsSubject.GetPresentation(patternModel.Pattern).OfType <ShapeElement>()); return(diagram.Id); } return(Guid.Empty); }
internal static PatternModelSchemaDiagram CreatePatternModelSchemaDiagram(DslModeling.SerializationResult serializationResult, DslModeling.Partition diagramPartition, PatternModelSchema modelRoot, string diagramId) { var diagram = new PatternModelSchemaDiagram( diagramPartition.Store, new DslModeling.PropertyAssignment(DslDiagrams.Diagram.NameDomainPropertyId, diagramId), new DslModeling.PropertyAssignment( DslModeling.ElementFactory.IdPropertyAssignment, !string.IsNullOrEmpty(diagramId) ? new Guid(diagramId) : Guid.NewGuid())); diagram.ModelElement = modelRoot; diagram.PostDeserialization(true); DoCheckForOrphanedShapes(diagram, serializationResult); return(diagram); }
private void LoadDiagram( DslModeling.SerializationResult serializationResult, DslModeling.Partition diagramPartition, PatternModelSchema modelRoot, DslModeling.DomainXmlSerializerDirectory directory, DslModeling.DomainClassXmlSerializer diagramSerializer, string diagramFileName, DslModeling.ISchemaResolver schemaResolver, ValidationController validationController) { if (diagramSerializer != null) { PatternModelSchemaDiagram diagram = null; using (FileStream fileStream = File.OpenRead(diagramFileName)) { var serializationContext = new DslModeling.SerializationContext(directory, fileStream.Name, serializationResult); this.InitializeSerializationContext(diagramPartition, serializationContext, true); var transactionContext = new DslModeling.TransactionContext(); transactionContext.Add(DslModeling.SerializationContext.TransactionContextKey, serializationContext); using (var transaction = diagramPartition.Store.TransactionManager.BeginTransaction(Resources.PatternModelSerializationHelper_TransactionDescriptionLoadingDiagram, true, transactionContext)) { // Ensure there is some content in the file. Blank (or almost blank, to account for encoding header bytes, etc.) // files will cause a new diagram to be created and returned if (fileStream.Length > 5) { var settings = PatternModelSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false); try { using (var reader = XmlReader.Create(fileStream, settings)) { reader.MoveToContent(); diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as PatternModelSchemaDiagram; if (diagram != null) { this.ReadRootElement(serializationContext, diagram, reader, schemaResolver); } } } catch (XmlException ex) { DslModeling.SerializationUtilities.AddMessage(serializationContext, DslModeling.SerializationMessageKind.Error, ex); } if (serializationResult.Failed) { // Serialization error encountered, rollback the transaction. diagram = null; transaction.Rollback(); } } if (diagram == null && !serializationResult.Failed) { // Create diagram if it doesn't exist if (diagramFileName.EndsWith(DesignerConstants.DiagramFileExtension, StringComparison.OrdinalIgnoreCase)) { diagram = new PatternModelSchemaDiagram( diagramPartition.Store, new DslModeling.PropertyAssignment(DslDiagrams.Diagram.NameDomainPropertyId, Guid.NewGuid())); } else { diagram = this.CreateDiagramHelper(diagramPartition, modelRoot); } } if (transaction.IsActive) { transaction.Commit(); } } // End inner Tx // Do load-time validation if a ValidationController is provided. if (!serializationResult.Failed && validationController != null) { using (new SerializationValidationObserver(serializationResult, validationController)) { validationController.Validate(diagramPartition, ValidationCategories.Load); } } } if (diagram != null) { if (!serializationResult.Failed) { // Succeeded. diagram.ModelElement = modelRoot; diagram.PostDeserialization(true); this.CheckForOrphanedShapes(diagram, serializationResult); } else { // Failed. diagram.PostDeserialization(false); } } } }
internal static PatternModelSchemaDiagram CreatePatternModelSchemaDiagram(DslModeling.SerializationResult serializationResult, DslModeling.Partition diagramPartition, PatternModelSchema modelRoot, string diagramId) { var diagram = new PatternModelSchemaDiagram( diagramPartition.Store, new DslModeling.PropertyAssignment(DslDiagrams.Diagram.NameDomainPropertyId, diagramId), new DslModeling.PropertyAssignment( DslModeling.ElementFactory.IdPropertyAssignment, !string.IsNullOrEmpty(diagramId) ? new Guid(diagramId) : Guid.NewGuid())); diagram.ModelElement = modelRoot; diagram.PostDeserialization(true); DoCheckForOrphanedShapes(diagram, serializationResult); return diagram; }
private static void SetCurrentDiagram(SingleDiagramDocView docview, PatternModelSchemaDiagram diagram, PatternSchema pattern) { docview.Diagram = diagram; pattern.WithTransaction(prod => prod.CurrentDiagramId = diagram.Id.ToString()); }
private static void SetCurrentDiagram(SingleDiagramDocView docview, PatternModelSchemaDiagram diagram, PatternSchema pattern) { docview.Diagram = diagram; pattern.WithTransaction(prod => prod.CurrentDiagramId = diagram.Id.ToString()); }
internal virtual void SaveDiagram(DslModeling::SerializationResult serializationResult, PatternModelSchemaDiagram 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">PatternModelSchemaDiagram 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 SaveDiagram(DslModeling::SerializationResult serializationResult, PatternModelSchemaDiagram 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">PatternModelSchemaDiagram to be saved.</param> /// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param> internal virtual void SaveDiagram(DslModeling::SerializationResult serializationResult, PatternModelSchemaDiagram diagram, string diagramFileName) { this.SaveDiagram(serializationResult, diagram, diagramFileName, global::System.Text.Encoding.UTF8, false); }
internal virtual PatternModelSchemaDiagram CreateDiagramHelper(DslModeling::Partition diagramPartition, DslModeling::ModelElement modelRoot) { PatternModelSchemaDiagram diagram = new PatternModelSchemaDiagram(diagramPartition); return diagram; }
/// <summary> /// Gets the represented view. /// </summary> /// <param name="diagram">The diagram.</param> /// <returns>The view represented by the diagram.</returns> internal static ViewSchema GetRepresentedView(this PatternModelSchemaDiagram diagram) { return(diagram.Store.GetViews().Single(view => diagram.IsViewRepresented(view))); }
/// <summary> /// Determines whether [is view represented] [the specified diagram]. /// </summary> /// <param name="diagram">The diagram.</param> /// <param name="view">The view to verify.</param> /// <returns> /// <c>true</c> if [is view represented] [the specified diagram]; otherwise, <c>false</c>. /// </returns> internal static bool IsViewRepresented(this PatternModelSchemaDiagram diagram, ViewSchema view) { return(diagram.Id.ToString().Equals(view.DiagramId, StringComparison.OrdinalIgnoreCase)); }
private void LoadDiagram( DslModeling.SerializationResult serializationResult, DslModeling.Partition diagramPartition, PatternModelSchema modelRoot, DslModeling.DomainXmlSerializerDirectory directory, DslModeling.DomainClassXmlSerializer diagramSerializer, string diagramFileName, DslModeling.ISchemaResolver schemaResolver, ValidationController validationController) { if (diagramSerializer != null) { PatternModelSchemaDiagram diagram = null; using (FileStream fileStream = File.OpenRead(diagramFileName)) { var serializationContext = new DslModeling.SerializationContext(directory, fileStream.Name, serializationResult); this.InitializeSerializationContext(diagramPartition, serializationContext, true); var transactionContext = new DslModeling.TransactionContext(); transactionContext.Add(DslModeling.SerializationContext.TransactionContextKey, serializationContext); using (var transaction = diagramPartition.Store.TransactionManager.BeginTransaction(Resources.PatternModelSerializationHelper_TransactionDescriptionLoadingDiagram, true, transactionContext)) { // Ensure there is some content in the file. Blank (or almost blank, to account for encoding header bytes, etc.) // files will cause a new diagram to be created and returned if (fileStream.Length > 5) { var settings = PatternModelSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false); try { using (var reader = XmlReader.Create(fileStream, settings)) { reader.MoveToContent(); diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as PatternModelSchemaDiagram; if (diagram != null) { this.ReadRootElement(serializationContext, diagram, reader, schemaResolver); } } } catch (XmlException ex) { DslModeling.SerializationUtilities.AddMessage(serializationContext, DslModeling.SerializationMessageKind.Error, ex); } if (serializationResult.Failed) { // Serialization error encountered, rollback the transaction. diagram = null; transaction.Rollback(); } } if (diagram == null && !serializationResult.Failed) { // Create diagram if it doesn't exist if (diagramFileName.EndsWith(DesignerConstants.DiagramFileExtension, StringComparison.OrdinalIgnoreCase)) { diagram = new PatternModelSchemaDiagram( diagramPartition.Store, new DslModeling.PropertyAssignment(DslDiagrams.Diagram.NameDomainPropertyId, Guid.NewGuid())); } else { diagram = this.CreateDiagramHelper(diagramPartition, modelRoot); } } if (transaction.IsActive) { transaction.Commit(); } } // End inner Tx // Do load-time validation if a ValidationController is provided. if (!serializationResult.Failed && validationController != null) { using (new SerializationValidationObserver(serializationResult, validationController)) { validationController.Validate(diagramPartition, ValidationCategories.Load); } } } if (diagram != null) { if (!serializationResult.Failed) { // Succeeded. diagram.ModelElement = modelRoot; diagram.PostDeserialization(true); this.CheckForOrphanedShapes(diagram, serializationResult); } else { // Failed. diagram.PostDeserialization(false); } } } }
private global::System.IO.MemoryStream InternalSaveDiagram2(DslModeling::SerializationResult serializationResult, PatternModelSchemaDiagram 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 = PatternModelSerializationHelper.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); }