Beispiel #1
0
        /// <summary>
        /// This method is called during deserialization to convert a given value to a specific typed value (Int32?).
        /// </summary>
        /// <param name="serializationContext">The current serialization context instance.</param>
        /// <param name="modelELement">ModdelElement, to which the property belongs to.</param>
        /// <param name="propertyName">The Property name, which value is to be converted.</param>
        /// <param name="value">Value to convert.</param>
        /// <param name="targetType">Type, the object is to be converted to.</param>
        /// <param name="isRequired">True if this property is marked as required in the domain model. Can be null.</param>
        /// <returns>Converted value.</returns>
        public override global::System.Int32?ConvertTypedObjectInt32From(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement modelELement, string propertyName, object value, System.Type targetType, bool?isRequired)
        {
            if (value is string)
            {
                if (String.IsNullOrEmpty(value as string))
                {
                    return(null);
                }

                if (String.IsNullOrWhiteSpace(value as string))
                {
                    return(null);
                }

                try
                {
                    System.Int32?d = Convert.ToInt32(value, System.Globalization.CultureInfo.InvariantCulture);
                    return(d);
                }
                catch (Exception ex)
                {
                    serializationContext.Result.AddMessage(new DslModeling::SerializationMessage(
                                                               DslModeling::SerializationMessageKind.Error, "Couldnt convert " + value + " to Int: " + ex.ToString(), "", 0, 0, null));
                }
            }

            return(null);
        }
        /// <summary>
        /// This method creates an instance of DesignerDiagram based on the tag currently pointed by the reader. The reader is guaranteed (by the caller)
        /// to be pointed at a serialized instance of DesignerDiagram.
        /// </summary>
        /// <remarks>
        /// The caller will guarantee that the reader is positioned at open XML tag of the ModelRoot instance being read. This method should
        /// not move the reader; the reader should remain at the same position when this method returns.
        /// </remarks>
        /// <param name="serializationContext">Serialization context.</param>
        /// <param name="reader">XmlReader to read serialized data from.</param>
        /// <param name="partition">Partition in which new DesignerDiagram instance should be created.</param>
        /// <returns>Created DesignerDiagram instance.</returns>
        protected override DslModeling::ModelElement CreateInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::Partition partition)
        {
            string idStr = reader.GetAttribute("Id");

            try
            {
                global::System.Guid id;
                if (string.IsNullOrEmpty(idStr))
                {                       // Create a default Id.
                    id = global::System.Guid.NewGuid();
                    StateMachineLanguageSerializationBehaviorSerializationMessages.MissingId(serializationContext, reader, id);
                }
                else
                {
                    id = new global::System.Guid(idStr);
                }
                return(new DesignerDiagram(partition, new DslModeling::PropertyAssignment(DslModeling::ElementFactory.IdPropertyAssignment, id)));
            }
            catch (global::System.ArgumentNullException /* anEx */)
            {
                StateMachineLanguageSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "Id", typeof(global::System.Guid), idStr);
            }
            catch (global::System.FormatException /* fEx */)
            {
                StateMachineLanguageSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "Id", typeof(global::System.Guid), idStr);
            }
            catch (global::System.OverflowException /* ofEx */)
            {
                StateMachineLanguageSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "Id", typeof(global::System.Guid), idStr);
            }
            return(null);
        }
