public void Initialize() { var serviceProvider = Mocks.Of<IServiceProvider>().First(provider => provider.GetService(typeof(IPatternManager)) == Mocks.Of<IPatternManager>().First(manager => manager.InstalledToolkits == new IInstalledToolkitInfo[] { Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.ValidExtensionToolkitId && toolkitInfo.Schema.Pattern.Id == Ids.ValidExtensionProductId && toolkitInfo.Schema.Pattern.ExtensionId == Ids.ValidExtensionToolkitId && toolkitInfo.Schema.Pattern.ProvidedExtensionPoints == new[] { Mocks.Of<IProvidedExtensionPointInfo>().First(extensionPoint => extensionPoint.ExtensionPointId == "ValidExtensionPointId") }), Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.InvalidExtensionToolkitId && toolkitInfo.Schema.Pattern.Id == Ids.InvalidExtensionProductId && toolkitInfo.Schema.Pattern.ExtensionId == Ids.InvalidExtensionToolkitId && toolkitInfo.Schema.Pattern.ProvidedExtensionPoints == new[] { Mocks.Of<IProvidedExtensionPointInfo>().First(extensionPoint => extensionPoint.ExtensionPointId == "InvalidExtensionPointId") }), Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.MainToolkitId && toolkitInfo.Schema.Pattern.Id == Ids.MainProductId && toolkitInfo.Schema.Pattern.Name == "Pattern" && toolkitInfo.Schema.Pattern.ExtensionId == Ids.MainToolkitId && toolkitInfo.Schema.Pattern.Views == new [] { // View // MainElement // MainCollection // MainExtensionPoint Mocks.Of<IViewInfo>().First(view => view.Id == Ids.MainViewId && view.Name == "View" && view.Elements == new IAbstractElementInfo[] { Mocks.Of<IElementInfo>().First(element => element.Id == Ids.MainElementId && element.Name == "Element" && element.Cardinality == Cardinality.ZeroToMany && element.Elements == new IAbstractElementInfo[] { Mocks.Of<ICollectionInfo>().First(collection => collection.Id == Ids.MainCollectionId && collection.Name == "Collection" && collection.Cardinality == Cardinality.ZeroToMany ), } && element.ExtensionPoints == new IExtensionPointInfo[] { Mocks.Of<IExtensionPointInfo>().First(extensionPoint => extensionPoint.Id == Ids.MainExtensionPointId && extensionPoint.Name == "ExtensionPoint" && extensionPoint.Cardinality == Cardinality.ZeroToMany && extensionPoint.RequiredExtensionPointId == "ValidExtensionPointId" ), }), }), }), }) ); using (var store = new Dsl.Store(serviceProvider, typeof(Dsl.CoreDomainModel), typeof(ProductStateStoreDomainModel))) using (var tx = store.TransactionManager.BeginTransaction()) { var productStore = store.ElementFactory.CreateElement<ProductState>(); productStore .CreateProduct(p => { p.ExtensionId = Ids.MainToolkitId; p.DefinitionId = Ids.MainProductId; }) .CreateView(v => v.DefinitionId = Ids.MainViewId) .CreateElement(e => e.DefinitionId = Ids.MainElementId); ProductStateStoreSerializationHelper.Instance.SaveModel(new Dsl.SerializationResult(), productStore, this.storeFilePath); tx.Commit(); } this.store = new Dsl.Store(serviceProvider, typeof(Dsl.CoreDomainModel), typeof(ProductStateStoreDomainModel)); using (var tx = this.store.TransactionManager.BeginTransaction("Loading", true)) { ProductStateStoreSerializationHelper.Instance.LoadModel(this.store, this.storeFilePath, null, null, null); tx.Commit(); this.productStore = this.store.ElementDirectory.AllElements.OfType<ProductState>().First(); } this.element = this.store.ElementDirectory.FindElements<Element>(true).First(); this.view = this.store.ElementDirectory.FindElements<View>(true).First(); }
public virtual void Initialize() { this.DslStore = new DslTestStore<ProductStateStoreDomainModel>(); using (var tx = this.DslStore.TransactionManager.BeginTransaction()) { this.ProductStore = this.DslStore.ElementFactory.CreateElement<ProductState>(); tx.Commit(); } }
/// <summary> /// Reads all instances of relationship ProductStateHasProducts. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be /// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the /// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens). /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="element">In-memory ProductState instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> private static void ReadProductStateHasProductsInstances(DslModeling::SerializationContext serializationContext, ProductState element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { DslModeling::DomainClassXmlSerializer newProductOfProductStateHasProductsSerializer = serializationContext.Directory.GetSerializer(Product.DomainClassId); global::System.Diagnostics.Debug.Assert(newProductOfProductStateHasProductsSerializer != null, "Cannot find serializer for Product!"); Product newProductOfProductStateHasProducts = newProductOfProductStateHasProductsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as Product; if (newProductOfProductStateHasProducts != null) { element.Products.Add(newProductOfProductStateHasProducts); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newProductOfProductStateHasProducts.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newProductOfProductStateHasProducts.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newProductOfProductStateHasProducts, reader); } else { global::System.Type typeofProductStateHasProducts = typeof(ProductStateHasProducts); DslModeling::DomainRelationshipXmlSerializer newProductStateHasProductsSerializer = serializationContext.Directory.GetSerializer(ProductStateHasProducts.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(newProductStateHasProductsSerializer != null, "Cannot find serializer for ProductStateHasProducts!"); ProductStateHasProducts newProductStateHasProducts = newProductStateHasProductsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as ProductStateHasProducts; if (newProductStateHasProducts != null) { if (newProductStateHasProducts.GetType() == typeofProductStateHasProducts) { // The relationship should be serialized in short-form. ProductStateStoreSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(ProductStateHasProducts)); } DslModeling::DomainRoleInfo.SetRolePlayer (newProductStateHasProducts, ProductStateHasProducts.ProductStateDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newProductStateHasProducts.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newProductStateHasProducts.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newProductStateHasProducts, reader); } else { // Unknown element, skip DslModeling::SerializationUtilities.Skip(reader); } } } }
private static void WriteChildElements(DslModeling::SerializationContext serializationContext, ProductState element, global::System.Xml.XmlWriter writer) { // ProductStateHasProducts global::System.Collections.ObjectModel.ReadOnlyCollection<ProductStateHasProducts> allProductStateHasProductsInstances = ProductStateHasProducts.GetLinksToProducts(element); if (!serializationContext.Result.Failed && allProductStateHasProductsInstances.Count > 0) { writer.WriteStartElement("products"); global::System.Type typeofProductStateHasProducts = typeof(ProductStateHasProducts); foreach (ProductStateHasProducts eachProductStateHasProductsInstance in allProductStateHasProductsInstances) { if (serializationContext.Result.Failed) break; if (eachProductStateHasProductsInstance.GetType() != typeofProductStateHasProducts) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachProductStateHasProductsInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachProductStateHasProductsInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachProductStateHasProductsInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachProductStateHasProductsInstance.Product; 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(); } }
/// <summary> /// Constructor /// Creates a ProductStateHasProducts link in the same Partition as the given ProductState /// </summary> /// <param name="source">ProductState to use as the source of the relationship.</param> /// <param name="target">Product to use as the target of the relationship.</param> internal ProductStateHasProducts(ProductState source, Product target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ProductStateHasProducts.ProductStateDomainRoleId, source), new DslModeling::RoleAssignment(ProductStateHasProducts.ProductDomainRoleId, target)}, null) { }
/// <summary> /// This method deserializes all child model elements. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first child XML element to deserialized. /// This method will read as many child elements as it can. It returns under three circumstances: /// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the /// open tag of the unknown element. This implies that if the first child XML element is unknown, this method /// should return immediately and do nothing. /// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element. /// 3) EOF. /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="reader">XmlReader to read serialized data from.</param> /// <param name="element">In-memory ProductState instance that will get the deserialized data.</param> private static void ReadChildElements(DslModeling::SerializationContext serializationContext, ProductState element, global::System.Xml.XmlReader reader) { if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { if (string.Compare(reader.LocalName, "products", global::System.StringComparison.CurrentCulture) == 0) { if (reader.IsEmptyElement) { // No instance of this relationship, just skip DslModeling::SerializationUtilities.Skip(reader); } else { DslModeling::SerializationUtilities.SkipToFirstChild(reader); // Skip the open tag of <products> ReadProductStateHasProductsInstances(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </products> } } } }
internal static void SetProductState(Product element, ProductState newProductState) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ProductDomainRoleId, newProductState); }
internal static DslModeling::LinkedElementCollection<Product> GetProducts(ProductState element) { return GetRoleCollection<DslModeling::LinkedElementCollection<Product>, Product>(element, ProductStateDomainRoleId); }
public void Initialize() { var serviceProvider = Mocks.Of<IServiceProvider>().First(provider => provider.GetService(typeof(IPatternManager)) == Mocks.Of<IPatternManager>().First(manager => manager.InstalledToolkits == new IInstalledToolkitInfo[] { Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.ExtensionToolkit1Id && toolkitInfo.Schema.Pattern.Id == Ids.ExtensionProduct1Id && toolkitInfo.Schema.Pattern.Name == "Product1" && toolkitInfo.Schema.Pattern.ExtensionId == Ids.ExtensionToolkit1Id && toolkitInfo.Schema.Pattern.OrderGroup == 7 && toolkitInfo.Schema.Pattern.ProvidedExtensionPoints == new[] { Mocks.Of<IProvidedExtensionPointInfo>().First(extensionPoint => extensionPoint.ExtensionPointId == "ExtensionPoint1Id") }), Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.ExtensionToolkit2Id && toolkitInfo.Schema.Pattern.Id == Ids.ExtensionProduct2Id && toolkitInfo.Schema.Pattern.Name == "Product2" && toolkitInfo.Schema.Pattern.ExtensionId == Ids.ExtensionToolkit2Id && toolkitInfo.Schema.Pattern.OrderGroup == 8 && toolkitInfo.Schema.Pattern.ProvidedExtensionPoints == new[] { Mocks.Of<IProvidedExtensionPointInfo>().First(extensionPoint => extensionPoint.ExtensionPointId == "ExtensionPoint2Id") }), Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.MainToolkitId && toolkitInfo.Schema.Pattern.Id == Ids.MainProductId && toolkitInfo.Schema.Pattern.Name == "MainProduct" && toolkitInfo.Schema.Pattern.ExtensionId == Ids.MainToolkitId && toolkitInfo.Schema.Pattern.Views == new [] { //MainProduct // View // MainElement // Collection1 // Property1 // Collection2 // Element1 // Element2 // Element3 // ExtensionPoint1 // ExtensionPoint2 Mocks.Of<IViewInfo>().First(view => view.Id == Ids.MainViewId && view.Name == "View" && view.Elements == new IAbstractElementInfo[] { Mocks.Of<IElementInfo>().First(element => element.Id == Ids.MainElementId && element.Name == "MainElement" && element.Cardinality == Cardinality.ZeroToMany && element.Elements == new IAbstractElementInfo[] { Mocks.Of<ICollectionInfo>().First(ce => ce.Id == Ids.Collection1Id && ce.Name == "Collection1" && ce.OrderGroup == 1 && ce.Cardinality == Cardinality.ZeroToMany && ce.Properties == new [] {Mocks.Of<IPropertyInfo>().First(p => p.Name == "Property1" && p.Id == Ids.Property1Id && p.Type == typeof(string).FullName)} ), Mocks.Of<ICollectionInfo>().First(ce => ce.Id == Ids.Collection2Id && ce.Name == "Collection2" && ce.OrderGroup == 1 && ce.Cardinality == Cardinality.ZeroToMany ), Mocks.Of<IElementInfo>().First(ce => ce.Id == Ids.Element1Id && ce.Name == "Element1" && ce.OrderGroup == 2 && ce.Cardinality == Cardinality.ZeroToMany ), Mocks.Of<IElementInfo>().First(ce => ce.Id == Ids.Element2Id && ce.Name == "Element2" && ce.OrderGroup == 3 && ce.Cardinality == Cardinality.ZeroToMany ), } && element.ExtensionPoints == new IExtensionPointInfo[] { Mocks.Of<IExtensionPointInfo>().First(extensionPoint => extensionPoint.Id == Ids.ExtensionPoint1Id && extensionPoint.Name == "ExtensionPoint1" && extensionPoint.OrderGroup == 4 && extensionPoint.Cardinality == Cardinality.ZeroToMany && extensionPoint.RequiredExtensionPointId == "ExtensionPoint1Id" ), Mocks.Of<IExtensionPointInfo>().First(extensionPoint => extensionPoint.Id == Ids.ExtensionPoint2Id && extensionPoint.Name == "ExtensionPoint2" && extensionPoint.OrderGroup == 5 && extensionPoint.Cardinality == Cardinality.ZeroToMany && extensionPoint.RequiredExtensionPointId == "ExtensionPoint2Id" ), }), }), }), }) ); using (var store = new Microsoft.VisualStudio.Modeling.Store(serviceProvider, typeof(Microsoft.VisualStudio.Modeling.CoreDomainModel), typeof(ProductStateStoreDomainModel))) using (var tx = store.TransactionManager.BeginTransaction()) { var productStore = store.ElementFactory.CreateElement<ProductState>(); productStore .CreateProduct(p => { p.ExtensionId = Ids.MainToolkitId; p.DefinitionId = Ids.MainProductId; }) .CreateView(v => v.DefinitionId = Ids.MainViewId) .CreateElement(e => e.DefinitionId = Ids.MainElementId); ProductStateStoreSerializationHelper.Instance.SaveModel(new Microsoft.VisualStudio.Modeling.SerializationResult(), productStore, this.storeFilePath); tx.Commit(); } this.store = new Microsoft.VisualStudio.Modeling.Store(serviceProvider, typeof(Microsoft.VisualStudio.Modeling.CoreDomainModel), typeof(ProductStateStoreDomainModel)); using (var tx = this.store.TransactionManager.BeginTransaction("Loading", true)) { ProductStateStoreSerializationHelper.Instance.LoadModel(this.store, this.storeFilePath, null, null, null); tx.Commit(); this.productStore = this.store.ElementDirectory.AllElements.OfType<ProductState>().First(); } this.mainElement = this.store.ElementDirectory.FindElements<Element>(true).First(); this.view = this.store.ElementDirectory.FindElements<View>(true).First(); }
public void InitializeContext() { var serviceProvider = Mocks.Of<IServiceProvider>().First(provider => provider.GetService(typeof(IPatternManager)) == Mocks.Of<IPatternManager>().First(manager => manager.InstalledToolkits == new IInstalledToolkitInfo[] { Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.PatternToolkit1Id && toolkitInfo.Schema.Pattern.Id == Ids.ExtensionToolkitPatternSchema1Id && toolkitInfo.Schema.Pattern.ExtensionId == Ids.PatternToolkit1Id && toolkitInfo.Schema.Pattern.ProvidedExtensionPoints == new[] { Mocks.Of<IProvidedExtensionPointInfo>().First(extensionPoint => extensionPoint.ExtensionPointId == Ids.ExtensionPointSchemaPath1), Mocks.Of<IProvidedExtensionPointInfo>().First(extensionPoint => extensionPoint.ExtensionPointId == Ids.ExtensionPointSchemaPath2) }), Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.PatternToolkit2Id && toolkitInfo.Schema.Pattern.Id == Ids.ExtensionToolkitPatternSchema2Id && toolkitInfo.Schema.Pattern.ExtensionId == Ids.PatternToolkit2Id && toolkitInfo.Schema.Pattern.ProvidedExtensionPoints == new[] { Mocks.Of<IProvidedExtensionPointInfo>().First(extensionPoint => extensionPoint.ExtensionPointId == Ids.ExtensionPointSchemaPath2) }), Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.SecondToolkitId && toolkitInfo.Schema.Pattern.Id == Ids.SecondPatternSchemaId && toolkitInfo.Schema.Pattern.Name == "SecondPatternSchema" && toolkitInfo.Schema.Pattern.ExtensionId == Ids.MainToolkitId), Mocks.Of<IInstalledToolkitInfo>().First(toolkitInfo => toolkitInfo.Id == Ids.MainToolkitId && toolkitInfo.Schema.Pattern.Id == Ids.MainPatternSchemaId && toolkitInfo.Schema.Pattern.Name == "MainPatternSchema" && toolkitInfo.Schema.Pattern.ExtensionId == Ids.MainToolkitId && toolkitInfo.Schema.Pattern.Views == new [] { // View // ExtensionPoint1 // ExtensionPoint2 Mocks.Of<IViewInfo>().First(view => view.Id == Ids.MainViewSchemaId && view.Name == "View" && view.ExtensionPoints == new IExtensionPointInfo[] { Mocks.Of<IExtensionPointInfo>().First(extensionPoint => extensionPoint.Id == Ids.ExtensionPointSchema1Id && extensionPoint.Name == "ExtensionPointSchema1" && extensionPoint.OrderGroup == 2 && extensionPoint.Cardinality == Cardinality.ZeroToMany && extensionPoint.RequiredExtensionPointId == Ids.ExtensionPointSchemaPath1 ), Mocks.Of<IExtensionPointInfo>().First(extensionPoint => extensionPoint.Id == Ids.ExtensionPointSchema2Id && extensionPoint.Name == "ExtensionPointSchema2" && extensionPoint.OrderGroup == 3 && extensionPoint.Cardinality == Cardinality.ZeroToOne && extensionPoint.RequiredExtensionPointId == Ids.ExtensionPointSchemaPath2 ), }), }), }) ); using (var store = new Microsoft.VisualStudio.Modeling.Store(serviceProvider, typeof(Microsoft.VisualStudio.Modeling.CoreDomainModel), typeof(ProductStateStoreDomainModel))) using (var tx = store.TransactionManager.BeginTransaction()) { var productStore = store.ElementFactory.CreateElement<ProductState>(); productStore .CreateProduct(p => { p.ExtensionId = Ids.SecondToolkitId; p.DefinitionId = Ids.SecondPatternSchemaId; }); productStore .CreateProduct(p => { p.ExtensionId = Ids.SecondToolkitId; p.DefinitionId = Ids.SecondPatternSchemaId; }); productStore .CreateProduct(p => { p.ExtensionId = Ids.MainToolkitId; p.DefinitionId = Ids.MainPatternSchemaId; }) .CreateView(v => v.DefinitionId = Ids.MainViewSchemaId); ProductStateStoreSerializationHelper.Instance.SaveModel(new Microsoft.VisualStudio.Modeling.SerializationResult(), productStore, this.storeFilePath); tx.Commit(); } this.store = new Microsoft.VisualStudio.Modeling.Store(serviceProvider, typeof(Microsoft.VisualStudio.Modeling.CoreDomainModel), typeof(ProductStateStoreDomainModel)); using (var tx = this.store.TransactionManager.BeginTransaction("Loading", true)) { ProductStateStoreSerializationHelper.Instance.LoadModel(this.store, this.storeFilePath, null, null, null); tx.Commit(); this.productStore = this.store.ElementDirectory.AllElements.OfType<ProductState>().First(); } this.rootProduct3 = this.store.ElementDirectory.FindElements<Product>(true).Where(p => p.DefinitionId == Ids.SecondPatternSchemaId).ToArray()[0]; this.rootProduct2 = this.store.ElementDirectory.FindElements<Product>(true).Where(p => p.DefinitionId == Ids.SecondPatternSchemaId).ToArray()[1]; this.rootProduct1 = this.store.ElementDirectory.FindElements<Product>(true).First(p => p.DefinitionId == Ids.MainPatternSchemaId); this.view = rootProduct1.Views.First(); this.extensionPointInfo2 = this.view.Info.ExtensionPoints.First(ep => ep.Id == Ids.ExtensionPointSchema2Id); this.extensionProduct1 = this.view.CreateExtension(prod => { prod.ProductState = this.productStore; prod.ExtensionId = Ids.PatternToolkit1Id; prod.DefinitionId = Ids.ExtensionToolkitPatternSchema1Id; }); this.extensionProduct2 = this.view.CreateExtension(prod => { prod.ProductState = this.productStore; prod.ExtensionId = Ids.PatternToolkit1Id; prod.DefinitionId = Ids.ExtensionToolkitPatternSchema1Id; }); this.extensionProduct4 = this.view.CreateExtension(prod => { prod.ProductState = this.productStore; prod.ExtensionId = Ids.PatternToolkit2Id; prod.DefinitionId = Ids.ExtensionToolkitPatternSchema2Id; }); }
/// <summary> /// Helper method to create and initialize a new ProductState. /// </summary> internal virtual ProductState CreateModelHelper(DslModeling::Partition modelPartition) { ProductState model = new ProductState(modelPartition); return model; }
internal global::System.IO.MemoryStream InternalSaveModel(DslModeling::SerializationResult serializationResult, ProductState 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 = ProductStateStoreSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding); using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings)) { this.WriteRootElement(serializationContext, modelRoot, writer); } return newFileContent; }
internal 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()); } } } } }
/// <summary> /// Saves the given model to the given file, with default encoding (UTF-8). /// </summary> /// <param name="serializationResult">Stores serialization result from the save operation.</param> /// <param name="modelRoot">ProductState instance to be saved.</param> /// <param name="fileName">Name of the file in which the ProductState instance will be saved.</param> /// <param name="writeOptionalPropertiesWithDefaultValue">Whether optional properties with default value will be saved.</param> internal virtual void SaveModel(DslModeling::SerializationResult serializationResult, ProductState modelRoot, string fileName, bool writeOptionalPropertiesWithDefaultValue) { this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue); }
/// <summary> /// Saves the given model root to the given file, with default encoding (UTF-8), and optional properties with default value will not /// be written out. /// </summary> /// <param name="serializationResult">Stores serialization result from the save operation.</param> /// <param name="modelRoot">ProductState instance to be saved.</param> /// <param name="fileName">Name of the file in which the ProductState instance will be saved.</param> internal virtual void SaveModel(DslModeling::SerializationResult serializationResult, ProductState modelRoot, string fileName) { this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, false); }