Beispiel #3
0
        private MemoryStream InternalSaveModel2(DslModeling::SerializationResult serializationResult, PatternModelSchema 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 = PatternModelSerializationHelper.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);
        }
        public override void SaveModel(DslModeling::SerializationResult serializationResult, MetaModel modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
        {
            base.SaveModel(serializationResult, modelRoot, fileName, encoding, writeOptionalPropertiesWithDefaultValue);

            System.IO.FileInfo info = new System.IO.FileInfo(fileName);
            string fileNameDiagram = info.DirectoryName + "\\" + info.Name.Remove(info.Name.Length - info.Extension.Length, info.Extension.Length) + DiagramExtension;

            // save view information
            using (global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream())
            {
                DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store);

                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 = LanguageDSLSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
                using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
                {
                    ViewSerializer serializer = directory.GetSerializer(View.DomainClassId) as ViewSerializer;
                    serializer.Write(serializationContext, modelRoot.View, writer);
                }

                if (!serializationResult.Failed && newFileContent != null)
                {	// Only write the content if there's no error encountered during serialization.
                    using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(fileNameDiagram, 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(newFileContent.ToArray());
                        }
                    }
                }
            }
        }
        private global::System.IO.MemoryStream InternalSaveDiagram(DslModeling::SerializationResult serializationResult, DslDiagrams::Diagram 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

            global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
            var directory = this.GetDirectory(diagram.Store);
            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 = EFModelSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, true, encoding);
            var diagramSerializer = GetSerializer(diagram);

            using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
            {
                //this.WriteRootElement(serializationContext, diagram, writer);
                // Carry out the normal serialization.
                this.WriteRootElement(serializationContext, diagramSerializer, diagram, writer);
            }

            return(newFileContent);
        }
        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;
        }
        private void CustomRead(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader)
        {
            DefaultRead(serializationContext, element, reader);

            ConfigurationSectionModel model = (ConfigurationSectionModel)element;

            // Make sure there's always a Validators instance in the model
            if (model.PropertyValidators == null)
            {
                model.PropertyValidators = new PropertyValidators(model.Store);
            }
        }
        /// <summary>
        /// Saves the diagram.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="serializationResult">The serialization result.</param>
        /// <param name="modelRoot">The model root.</param>
        /// <param name="modelFileName">Name of the model file.</param>
        /// <param name="diagram">The diagram.</param>
        /// <param name="diagramFileName">Name of the diagram file.</param>
        /// <param name="encoding">The encoding.</param>
        /// <param name="writeOptionalPropertiesWithDefaultValue">if set to <c>true</c> [write optional properties with default value].</param>
        public void SaveDiagram <TModel>(DslModeling::SerializationResult serializationResult, TModel modelRoot, string modelFileName, ComponentModelDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
            where TModel : ModelElement
        {
            if (serializationResult.Failed)
            {
                return;
            }

            // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.

            using (global::System.IO.MemoryStream diagramFileContent = new global::System.IO.MemoryStream())
            {
                DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id);
                global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!");
                if (diagramSerializer != null)
                {
                    DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, diagramFileName, serializationResult);
                    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(diagramFileContent, encoding))
                    {
                        using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(streamWriter, settings))
                        {
                            diagramSerializer.WriteRootElement(serializationContext, diagram, writer);
                        }
                    }
                }
                if (!serializationResult.Failed)
                {       // Only write the contents if there's no error encountered during serialization.
                    if (diagramFileContent != null)
                    {
                        IVsQueryEditQuerySave2 scc = ServiceLocator.Instance.GetService <IVsQueryEditQuerySave2>(typeof(SVsQueryEditQuerySave));
                        if (scc != null)
                        {
                            uint result;
                            if (scc.QuerySaveFile(diagramFileName, 0, null, out result) != (int)tagVSQuerySaveResult.QSR_SaveOK)
                            {
                                return;
                            }
                        }
                        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());
                            }
                        }
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// This method is called during serialization to convert a given typed value (Double?) to a specific value (string).
        /// </summary>
        /// <param name="serializationContext">The current serialization context instance.</param>
        /// <param name="modelELement">ModdelElement, to which the property belongs to.</param>
        /// <param name="propertyName">The Property name, which value is to be converted.</param>
        /// <param name="value">Typed value to convert.</param>
        /// <param name="sourceType">Type of the value.</param>
        /// <param name="isRequired">True if this property is marked as required in the domain model. Can be null.</param>
        /// <returns>Converted value.</returns>
        public override object ConvertTypedObjectDoubleTo(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement modelELement, string propertyName, object value, System.Type sourceType, bool?isRequired)
        {
            if (value != null)
            {
                if (value is Double)
                {
                    return(((Double)value).ToString(System.Globalization.CultureInfo.InvariantCulture));
                }
            }

            return("");
        }
        /// <summary>
        /// This method is called during deserialization to convert a given id as string to the id of type Guid as used by the domain model.
        /// </summary>
        /// <param name="serializationContext">The current serialization context instance.</param>
        /// <param name="id">Id as string.</param>
        /// <returns>Converted value, Id as Guid.</returns>
        public static Guid ConvertIdFrom(DslModeling::SerializationContext serializationContext, string id)
        {
            try
            {
                return(KeyGenerator.Instance.ConvertVModellIDToGuid(id));
            }
            catch (Exception ex)
            {
                serializationContext.Result.AddMessage(new DslModeling::SerializationMessage(
                                                           DslModeling::SerializationMessageKind.Error, "Couldnt convert " + id + " to Guid: " + ex.ToString(), "", 0, 0, null));

                return(Guid.Empty);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Read an element from the root of XML.
        /// </summary>
        /// <param name="serializationContext">Serialization context.</param>
        /// <param name="rootElement">In-memory element instance that will get the deserialized data.</param>
        /// <param name="reader">XmlReader to read serialized data from.</param>
        /// <param name="schemaResolver">An ISchemaResolver that allows the serializer to do schema validation on the root element (and everything inside it).</param>
        protected override void ReadRootElement(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement rootElement, global::System.Xml.XmlReader reader, DslModeling::ISchemaResolver schemaResolver)
        {
            #region Check Parameters
            global::System.Diagnostics.Debug.Assert(serializationContext != null);
            if (serializationContext == null)
            {
                throw new global::System.ArgumentNullException("serializationContext");
            }
            global::System.Diagnostics.Debug.Assert(rootElement != null);
            if (rootElement == null)
            {
                throw new global::System.ArgumentNullException("rootElement");
            }
            global::System.Diagnostics.Debug.Assert(reader != null);
            if (reader == null)
            {
                throw new global::System.ArgumentNullException("reader");
            }
            #endregion

            DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(rootElement.Store);

            DslModeling::DomainClassXmlSerializer rootSerializer = null;

            if (rootElement is DslDiagrams::Diagram)
            {
                rootSerializer = directory.GetSerializer(PatternModelSchemaDiagram.DomainClassId);
            }
            else
            {
                rootSerializer = directory.GetSerializer(rootElement.GetDomainClass().Id);
            }

            global::System.Diagnostics.Debug.Assert(rootSerializer != null, @"Cannot find serializer for " + rootElement.GetDomainClass().Name + @"!");

            // Version check.
            this.CheckVersion(serializationContext, reader);

            if (!serializationContext.Result.Failed)
            {
                // Use a validating reader if possible
                using (reader = TryCreateValidatingReader(schemaResolver, reader, serializationContext))
                {
                    rootSerializer.Read(serializationContext, rootElement, reader);
                }
            }
        }
        /// <summary>
        /// Write an element as the root of XML.
        /// </summary>
        /// <param name="serializationContext">Serialization context.</param>
        /// <param name="rootElement">Root element instance that will be serialized.</param>
        /// <param name="writer">XmlWriter to write serialized data to.</param>
        public override void WriteRootElement(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement rootElement, global::System.Xml.XmlWriter writer)
        {
            #region Check Parameters
            global::System.Diagnostics.Debug.Assert(serializationContext != null);
            if (serializationContext == null)
            {
                throw new global::System.ArgumentNullException("serializationContext");
            }
            global::System.Diagnostics.Debug.Assert(rootElement != null);
            if (rootElement == null)
            {
                throw new global::System.ArgumentNullException("rootElement");
            }
            global::System.Diagnostics.Debug.Assert(writer != null);
            if (writer == null)
            {
                throw new global::System.ArgumentNullException("writer");
            }
            #endregion

            DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(rootElement.Store);

            DslModeling::DomainClassXmlSerializer rootSerializer = null;

            if (rootElement is DslDiagrams::Diagram)
            {
                rootSerializer = directory.GetSerializer(PatternModelSchemaDiagram.DomainClassId);
            }
            else
            {
                rootSerializer = directory.GetSerializer(rootElement.GetDomainClass().Id);
            }

            global::System.Diagnostics.Debug.Assert(rootSerializer != null, "Cannot find serializer for " + rootElement.GetDomainClass().Name + "!");

            // Set up root element settings
            DslModeling::RootElementSettings rootElementSettings = new DslModeling::RootElementSettings();
            if (!(rootElement is DslDiagrams::Diagram))
            {
                // Only model has schema, diagram has no schema.
                rootElementSettings.SchemaTargetNamespace = "http://schemas.microsoft.com/visualstudio/patterning/runtime/patternmodel";
            }
            rootElementSettings.Version = new global::System.Version("1.3.0.0");

            // Carry out the normal serialization.
            rootSerializer.Write(serializationContext, rootElement, writer, rootElementSettings);
        }
Beispiel #13
0
        /// <summary>
        /// This methods serializes 1) properties serialized as nested XML elements and 2) child model elements into XML.
        /// </summary>
        /// <param name="serializationContext">Serialization context.</param>
        /// <param name="element">MetaModel instance to be serialized.</param>
        /// <param name="writer">XmlWriter to write serialized data to.</param>
        protected override void WriteElements(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer)
        {
            // Always call the base class so any extensions are serialized
            //base.WriteElements(serializationContext, element, writer);

            // Write any additional element data under this XML element
            WriteAdditionalElementData(serializationContext, element, writer);

            MetaModel instance = element as MetaModel;

            global::System.Diagnostics.Debug.Assert(instance != null, "Expecting an instance of MetaModel!");

            // Write child model elements (which are always serialized as nested XML elements).
            if (!serializationContext.Result.Failed)
            {
                WriteChildElementsExtended(serializationContext, instance, writer);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Read any extension data written inside this XML element
        /// </summary>
        /// <param name="serializationContext">The current serialization context instance.</param>
        /// <param name="element">In-memory ModelElement instance that is currently being read.</param>
        /// <param name="reader">Reader for the file being read. The reader is positioned after the attributes of the specified element.</param>
        /// <remarks>The method reads any extension element data, regardless of whether it relates the current
        /// element or not. There may be no additional data for the specified element.</remarks>
        internal protected virtual void ReadExtensions(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader)
        {
            if (serializationContext == null)
            {
                throw new global::System.ArgumentNullException("serializationContext");
            }
            if (element == null)
            {
                throw new global::System.ArgumentNullException("element");
            }
            if (reader == null)
            {
                throw new global::System.ArgumentNullException("reader");
            }

            if (string.CompareOrdinal(reader.LocalName, DslModeling::SerializationUtilities.ExtensionsXmlElementName) == 0)
            {
                DslModeling::SerializationUtilities.ReadExtensions(serializationContext, reader, element.Partition);
            }
        }
 /// <summary>
 /// This method is called during serialization to convert a given typed value (Html) to a specific value (string).
 /// </summary>
 /// <param name="serializationContext">The current serialization context instance.</param>
 /// <param name="modelELement">ModdelElement, to which the property belongs to.</param>
 /// <param name="propertyName">The Property name, which value is to be converted.</param>
 /// <param name="value">Typed value to convert.</param>
 /// <param name="sourceType">Type of the value.</param>
 /// <param name="isRequired">True if this property is marked as required in the domain model. Can be null.</param>
 /// <returns>Converted value.</returns>
 public static object ConvertTypedObjectHtmlTo(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement modelELement, string propertyName, object value, System.Type sourceType, bool?isRequired)
 {
     Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions.Html.Html strValue = value as Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions.Html.Html;
     if (strValue != null)
     {
         return(strValue.HtmlData);
     }
     else
     {
         if (isRequired != null)
         {
             // Important: This is needed, otherwise export will fail! (as long as we still use this extern export)
             if (isRequired.Value == true)
             {
                 return("");
             }
         }
         return(null);
     }
 }
Beispiel #16
0
        /// <summary>
        /// Write extension element data inside the current XML element
        /// </summary>
        /// <param name="serializationContext">The current serialization context instance.</param>
        /// <param name="element">The element whose attributes have just been written.</param>
        /// <param name="writer">XmlWriter to write serialized data to.</param>
        /// <remarks>The default implemenation is to write out all non-embedded extension elements,
        /// regardless of whether they relate to the current element or not.
        /// The additional data should be written as a series of one or more
        /// XML elements.</remarks>
        internal protected virtual void WriteExtensions(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer)
        {
            if (serializationContext == null)
            {
                throw new global::System.ArgumentNullException("serializationContext");
            }
            if (element == null)
            {
                throw new global::System.ArgumentNullException("element");
            }
            if (writer == null)
            {
                throw new global::System.ArgumentNullException("writer");
            }

            // Build a list of extension elements to serialize
            global::System.Collections.ObjectModel.ReadOnlyCollection <DslModeling::ModelElement> allExtensionElements          = element.Partition.ElementDirectory.FindElements(DslModeling::ExtensionElement.DomainClassId, true);
            global::System.Collections.Generic.IEnumerable <DslModeling::ExtensionElement>        nonEmbeddedExtensionsElements = allExtensionElements.Where(e => DslModeling::DomainClassInfo.FindEmbeddingElementLink(e) == null).OfType <DslModeling::ExtensionElement>();

            DslModeling::SerializationUtilities.WriteExtensions(serializationContext, writer, nonEmbeddedExtensionsElements);
        }
        protected virtual void WriteRootElement(DslModeling::SerializationContext serializationContext, DslModeling::DomainClassXmlSerializer domainClassXmlSerializer, DslModeling::ModelElement rootElement, global::System.Xml.XmlWriter writer)
        {
            #region Check Parameters
            global::System.Diagnostics.Debug.Assert(serializationContext != null);
            if (serializationContext == null)
            {
                throw new global::System.ArgumentNullException("serializationContext");
            }
            global::System.Diagnostics.Debug.Assert(domainClassXmlSerializer != null);
            if (domainClassXmlSerializer == null)
            {
                throw new global::System.ArgumentNullException("domainClassXmlSerializer");
            }
            global::System.Diagnostics.Debug.Assert(rootElement != null);
            if (rootElement == null)
            {
                throw new global::System.ArgumentNullException("rootElement");
            }
            global::System.Diagnostics.Debug.Assert(writer != null);
            if (writer == null)
            {
                throw new global::System.ArgumentNullException("writer");
            }
            #endregion

            // Set up root element settings
            DslModeling::RootElementSettings rootElementSettings = new DslModeling::RootElementSettings();
            if (!(rootElement is DslDiagrams::Diagram))
            {
                // Only model has schema, diagram has no schema.
                rootElementSettings.SchemaTargetNamespace = "http://schemas.microsoft.com/dsltools/Language4";
            }
            rootElementSettings.Version = new global::System.Version("1.0.0.0");

            // Carry out the normal serialization.
            domainClassXmlSerializer.Write(serializationContext, rootElement, writer, rootElementSettings);
        }
        protected virtual void ReadRootElement(DslModeling::SerializationContext serializationContext, DslModeling::DomainClassXmlSerializer domainClassXmlSerializer, DslModeling::ModelElement rootElement, global::System.Xml.XmlReader reader, DslModeling::ISchemaResolver schemaResolver)
        {
            #region Check Parameters
            global::System.Diagnostics.Debug.Assert(serializationContext != null);
            if (serializationContext == null)
            {
                throw new global::System.ArgumentNullException("serializationContext");
            }
            global::System.Diagnostics.Debug.Assert(domainClassXmlSerializer != null);
            if (domainClassXmlSerializer == null)
            {
                throw new global::System.ArgumentNullException("domainClassXmlSerializer");
            }
            global::System.Diagnostics.Debug.Assert(rootElement != null);
            if (rootElement == null)
            {
                throw new global::System.ArgumentNullException("rootElement");
            }
            global::System.Diagnostics.Debug.Assert(reader != null);
            if (reader == null)
            {
                throw new global::System.ArgumentNullException("reader");
            }
            #endregion

            // Version check.
            this.CheckVersion(serializationContext, reader);

            if (!serializationContext.Result.Failed)
            {
                // Use a validating reader if possible
                using (reader = TryCreateValidatingReader(schemaResolver, reader, serializationContext))
                {
                    domainClassXmlSerializer.Read(serializationContext, rootElement, reader);
                }
            }
        }
 private void CustomWrite(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer, DslModeling::RootElementSettings rootElementSettings)
 {
     DefaultWrite(serializationContext, element, writer, rootElementSettings);
 }
 private DslModeling::Moniker CustomCreateMonikerInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::ModelElement sourceRolePlayer, global::System.Guid relDomainClassId, DslModeling::Partition partition)
 {
     return(DefaultCreateMonikerInstance(serializationContext, reader, sourceRolePlayer, relDomainClassId, partition));
 }
Beispiel #21
0
        private void WriteChildElementsExtended(DslModeling::SerializationContext serializationContext, MetaModel element, global::System.Xml.XmlWriter writer)
        {
            // MetaModelHasDomainTypes
            global::System.Collections.ObjectModel.ReadOnlyCollection <MetaModelHasDomainTypes> allMetaModelHasDomainTypesInstances = MetaModelHasDomainTypes.GetLinksToDomainTypes(element);
            if (!serializationContext.Result.Failed && allMetaModelHasDomainTypesInstances.Count > 0)
            {
                writer.WriteStartElement("domainTypes");
                global::System.Type typeofMetaModelHasDomainTypes = typeof(MetaModelHasDomainTypes);
                foreach (MetaModelHasDomainTypes eachMetaModelHasDomainTypesInstance in allMetaModelHasDomainTypesInstances)
                {
                    if (serializationContext.Result.Failed)
                    {
                        break;
                    }

                    if (eachMetaModelHasDomainTypesInstance.GetType() != typeofMetaModelHasDomainTypes)
                    {                           // Derived relationships will be serialized in full-form.
                        DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachMetaModelHasDomainTypesInstance.GetDomainClass().Id);
                        global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachMetaModelHasDomainTypesInstance.GetDomainClass().Name + "!");
                        derivedRelSerializer.Write(serializationContext, eachMetaModelHasDomainTypesInstance, writer);
                    }
                    else
                    {                           // No need to serialize the relationship itself, just serialize the role-player directly.
                        DslModeling::ModelElement             targetElement    = eachMetaModelHasDomainTypesInstance.DomainType;
                        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();
            }

            // MetaModelHasValidation
            MetaModelHasValidation theMetaModelHasValidationInstance = MetaModelHasValidation.GetLinkToValidation(element);

            if (!serializationContext.Result.Failed && theMetaModelHasValidationInstance != null)
            {
                writer.WriteStartElement("validation");
                DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(theMetaModelHasValidationInstance.GetDomainClass().Id);
                global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + theMetaModelHasValidationInstance.GetDomainClass().Name + "!");
                relSerializer.Write(serializationContext, theMetaModelHasValidationInstance, writer);
                writer.WriteEndElement();
            }

            // MetaModelHasAdditionalInformation
            MetaModelHasAdditionalInformation theMetaModelHasAdditionalInformationInstance = MetaModelHasAdditionalInformation.GetLinkToAdditionalInformation(element);

            if (!serializationContext.Result.Failed && theMetaModelHasAdditionalInformationInstance != null)
            {
                writer.WriteStartElement("additionalInformation");
                DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(theMetaModelHasAdditionalInformationInstance.GetDomainClass().Id);
                global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + theMetaModelHasAdditionalInformationInstance.GetDomainClass().Name + "!");
                relSerializer.Write(serializationContext, theMetaModelHasAdditionalInformationInstance, writer);
                writer.WriteEndElement();
            }

            // MetaModelHasMetaModelLibraries
            global::System.Collections.ObjectModel.ReadOnlyCollection <MetaModelHasMetaModelLibraries> allMetaModelHasMetaModelLibrariesInstances = MetaModelHasMetaModelLibraries.GetLinksToMetaModelLibraries(element);
            if (!serializationContext.Result.Failed && allMetaModelHasMetaModelLibrariesInstances.Count > 0)
            {
                writer.WriteStartElement("metaModelLibraries");
                foreach (MetaModelHasMetaModelLibraries eachMetaModelHasMetaModelLibrariesInstance in allMetaModelHasMetaModelLibrariesInstances)
                {
                    if (serializationContext.Result.Failed)
                    {
                        break;
                    }

                    DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachMetaModelHasMetaModelLibrariesInstance.GetDomainClass().Id);
                    global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachMetaModelHasMetaModelLibrariesInstance.GetDomainClass().Name + "!");
                    relSerializer.Write(serializationContext, eachMetaModelHasMetaModelLibrariesInstance, writer);
                }
                writer.WriteEndElement();
            }

            /*
             *          // MetaModelHasView
             *          MetaModelHasView theMetaModelHasViewInstance = MetaModelHasView.GetLinkToView(element);
             *          if (!serializationContext.Result.Failed && theMetaModelHasViewInstance != null)
             *          {
             *                  DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(theMetaModelHasViewInstance.GetDomainClass().Id);
             *                  global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + theMetaModelHasViewInstance.GetDomainClass().Name + "!");
             *                  relSerializer.Write(serializationContext, theMetaModelHasViewInstance, writer);
             *          }*/

            // MetaModelHasModelContexts
            global::System.Collections.ObjectModel.ReadOnlyCollection <MetaModelHasModelContexts> allMetaModelHasModelContextsInstances = MetaModelHasModelContexts.GetLinksToModelContexts(element);
            if (!serializationContext.Result.Failed && allMetaModelHasModelContextsInstances.Count > 0)
            {
                writer.WriteStartElement("modelContexts");
                foreach (MetaModelHasModelContexts eachMetaModelHasModelContextsInstance in allMetaModelHasModelContextsInstances)
                {
                    if (serializationContext.Result.Failed)
                    {
                        break;
                    }

                    DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachMetaModelHasModelContextsInstance.GetDomainClass().Id);
                    global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachMetaModelHasModelContextsInstance.GetDomainClass().Name + "!");
                    relSerializer.Write(serializationContext, eachMetaModelHasModelContextsInstance, writer);
                }
                writer.WriteEndElement();
            }

            // MetaModelHasPropertyGridEditors
            global::System.Collections.ObjectModel.ReadOnlyCollection <MetaModelHasPropertyGridEditors> allMetaModelHasPropertyGridEditorsInstances = MetaModelHasPropertyGridEditors.GetLinksToPropertyGridEditors(element);
            if (!serializationContext.Result.Failed && allMetaModelHasPropertyGridEditorsInstances.Count > 0)
            {
                writer.WriteStartElement("propertyGridEditors");
                global::System.Type typeofMetaModelHasPropertyGridEditors = typeof(MetaModelHasPropertyGridEditors);
                foreach (MetaModelHasPropertyGridEditors eachMetaModelHasPropertyGridEditorsInstance in allMetaModelHasPropertyGridEditorsInstances)
                {
                    if (serializationContext.Result.Failed)
                    {
                        break;
                    }

                    if (eachMetaModelHasPropertyGridEditorsInstance.GetType() != typeofMetaModelHasPropertyGridEditors)
                    {                           // Derived relationships will be serialized in full-form.
                        DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachMetaModelHasPropertyGridEditorsInstance.GetDomainClass().Id);
                        global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachMetaModelHasPropertyGridEditorsInstance.GetDomainClass().Name + "!");
                        derivedRelSerializer.Write(serializationContext, eachMetaModelHasPropertyGridEditorsInstance, writer);
                    }
                    else
                    {                           // No need to serialize the relationship itself, just serialize the role-player directly.
                        DslModeling::ModelElement             targetElement    = eachMetaModelHasPropertyGridEditorsInstance.PropertyGridEditor;
                        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();
            }
        }
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, Model modelRoot, string modelFileName, ActiveRecordMapping 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 = new global::System.IO.MemoryStream())
				{
					DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!");
					if (diagramSerializer != null)
					{
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, diagramFileName, 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(diagramFileContent, encoding))
						{
							using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(streamWriter, settings))
							{
								diagramSerializer.WriteRootElement(serializationContext, diagram, writer);
							}
						}
					}
					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());
								}
							}
						}
					}
				}
			}
		}
		/// <summary>
		/// Saves the given model root as a in-memory stream.
		/// This is a helper used by SaveModel() and SaveModelAndDiagram(). When saving the model and the diagram together, we want to make sure that 
		/// both can be saved without error before writing the content to disk, so we serialize the model into a in-memory stream first.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">EntityDesignerViewModel instance to be saved.</param>
		/// <param name="fileName">Name of the file in which the EntityDesignerViewModel instance will be saved.</param>
		/// <param name="encoding">Encoding to use when saving the EntityDesignerViewModel instance.</param>
		/// <param name="writeOptionalPropertiesWithDefaultValue">Whether optional properties with default value will be saved.</param>
		/// <returns>In-memory stream containing the serialized EntityDesignerViewModel instance.</returns>
		internal virtual global::System.IO.MemoryStream InternalSaveModel(DslModeling::SerializationResult serializationResult, global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityDesignerViewModel 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 = MicrosoftDataEntityDesignSerializationHelper.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;
		}
			/// <summary>
			/// Constructor
			/// </summary>
			/// <param name="serializationContext">SerializationContext to be used to store schema validation warning/error.</param>
			internal BinbinDomainLanguageSerializationBehaviorSchemaValidationCallback(DslModeling::SerializationContext serializationContext)
			{
				global::System.Diagnostics.Debug.Assert(serializationContext != null);
				this.serializationContext = serializationContext;
			}
 private void CustomWriteMoniker(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer, DslModeling::ModelElement sourceRolePlayer, DslModeling::DomainRelationshipXmlSerializer relSerializer)
 {
     DefaultWriteMoniker(serializationContext, element, writer, sourceRolePlayer, relSerializer);
 }
 /// <summary>
 /// This method is called during deserialization to convert a given id as string to the id of type Guid as used by the domain model.
 /// </summary>
 /// <param name="serializationContext">The current serialization context instance.</param>
 /// <param name="id">Id as string.</param>
 /// <returns>Converted value, Id as Guid.</returns>
 public override Guid ConvertIdFrom(DslModeling::SerializationContext serializationContext, string id)
 {
     return(VMXExt::SerializationHelper.ConvertIdFrom(serializationContext, id));
 }
 private void CustomWriteElements(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer)
 {
     DefaultWriteElements(serializationContext, element, writer);
 }
 /// <summary>
 /// This method is called during serialization to convert a given id to its specific string representation.
 /// </summary>
 /// <param name="serializationContext">The current serialization context instance.</param>
 /// <param name="id">Id.</param>
 /// <returns>Converted value.</returns>
 public override string ConvertIdTo(DslModeling::SerializationContext serializationContext, Guid id)
 {
     return(VMXExt::SerializationHelper.ConvertIdTo(serializationContext, id));
 }
        // private void OnPostLoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, ModelRoot modelRoot, EFModelDiagram diagram)
        // private DslDiagrams::Diagram LoadDiagram(DslModeling::SerializationResult serializationResult, DslModeling::ModelElement modelRoot, DslModeling::Partition diagramPartition, global::System.IO.Stream diagramStream, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
        private DslDiagrams::Diagram LoadDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, string diagramFileName, DslModeling::ModelElement modelRoot, DslModeling::Partition diagramPartition, global::System.IO.Stream diagramStream, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
        {
            #region Check Parameters
            if (serializationResult == null)
            {
                throw new global::System.ArgumentNullException("serializationResult");
            }
            if (modelRoot == null)
            {
                throw new global::System.ArgumentNullException("modelRoot");
            }
            if (diagramPartition == null)
            {
                throw new global::System.ArgumentNullException("diagramPartition");
            }
            #endregion

            DslDiagrams::Diagram diagram = null;
            var diagramName = string.Empty;

            // Ensure there is an outer transaction spanning both model and diagram load, so moniker resolution works properly.
            if (!diagramPartition.Store.TransactionActive)
            {
                throw new global::System.InvalidOperationException(EFModelDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
            }

            if (diagramStream == null || diagramStream == global::System.IO.Stream.Null || !diagramStream.CanRead || diagramStream.Length < 6)
            {
                // missing diagram file indicates we should create a new diagram.
                diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
            }
            else
            {
                var directory     = this.GetDirectory(diagramPartition.Store);
                var localName     = string.Empty;
                var localSettings = EFModelSerializationHelper.Instance.CreateXmlReaderSettings(null, false);
                try
                {
                    using (var reader = global::System.Xml.XmlReader.Create(diagramStream, localSettings))
                    {
                        reader.MoveToContent();
                        localName = reader.LocalName;
                        global::System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(reader.GetAttribute("name")), "One of diagram streams is not well-formed");
                        diagramName = reader.GetAttribute("name");
                    }
                    diagramStream.Seek(0, global::System.IO.SeekOrigin.Begin);
                }
                catch (global::System.Xml.XmlException xEx)
                {
                    DslModeling::SerializationUtilities.AddMessage(
                        new DslModeling::SerializationContext(directory),
                        DslModeling::SerializationMessageKind.Error,
                        xEx
                        );
                }

                var diagramSerializer = directory.GetSerializer(EFModelDiagram.DomainClassId) ?? this.GetSerializer(diagramPartition.Store, localName);
                global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagramName);

                if (diagramSerializer != null)
                {
                    DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, diagramName, serializationResult);
                    this.InitializeSerializationContext(diagramPartition, serializationContext, true);
                    DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext();
                    transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext);


                    using (DslModeling::Transaction postT = diagramPartition.Store.TransactionManager.BeginTransaction("PostLoad Model and Diagram", true, transactionContext))
                    {
                        using (DslModeling::Transaction t = diagramPartition.Store.TransactionManager.BeginTransaction("LoadDiagram", 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 (diagramStream.Length > 5)
                            {
                                global::System.Xml.XmlReaderSettings settings = EFModelSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
                                try
                                {
                                    using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(diagramStream, settings))
                                    {
                                        reader.MoveToContent();
                                        diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as DslDiagrams::Diagram;
                                        if (diagram != null)
                                        {
                                            this.ReadRootElement(serializationContext, diagramSerializer, diagram, reader, schemaResolver);
                                        }
                                    }
                                }
                                catch (global::System.Xml.XmlException xEx)
                                {
                                    DslModeling::SerializationUtilities.AddMessage(
                                        serializationContext,
                                        DslModeling::SerializationMessageKind.Error,
                                        xEx
                                        );
                                }
                                if (serializationResult.Failed)
                                {
                                    // Serialization error encountered, rollback the transaction.
                                    diagram = null;
                                    t.Rollback();
                                }
                            }

                            if (diagram == null && !serializationResult.Failed)
                            {
                                // Create diagram if it doesn't exist
                                diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
                            }

                            if (t.IsActive)
                            {
                                t.Commit();
                            }
                        }     // End inner Tx


                        // Fire PostLoad customization code whether Load succeeded or not
                        // Provide a method in a partial class with the following signature:

                        ///// <summary>
                        ///// Customize Model and Diagram Loading.
                        ///// </summary>
                        ///// <param name="serializationResult">Stores serialization result from the load operation.</param>
                        ///// <param name="modelPartition">Partition in which the new DslLibrary instance will be created.</param>
                        ///// <param name="modelFileName">Name of the file from which the DslLibrary instance will be deserialized.</param>
                        ///// <param name="diagramPartition">Partition in which the new DslDesignerDiagram instance will be created.</param>
                        ///// <param name="diagramFileName">Name of the file from which the DslDesignerDiagram instance will be deserialized.</param>
                        ///// <param name="modelRoot">The root of the file that was loaded.</param>
                        ///// <param name="diagram">The diagram matching the modelRoot.</param>
                        // private void OnPostLoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, ModelRoot modelRoot, EFModelDiagram diagram)

                        this.OnPostLoadModelAndDiagram(serializationResult, modelPartition, modelFileName, diagramPartition, diagramFileName, (ModelRoot)modelRoot, (EFModelDiagram)diagram);
                        if (serializationResult.Failed)
                        {       // Serialization error encountered, rollback the middle transaction.
                            modelRoot = null;
                            postT.Rollback();
                        }
                        if (postT.IsActive)
                        {
                            postT.Commit();
                        }
                    }    // End MiddleTx
                    // Do load-time validation if a ValidationController is provided.
                    if (!serializationResult.Failed && validationController != null)
                    {
                        using (new SerializationValidationObserver(serializationResult, validationController))
                        {
                            validationController.Validate(diagramPartition, DslValidation::ValidationCategories.Load);
                        }
                    }
                }
            }

            if (diagram != null)
            {
                if (!serializationResult.Failed)
                {       // Succeeded.
                    diagram.ModelElement = diagram.ModelElement ?? modelRoot;
                    diagram.PostDeserialization(true);
                    this.CheckForOrphanedShapes(diagram, serializationResult);
                }
                else
                {       // Failed.
                    diagram.PostDeserialization(false);
                }
            }

            return(diagram);
        }
		/// <summary>
		/// Loads a ExampleModel instance.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the load operation.</param>
		/// <param name="partition">Partition in which the new ExampleModel instance will be created.</param>
		/// <param name="fileName">Name of the file from which the ExampleModel instance will be deserialized.</param>
		/// <param name="schemaResolver">
		/// An ISchemaResolver that allows the serializer to do schema validation on the root element (and everything inside it).
		/// If null is passed, schema validation will not be performed.
		/// </param>
		/// <param name="validationController">
		/// A ValidationController that will be used to do load-time validation (validations with validation category "Load"). If null
		/// is passed, load-time validation will not be performed.
		/// </param>
		/// <returns>The loaded ExampleModel instance.</returns>
		public virtual ExampleModel LoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (partition == null)
				throw new global::System.ArgumentNullException("partition");
			if (string.IsNullOrEmpty(fileName))
				throw new global::System.ArgumentNullException("fileName");
			#endregion
		
			// Ensure there is a transaction for this model to Load in.
			if (!partition.Store.TransactionActive)
			{
				throw new global::System.InvalidOperationException(AsyncDslDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
			}
			
			ExampleModel modelRoot = null;
			DslModeling::DomainClassXmlSerializer modelRootSerializer = this.Directory.GetSerializer(ExampleModel.DomainClassId);
			global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for ExampleModel!");
			if (modelRootSerializer != null)
			{
				using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(fileName))
				{
					using (DslModeling::Transaction t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, true))
					{
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, fileStream.Name, serializationResult);
						// Set up MonikerResolver for AsyncDsl.
						this.SetupMonikerResolver(serializationContext, partition.Store);
						// Ensure there is some content in the file.  Blank (or almost blank, to account for encoding header bytes, etc.)
						// files will cause a new root element to be created and returned. 
						if (fileStream.Length > 5)
						{
							global::System.Xml.XmlReaderSettings settings = new global::System.Xml.XmlReaderSettings();
							try
							{
								using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
								{
									reader.MoveToContent();
									modelRoot = modelRootSerializer.TryCreateInstance(serializationContext, reader, partition) as ExampleModel;
									if (modelRoot != null && !serializationResult.Failed)
									{
										// Note: the actual instance we get back from TryCreateInstance() can be of a derived type of ExampleModel,
										// so we need to find the correct serializer instance to deserialize the element properly.
										DslModeling::DomainClassXmlSerializer instanceSerializer = this.Directory.GetSerializer(modelRoot.GetDomainClass().Id);
										global::System.Diagnostics.Debug.Assert(instanceSerializer != null, "Cannot find serializer for " + modelRoot.GetDomainClass().Name + "!");
										instanceSerializer.ReadRootElement(serializationContext, modelRoot, reader, schemaResolver);
									}
								}
	
							}
							catch (global::System.Xml.XmlException xEx)
							{
								DslModeling::SerializationUtilities.AddMessage(
									serializationContext,
									DslModeling::SerializationMessageKind.Error,
									xEx
								);
							}
						}
				
						if(modelRoot == null && !serializationResult.Failed)
						{
							// create model root if it doesn't exist.
							modelRoot = this.CreateModelHelper(partition);
						}
						if (t.IsActive)
							t.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(partition, DslValidation::ValidationCategories.Load);
						}
					}
				}
			}
			return modelRoot;
		}
		public virtual ExampleModel LoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (modelPartition == null)		
				throw new global::System.ArgumentNullException("modelPartition");
			if (diagramPartition == null)
				throw new global::System.ArgumentNullException("diagramPartition");
			if (string.IsNullOrEmpty(diagramFileName))
				throw new global::System.ArgumentNullException("diagramFileName");
			#endregion
	
			ExampleModel modelRoot;
	
			// Ensure there is an outer transaction spanning both model and diagram load, so moniker resolution works properly.
			if (!diagramPartition.Store.TransactionActive)
			{
				throw new global::System.InvalidOperationException(AsyncDslDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
			}
	
			modelRoot = this.LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController);
	
			if (serializationResult.Failed)
			{
				// don't try to deserialize diagram data if model load failed.
				return modelRoot;
			}
	
			AsyncDslDiagram diagram = null;
			DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(AsyncDslDiagram.DomainClassId);
			global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for AsyncDslDiagram");
			if (diagramSerializer != null)
			{
				if(!global::System.IO.File.Exists(diagramFileName))
				{
					// missing diagram file indicates we should create a new diagram.
					diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
				}
				else
				{
					using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(diagramFileName))
					{
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, fileStream.Name, serializationResult);
						// Set up MonikerResolver for AsyncDsl.
						this.SetupMonikerResolver(serializationContext, diagramPartition.Store);
						
						using (DslModeling::Transaction t = diagramPartition.Store.TransactionManager.BeginTransaction("LoadDiagram", true))
						{
							// 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)
							{
								global::System.Xml.XmlReaderSettings settings = new global::System.Xml.XmlReaderSettings();
								try
								{
									using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
									{
										reader.MoveToContent();
										diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as AsyncDslDiagram;
										if (diagram != null)
										{
											// Note: the actual instance we get back from TryCreateInstance() can be of a derived type of AsyncDslDiagram,
											// so we need to find the correct serializer instance to deserialize the element properly.
											DslModeling::DomainClassXmlSerializer instanceSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id);
											global::System.Diagnostics.Debug.Assert(instanceSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!");
											instanceSerializer.ReadRootElement(serializationContext, diagram, reader, schemaResolver);
										}
									}
								}
								catch (global::System.Xml.XmlException xEx)
								{
									DslModeling::SerializationUtilities.AddMessage(
										serializationContext,
										DslModeling::SerializationMessageKind.Error,
										xEx
									);
								}
								if (serializationResult.Failed)
								{	
									// Serialization error encountered, rollback the transaction.
									diagram = null;
									t.Rollback();
								}
							}
							
							if(diagram == null && !serializationResult.Failed)
							{
								// Create diagram if it doesn't exist
								diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
							}
							
							if (t.IsActive)
								t.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, DslValidation::ValidationCategories.Load);
							}
						}
					}
				}
	
				if (diagram != null)
				{
					if (!serializationResult.Failed)
					{	// Succeeded.
						diagram.ModelElement = modelRoot;
						diagram.PostDeserialization(true);
						this.CheckForOrphanedShapes(diagram, serializationResult);
					}
					else
					{	// Failed.
						diagram.PostDeserialization(false);
					}
				}
			}
			return modelRoot;
		}
		public virtual HostDesignerModel LoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (partition == null)
				throw new global::System.ArgumentNullException("partition");
			if (string.IsNullOrEmpty(fileName))
				throw new global::System.ArgumentNullException("fileName");
			#endregion
		
			// Ensure there is a transaction for this model to Load in.
			if (!partition.Store.TransactionActive)
			{
				throw new global::System.InvalidOperationException(HostDesignerDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
			}
			
			HostDesignerModel modelRoot = null;
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(partition.Store);
			DslModeling::DomainClassXmlSerializer modelRootSerializer = directory.GetSerializer(HostDesignerModel.DomainClassId);
			global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for HostDesignerModel!");
			if (modelRootSerializer != null)
			{
				using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(fileName))
				{
		
					using (DslModeling::Transaction postT = partition.Store.TransactionManager.BeginTransaction("PostLoad Model", true))
					{		
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileStream.Name, serializationResult);
						this.InitializeSerializationContext(partition, serializationContext, true);
						DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext();
						transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext);
						using (DslModeling::Transaction t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, 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 root element to be created and returned. 
							if (fileStream.Length > 5)
							{
								try
								{
									global::System.Xml.XmlReaderSettings settings = HostDesignerSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
									using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
									{
										// Attempt to read the encoding.
										reader.Read(); // Move to the first node - will be the XmlDeclaration if there is one.
										global::System.Text.Encoding encoding;
										if (this.TryGetEncoding(reader, out encoding))
										{
											serializationResult.Encoding = encoding;
										}
		
										// Load any additional domain models that are required
										DslModeling::SerializationUtilities.ResolveDomainModels(reader, serializerLocator, partition.Store);
									
										reader.MoveToContent();
		
										
										modelRoot = modelRootSerializer.TryCreateInstance(serializationContext, reader, partition) as HostDesignerModel;
										if (modelRoot != null && !serializationResult.Failed)
										{
											this.ReadRootElement(serializationContext, modelRoot, reader, schemaResolver);
										}
									}
		
								}
								catch (global::System.Xml.XmlException xEx)
								{
									DslModeling::SerializationUtilities.AddMessage(
										serializationContext,
										DslModeling::SerializationMessageKind.Error,
										xEx
									);
								}
							}
					
							if(modelRoot == null && !serializationResult.Failed)
							{
								// create model root if it doesn't exist.
								modelRoot = this.CreateModelHelper(partition);
							}
							if (t.IsActive)
								t.Commit();
						} // End Inner Tx
		
						// Fire PostLoad customization code whether load has succeeded or not
						// Provide a method in a partial class with the following signature:
						
						///// <summary>
						///// Customize Model Loading.
						///// </summary>
						///// <param name="serializationResult">Stores serialization result from the load operation.</param>
						///// <param name="partition">Partition in which the new HostDesignerModel instance will be created.</param>
						///// <param name="fileName">Name of the file from which the HostDesignerModel instance will be deserialized.</param>
						///// <param name="modelRoot">The root of the file that was loaded.</param>
						// private void OnPostLoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, HostDesignerModel modelRoot )
	
						this.OnPostLoadModel(serializationResult, partition, fileName, modelRoot);
						if (serializationResult.Failed)
						{	// Serialization error encountered, rollback the middle transaction.
							modelRoot = null;
							postT.Rollback();
						}
						if (postT.IsActive)
							postT.Commit();
					} // End PostLoad Tx
	
					// Do load-time validation if a ValidationController is provided.
					if (!serializationResult.Failed && validationController != null)
					{
						using (new SerializationValidationObserver(serializationResult, validationController))
						{
							validationController.Validate(partition, DslValidation::ValidationCategories.Load);
						}
					}
	
				}
			}
			return modelRoot;
		}
 /// <summary>
 /// This method is called during deserialization to convert a given value to a specific typed value (Html).
 /// </summary>
 /// <param name="serializationContext">The current serialization context instance.</param>
 /// <param name="modelELement">ModdelElement, to which the property belongs to.</param>
 /// <param name="propertyName">The Property name, which value is to be converted.</param>
 /// <param name="value">Value to convert.</param>
 /// <param name="targetType">Type, the object is to be converted to.</param>
 /// <param name="isRequired">True if this property is marked as required in the domain model. Can be null.</param>
 /// <returns>Converted value.</returns>
 public override VMXExt::Html.Html ConvertTypedObjectHtmlFrom(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement modelELement, string propertyName, object value, System.Type targetType, bool?isRequired)
 {
     return(VMXExt::SerializationHelper.ConvertTypedObjectHtmlFrom(serializationContext, modelELement, propertyName, value, targetType, isRequired));
 }
        public MetaModel LoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator, bool bStartT, bool bIsTopMost)
        {
            #region Model
            #region Check Parameters
            if (serializationResult == null)
                throw new global::System.ArgumentNullException("serializationResult");
            if (partition == null)
                throw new global::System.ArgumentNullException("partition");
            if (string.IsNullOrEmpty(fileName))
                throw new global::System.ArgumentNullException("fileName");
            #endregion

            // Ensure there is a transaction for this model to Load in.
            if (!partition.Store.TransactionActive)
            {
                throw new global::System.InvalidOperationException(LanguageDSLDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
            }

            MetaModel modelRoot = null;
            DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(partition.Store);
            DslModeling::DomainClassXmlSerializer modelRootSerializer = directory.GetSerializer(MetaModel.DomainClassId);
            global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for MetaModel!");
            if (modelRootSerializer != null)
            {
                using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(fileName))
                {
                    DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileStream.Name, serializationResult);
                    this.InitializeSerializationContext(partition, serializationContext, true);
                    DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext();
                    transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext);

                    DslModeling::Transaction t = null;
                    if (bStartT)
                    {
                        t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, 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 root element to be created and returned. 
                    if (fileStream.Length > 5)
                    {
                        try
                        {
                            global::System.Xml.XmlReaderSettings settings = LanguageDSLSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
                            using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
                            {
                                // Attempt to read the encoding.
                                reader.Read(); // Move to the first node - will be the XmlDeclaration if there is one.
                                global::System.Text.Encoding encoding;
                                if (this.TryGetEncoding(reader, out encoding))
                                {
                                    serializationResult.Encoding = encoding;
                                }

                                // Load any additional domain models that are required
                                DslModeling::SerializationUtilities.ResolveDomainModels(reader, serializerLocator, partition.Store);

                                reader.MoveToContent();


                                modelRoot = modelRootSerializer.TryCreateInstance(serializationContext, reader, partition) as MetaModel;
                                if (modelRoot != null && !serializationResult.Failed)
                                {
                                    modelRoot.BaseDirectory = MetaModelLibraryBase.GetBaseDirectory(fileName);
                                    modelRoot.FilePath = fileName;
                                    this.ReadRootElement(serializationContext, modelRoot, reader, schemaResolver);
                                }
                            }

                        }
                        catch (global::System.Xml.XmlException xEx)
                        {
                            DslModeling::SerializationUtilities.AddMessage(
                                serializationContext,
                                DslModeling::SerializationMessageKind.Error,
                                xEx
                            );
                        }
                    }

                    if (modelRoot == null && !serializationResult.Failed)
                    {
                        // create model root if it doesn't exist.
                        modelRoot = this.CreateModelHelper(partition);
                        modelRoot.BaseDirectory = MetaModelLibraryBase.GetBaseDirectory(fileName);
                        modelRoot.FilePath = fileName;
                    }
                    if (bStartT)
                        if (t.IsActive)
                            t.Commit();

                    // Do load-time validation if a ValidationController is provided.
                    if (!serializationResult.Failed && validationController != null)
                    {
                        using (new SerializationValidationObserver(serializationResult, validationController))
                        {
                            validationController.Validate(partition, DslValidation::ValidationCategories.Load);
                        }
                    }
                }
            }

            #endregion

            MetaModel model = modelRoot;
            if (bIsTopMost)
                model.IsTopMost = true;

            #region Diagrams

            System.IO.FileInfo info = new System.IO.FileInfo(fileName);
            string fileNameDiagram = info.DirectoryName + "\\" + info.Name.Remove(info.Name.Length - info.Extension.Length, info.Extension.Length) + DiagramExtension;

            View view = null;
            if (System.IO.File.Exists(fileNameDiagram))
            {
                //DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(partition.Store);
                DslModeling::DomainClassXmlSerializer viewSerializer = directory.GetSerializer(View.DomainClassId);
                global::System.Diagnostics.Debug.Assert(viewSerializer != null, "Cannot find serializer for View!");
                if (viewSerializer != null)
                {
                    using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(fileNameDiagram))
                    {
                        DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileStream.Name, serializationResult);
                        this.InitializeSerializationContext(partition, serializationContext, true);
                        DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext();
                        transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext);

                        DslModeling::Transaction t = null;
                        if (bStartT)
                            t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileNameDiagram, 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 root element to be created and returned. 
                        if (fileStream.Length > 5)
                        {
                            try
                            {
                                global::System.Xml.XmlReaderSettings settings = LanguageDSLSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
                                using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
                                {
                                    // Attempt to read the encoding.
                                    reader.Read(); // Move to the first node - will be the XmlDeclaration if there is one.
                                    global::System.Text.Encoding encoding;
                                    if (this.TryGetEncoding(reader, out encoding))
                                    {
                                        serializationResult.Encoding = encoding;
                                    }
                                    reader.MoveToContent();

                                    view = viewSerializer.TryCreateInstance(serializationContext, reader, partition) as View;
                                    if (view != null && !serializationResult.Failed)
                                    {
                                        // Use a validating reader if possible
                                        viewSerializer.Read(serializationContext, view, reader);

                                        model.View = view;
                                    }
                                }
                            }

                            catch (global::System.Xml.XmlException xEx)
                            {
                                DslModeling::SerializationUtilities.AddMessage(
                                    serializationContext,
                                    DslModeling::SerializationMessageKind.Error,
                                    xEx
                                );
                            }
                        }

                        if (bStartT)
                            if (t.IsActive)
                                t.Commit();

                    }
                }
            }
            #endregion

            //if( bIsTopMost )
            SerializationPostProcessor.PostProcessModelLoad(model);

            return model;
        }
		private global::System.IO.MemoryStream InternalSaveDiagram(DslModeling::SerializationResult serializationResult, AsyncDslDiagram 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
			
			global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
			
			DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id);
			global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!");
			if (diagramSerializer != null)
			{
				DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, diagramFileName, 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))
					{
						diagramSerializer.WriteRootElement(serializationContext, diagram, writer);
					}
				}
			}
			return newFileContent;
		}
 /// <summary>
 /// This method is called during serialization to convert a given typed value (Html) to a specific value (string).
 /// </summary>
 /// <param name="serializationContext">The current serialization context instance.</param>
 /// <param name="modelELement">ModdelElement, to which the property belongs to.</param>
 /// <param name="propertyName">The Property name, which value is to be converted.</param>
 /// <param name="value">Typed value to convert.</param>
 /// <param name="sourceType">Type of the value.</param>
 /// <param name="isRequired">True if this property is marked as required in the domain model. Can be null.</param>
 /// <returns>Converted value.</returns>
 public override object ConvertTypedObjectHtmlTo(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement modelELement, string propertyName, object value, System.Type sourceType, bool?isRequired)
 {
     return(VMXExt::SerializationHelper.ConvertTypedObjectHtmlTo(serializationContext, modelELement, propertyName, value, sourceType, isRequired));
 }
			/// <summary>
			/// Constructor
			/// </summary>
			/// <param name="serializationContext">SerializationContext to be used to store schema validation warning/error.</param>
			internal HostDesignerSerializationBehaviorSchemaValidationCallback(DslModeling::SerializationContext serializationContext)
			{
				global::System.Diagnostics.Debug.Assert(serializationContext != null);
				this.serializationContext = serializationContext;
			}
        public virtual global::Tum.VModellXT.VModell LoadModelVModell(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
        {
            #region Check Parameters
            if (serializationResult == null)
                throw new global::System.ArgumentNullException("serializationResult");
            if (partition == null)
                throw new global::System.ArgumentNullException("partition");
            if (string.IsNullOrEmpty(fileName))
                throw new global::System.ArgumentNullException("fileName");
            #endregion

            DslEditorModeling::DomainModelStore dStore = (DslEditorModeling::DomainModelStore)partition.Store;
            if( dStore == null)
                throw new global::System.ArgumentNullException("dStore");
			//dStore.WaitForWritingLockRelease();

            // Ensure there is a transaction for this model to Load in.
            if (!partition.Store.TransactionActive)
            {
                throw new global::System.InvalidOperationException(VModellXTDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
            }
			
			global::Tum.VModellXT.VModell modelRoot = null;
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(partition.Store);
			DslModeling::DomainClassXmlSerializer modelRootSerializer = directory.GetSerializer(global::Tum.VModellXT.VModell.DomainClassId);
			global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for VModell!");
			if (modelRootSerializer != null)
			{
				global::System.IO.FileStream fileStream = null;
			
				try
				{
					fileStream = global::System.IO.File.OpenRead(fileName);
					
					DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileStream.Name, serializationResult);
					this.InitializeSerializationContext(partition, serializationContext, true);
					DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext();
					transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext);
					
					//using (DslModeling::Transaction t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, 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 root element to be created and returned. 
						if (fileStream.Length > 5)
						{
							global::System.Xml.XmlReaderSettings settings = VModellXTSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
							using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
							{
								try
								{	
									// Attempt to read the encoding.
									reader.Read(); // Move to the first node - will be the XmlDeclaration if there is one.
									global::System.Text.Encoding encoding;
									if (this.TryGetEncoding(reader, out encoding))
									{
										serializationResult.Encoding = encoding;
									}
	
									// Load any additional domain models that are required
									//DslModeling::SerializationUtilities.ResolveDomainModels(reader, serializerLocator, partition.Store);
								
									reader.MoveToContent();
									
									modelRoot = modelRootSerializer.TryCreateInstance(serializationContext, reader, partition) as global::Tum.VModellXT.VModell;
									if (modelRoot != null && !serializationResult.Failed)
									{
										modelRoot.DomainFilePath = fileName;
										this.ReadRootElementVModell(serializationContext, modelRoot, reader, schemaResolver);
									}
									
                                    fileStream.Dispose();
								}
								catch (global::System.Xml.XmlException xEx)
								{
									DslModeling::SerializationUtilities.AddMessage(
										serializationContext,
										DslModeling::SerializationMessageKind.Error,
										xEx
									);
								}
								finally
								{
									fileStream = null;
								}	
							}							
						}
				
						if(modelRoot == null && !serializationResult.Failed)
						{
							// create model root if it doesn't exist.
							modelRoot = this.CreateModelHelperVModell(partition);
							modelRoot.DomainFilePath = fileName;
						}
						//if (t.IsActive)
						//	t.Commit();
					//}
	
					// Do load-time validation if a ValidationController is provided.
					if (!serializationResult.Failed && validationController != null)
					{
						using (new SerializationValidationObserver(serializationResult, validationController))
						{
							validationController.Validate(partition, DslValidation::ValidationCategories.Load);
						}
					}
				}
				finally
				{
					if( fileStream != null )
						fileStream.Dispose();
				}
			}
			return modelRoot;
        }
		public virtual HostDesignerModel LoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (modelPartition == null)		
				throw new global::System.ArgumentNullException("modelPartition");
			if (diagramPartition == null)
				throw new global::System.ArgumentNullException("diagramPartition");
			if (string.IsNullOrEmpty(diagramFileName))
				throw new global::System.ArgumentNullException("diagramFileName");
			#endregion
	
			HostDesignerModel modelRoot;
	
			// Ensure there is an outer transaction spanning both model and diagram load, so moniker resolution works properly.
			if (!diagramPartition.Store.TransactionActive)
			{
				throw new global::System.InvalidOperationException(HostDesignerDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
			}
	
			modelRoot = this.LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController, serializerLocator);
	
			if (serializationResult.Failed)
			{
				// don't try to deserialize diagram data if model load failed.
				return modelRoot;
			}
	
			HostDesignerDiagram diagram = null;
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(diagramPartition.Store);
			DslModeling::DomainClassXmlSerializer diagramSerializer = directory.GetSerializer(HostDesignerDiagram.DomainClassId);
			global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for HostDesignerDiagram");
			if (diagramSerializer != null)
			{
				if(!global::System.IO.File.Exists(diagramFileName))
				{
					// missing diagram file indicates we should create a new diagram.
					diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
				}
				else
				{
					using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(diagramFileName))
					{
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileStream.Name, serializationResult);
						this.InitializeSerializationContext(diagramPartition, serializationContext, true);
						DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext();
						transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext);
		
						using (DslModeling::Transaction postT = diagramPartition.Store.TransactionManager.BeginTransaction("PostLoad Model and Diagram", true, transactionContext))
						{
							
							using (DslModeling::Transaction t = diagramPartition.Store.TransactionManager.BeginTransaction("LoadDiagram", 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)
								{
									global::System.Xml.XmlReaderSettings settings = HostDesignerSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
									try
									{
										using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
										{
											reader.MoveToContent();
											diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as HostDesignerDiagram;
											if (diagram != null)
											{
												this.ReadRootElement(serializationContext, diagram, reader, schemaResolver);
											}
										}
									}
									catch (global::System.Xml.XmlException xEx)
									{
										DslModeling::SerializationUtilities.AddMessage(
											serializationContext,
											DslModeling::SerializationMessageKind.Error,
											xEx
										);
									}
									if (serializationResult.Failed)
									{	
										// Serialization error encountered, rollback the transaction.
										diagram = null;
										t.Rollback();
									}
								}
								
								if(diagram == null && !serializationResult.Failed)
								{
									// Create diagram if it doesn't exist
									diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
								}
								
								if (t.IsActive)
									t.Commit();
							} // End inner Tx
	
							// Fire PostLoad customization code whether Load succeeded or not
							// Provide a method in a partial class with the following signature:
							
							///// <summary>
							///// Customize Model and Diagram Loading.
							///// </summary>
							///// <param name="serializationResult">Stores serialization result from the load operation.</param>
							///// <param name="modelPartition">Partition in which the new DslLibrary instance will be created.</param>
							///// <param name="modelFileName">Name of the file from which the DslLibrary instance will be deserialized.</param>
							///// <param name="diagramPartition">Partition in which the new DslDesignerDiagram instance will be created.</param>
							///// <param name="diagramFileName">Name of the file from which the DslDesignerDiagram instance will be deserialized.</param>
							///// <param name="modelRoot">The root of the file that was loaded.</param>
							///// <param name="diagram">The diagram matching the modelRoot.</param>
							// private void OnPostLoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, HostDesignerModel modelRoot, HostDesignerDiagram diagram)
	
							this.OnPostLoadModelAndDiagram(serializationResult, modelPartition, modelFileName, diagramPartition, diagramFileName, modelRoot, diagram);
							if (serializationResult.Failed)
							{	// Serialization error encountered, rollback the middle transaction.
									modelRoot = null;
									postT.Rollback();
							}
							if (postT.IsActive)
								postT.Commit();
						} // End MiddleTx					
	
						// Do load-time validation if a ValidationController is provided.
						if (!serializationResult.Failed && validationController != null)
						{
							using (new SerializationValidationObserver(serializationResult, validationController))
							{
								validationController.Validate(diagramPartition, DslValidation::ValidationCategories.Load);
							}
						}
					}
				}
	
				if (diagram != null)
				{
					if (!serializationResult.Failed)
					{	// Succeeded.
						diagram.ModelElement = modelRoot;
						diagram.PostDeserialization(true);
						this.CheckForOrphanedShapes(diagram, serializationResult);
					}
					else
					{	// Failed.
						diagram.PostDeserialization(false);
					}
				}
			}
			return modelRoot;
		}
        public virtual void TemporarlySaveModelVModell(DslModeling::SerializationResult serializationResult, global::Tum.VModellXT.VModell modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
        {
            #region Check Parameters
            if (serializationResult == null)
                throw new global::System.ArgumentNullException("serializationResult");
            if (modelRoot == null)
                throw new global::System.ArgumentNullException("modelRoot");
            if (string.IsNullOrEmpty(fileName))
                throw new global::System.ArgumentNullException("fileName");
            #endregion

            if (serializationResult.Failed)
                return;

            //DslEditorModeling::DomainModelStore dStore = (DslEditorModeling::DomainModelStore)modelRoot.Store;
            //if( dStore == null)
            //    throw new global::System.ArgumentNullException("dStore");
				
			//dStore.WaitForWritingLockRelease();

			global::System.IO.MemoryStream newFileContent = null;
            try 
            {
				newFileContent = new global::System.IO.MemoryStream();
				
                DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store);

                DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileName, serializationResult);
                this.InitializeSerializationContext(modelRoot.Partition, serializationContext, false);
                serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
                global::System.Xml.XmlWriterSettings settings = VModellXTSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
                
				global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings);
               	DslEditorModeling::SerializationOptions options = new DslEditorModeling.SerializationOptions();
              	options.SerializationMode = DslEditorModeling.SerializationMode.Temporarly;
              	this.WriteRootElementVModell(serializationContext, modelRoot, writer, options);
				
				writer.Flush();

                if (!serializationResult.Failed && newFileContent != null)
                {	// Only write the content if there's no error encountered during serialization.
					global::System.IO.FileStream fileStream = null;
                    try
                    {
						fileStream = new global::System.IO.FileStream(fileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None);
                        using (global::System.IO.BinaryWriter writerBin = new global::System.IO.BinaryWriter(fileStream, encoding))
                        {
							try
							{
                            	writerBin.Write(newFileContent.ToArray());
								fileStream.Dispose();
							}
							finally
							{
								fileStream = null;
							}							
                        }
                    }
					finally
					{
						if( fileStream != null )
							fileStream.Dispose();
					}
                }
            }
			finally
			{
				if( newFileContent != null )
					newFileContent.Dispose();
			}
        }
 private void CustomReadPropertiesFromAttributes(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader)
 {
     DefaultReadPropertiesFromAttributes(serializationContext, element, reader);
 }
		internal virtual void SaveModel(DslModeling::SerializationResult serializationResult, ProductState modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (modelRoot == null)
				throw new global::System.ArgumentNullException("modelRoot");
			if (string.IsNullOrEmpty(fileName))
				throw new global::System.ArgumentNullException("fileName");
			#endregion
	
			if (serializationResult.Failed)
				return;
	
			using (global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream())
			{
				DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store);
	
				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 = ProductStateStoreSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
				using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
				{
					this.WriteRootElement(serializationContext, modelRoot, writer);
				}
	
				if (!serializationResult.Failed && newFileContent != null)
				{	// Only write the content if there's no error encountered during serialization.
					using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(fileName, 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(newFileContent.ToArray());
						}
					}
				}
			}
		}
		private global::System.IO.MemoryStream InternalSaveModelVModell(DslModeling::SerializationResult serializationResult, global::Tum.VModellXT.VModell modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue, DslEditorModeling.SerializationMode serializationMode)
		{
			#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
		
            //DslEditorModeling::DomainModelStore dStore = (DslEditorModeling::DomainModelStore)modelRoot.Store;
            //if( dStore == null)
            //    throw new global::System.ArgumentNullException("dStore");
				
			//dStore.WaitForWritingLockRelease();
			
			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 = VModellXTSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
			using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
			{
				DslEditorModeling.SerializationOptions options = new DslEditorModeling.SerializationOptions();
                //options.SerializationMode = DslEditorModeling.SerializationMode.InternalToString;
				options.SerializationMode = serializationMode;
                this.WriteRootElementVModell(serializationContext, modelRoot, writer, options);
			}
				
			return newFileContent;
		}
 private void CustomReadElements(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader)
 {
     DefaultReadElements(serializationContext, element, reader);
 }
 private DslModeling::ModelElement CustomCreateInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::Partition partition)
 {
     return(DefaultCreateInstance(serializationContext, reader, partition));
 }
Beispiel #46
0
			/// <summary>
			/// Constructor
			/// </summary>
			/// <param name="serializationContext">SerializationContext to be used to store schema validation warning/error.</param>
			internal CloudCoreArchitectProcessOverviewSerializationBehaviorSchemaValidationCallback(DslModeling::SerializationContext serializationContext)
			{
				global::System.Diagnostics.Debug.Assert(serializationContext != null);
				this.serializationContext = serializationContext;
			}