Esempio n. 1
0
        private static IPropertyInfo FindInfo(ProductElement owner, Guid id)
        {
            if (owner != null && owner.Info != null)
            {
                return owner.Info.Properties.FirstOrDefault(p => p.Id == id);
            }

            return null;
        }
Esempio n. 2
0
        private static IPropertyInfo FindInfo(ProductElement owner, Guid id)
        {
            if (owner != null && owner.Info != null)
            {
                return(owner.Info.Properties.FirstOrDefault(p => p.Id == id));
            }

            return(null);
        }
            public void Initialize()
            {
                this.store = new DslTestStore<ProductStateStoreDomainModel>();

                this.extension = new Mock<IAutomationExtension>();
                this.extension.As<IDisposable>();

                using (var tx = this.store.TransactionManager.BeginTransaction())
                {
                    this.element = this.store.ElementFactory.CreateElement<Product>();
                    tx.Commit();
                }

                this.element.AutomationExtensions.Add(this.extension.Object);
            }
            public void Initialize()
            {
                this.store = new DslTestStore<ProductStateStoreDomainModel>();

                using (var tx = store.TransactionManager.BeginTransaction())
                {
                    this.property = store.ElementFactory.CreateElement<Property>();
                    this.property.Info = Mocks.Of<IPropertyInfo>().First(i => i.Name == PropertyName && i.IsVisible == true && i.IsReadOnly == false);

                    this.element = store.ElementFactory.CreateElement<Element>();
                    this.element.Properties.Add(this.property);
                    tx.Commit();
                }

                this.descriptor = new ProductElementTypeDescriptor(
                    TypeDescriptor.GetProvider(this.element).GetTypeDescriptor(this.element), this.element);
            }
Esempio n. 5
0
        /// <summary>
        /// Sync the properties of the given property container.
        /// </summary>
        internal static void SyncPropertiesFrom(this ProductElement container, IEnumerable <IPropertyInfo> properties)
        {
            // Delete existing properties that don't have a corresponding definition.
            container.Properties
            .Where(p => !properties.Any(info => info.Id == p.DefinitionId))
            .ToArray()
            .ForEach(p => p.Delete());

            // Initialize all the new properties. Existing ones are not modified.
            foreach (var info in properties.Where(info => !container.Properties.Any(p => p.DefinitionId == info.Id)))
            {
                // Assigning the DefinitionId on create automatically loads the Info property.
                var property = container.CreateProperty(p => { p.DefinitionId = info.Id; });
                // Reset evaluates VP and default value.
                property.Reset();
            }
        }
            public void Initialize()
            {
                this.store = new DslTestStore<ProductStateStoreDomainModel>();
                Mock.Get(this.store.ServiceProvider)
                    .Setup(x => x.GetService(typeof(SComponentModel)))
                    .Returns(new Mock<IComponentModel>
                    {
                        DefaultValue = DefaultValue.Mock
                    }
                    .Object);
                Mock.Get(this.store.ServiceProvider)
                    .Setup(x => x.GetService(typeof(IBindingCompositionService)))
                    .Returns(new Mock<IBindingCompositionService>
                    {
                        DefaultValue = DefaultValue.Mock
                    }
                    .Object);

                this.automationExtension = new Mock<IAutomationExtension>();
                this.automationExtension.As<IDisposable>();
                this.automationExtension.As<ISupportInitialize>();
                this.extensionSettings = new Mock<IAutomationSettings>();
                this.extensionSettings
                    .Setup(x => x.CreateAutomation(It.IsAny<IProductElement>()))
                    .Returns(this.automationExtension.Object);

                var settingsContainer = new Mock<IPatternElementInfo>();
                var settingsInfo = new Mock<IAutomationSettingsInfo>();

                settingsContainer
                    .Setup(x => x.AutomationSettings)
                    .Returns(new[] { settingsInfo.Object });

                settingsInfo
                    .Setup(info => info.As<IAutomationSettings>())
                    .Returns(this.extensionSettings.Object);

                using (var tx = this.store.TransactionManager.BeginTransaction())
                {
                    this.element = this.store.ElementFactory.CreateElement<Product>();
                    this.element.Info = settingsContainer.Object;
                    tx.Commit();
                }
            }
            public void Initialize()
            {
                this.store = new DslTestStore<ProductStateStoreDomainModel>();

                using (var tx = this.store.TransactionManager.BeginTransaction())
                {
                    this.element = this.store.ElementFactory.CreateElement<Product>();
                    tx.Commit();
                }
            }
Esempio n. 8
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, ProductElement element, global::System.Xml.XmlWriter writer)
		{
			// ProductElementHasProperties
			global::System.Collections.ObjectModel.ReadOnlyCollection<ProductElementHasProperties> allProductElementHasPropertiesInstances = ProductElementHasProperties.GetLinksToProperties(element);
			if (!serializationContext.Result.Failed && allProductElementHasPropertiesInstances.Count > 0)
			{
				writer.WriteStartElement("properties");
				global::System.Type typeofProductElementHasProperties = typeof(ProductElementHasProperties);
				foreach (ProductElementHasProperties eachProductElementHasPropertiesInstance in allProductElementHasPropertiesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachProductElementHasPropertiesInstance.GetType() != typeofProductElementHasProperties)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachProductElementHasPropertiesInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachProductElementHasPropertiesInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachProductElementHasPropertiesInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachProductElementHasPropertiesInstance.Property;
						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();
			}
	
			// ProductElementHasReferences
			global::System.Collections.ObjectModel.ReadOnlyCollection<ProductElementHasReferences> allProductElementHasReferencesInstances = ProductElementHasReferences.GetLinksToReferences(element);
			if (!serializationContext.Result.Failed && allProductElementHasReferencesInstances.Count > 0)
			{
				writer.WriteStartElement("references");
				global::System.Type typeofProductElementHasReferences = typeof(ProductElementHasReferences);
				foreach (ProductElementHasReferences eachProductElementHasReferencesInstance in allProductElementHasReferencesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachProductElementHasReferencesInstance.GetType() != typeofProductElementHasReferences)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachProductElementHasReferencesInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachProductElementHasReferencesInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachProductElementHasReferencesInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachProductElementHasReferencesInstance.Reference;
						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();
			}
	
		}
Esempio n. 9
0
		/// <summary>
		/// Reads all instances of relationship ProductElementHasReferences.
		/// </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 ProductElement instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadProductElementHasReferencesInstances(DslModeling::SerializationContext serializationContext, ProductElement element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newReferenceOfProductElementHasReferencesSerializer = serializationContext.Directory.GetSerializer(Reference.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newReferenceOfProductElementHasReferencesSerializer != null, "Cannot find serializer for Reference!");
				Reference newReferenceOfProductElementHasReferences = newReferenceOfProductElementHasReferencesSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as Reference;
				if (newReferenceOfProductElementHasReferences != null)
				{
					element.References.Add(newReferenceOfProductElementHasReferences);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newReferenceOfProductElementHasReferences.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newReferenceOfProductElementHasReferences.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newReferenceOfProductElementHasReferences, reader);
				}
				else
				{
					global::System.Type typeofProductElementHasReferences = typeof(ProductElementHasReferences);
					DslModeling::DomainRelationshipXmlSerializer newProductElementHasReferencesSerializer = serializationContext.Directory.GetSerializer(ProductElementHasReferences.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newProductElementHasReferencesSerializer != null, "Cannot find serializer for ProductElementHasReferences!");
					ProductElementHasReferences newProductElementHasReferences = newProductElementHasReferencesSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as ProductElementHasReferences;
					if (newProductElementHasReferences != null)
					{
						if (newProductElementHasReferences.GetType() == typeofProductElementHasReferences)
						{	// The relationship should be serialized in short-form.
							ProductStateStoreSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(ProductElementHasReferences));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newProductElementHasReferences, ProductElementHasReferences.ProductElementDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newProductElementHasReferences.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newProductElementHasReferences.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newProductElementHasReferences, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
Esempio n. 10
0
		/// <summary>
		/// This method deserializes all child model elements.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first child XML element to deserialized.
		/// This method will read as many child elements as it can. It returns under three circumstances:
		/// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the 
		///    open tag of the unknown element. This implies that if the first child XML element is unknown, this method 
		///    should return immediately and do nothing.
		/// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element.
		/// 3) EOF.
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		/// <param name="element">In-memory ProductElement instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, ProductElement element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "properties":	// Relationship "ProductElementHasProperties"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <properties>
							ReadProductElementHasPropertiesInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </properties>
						}
						break;
					case "references":	// Relationship "ProductElementHasReferences"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <references>
							ReadProductElementHasReferencesInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </references>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}
		/// <summary>
		/// Constructor
		/// Creates a ProductElementHasProperties link in the same Partition as the given ProductElement
		/// </summary>
		/// <param name="source">ProductElement to use as the source of the relationship.</param>
		/// <param name="target">Property to use as the target of the relationship.</param>
		internal ProductElementHasProperties(ProductElement source, Property target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ProductElementHasProperties.ProductElementDomainRoleId, source), new DslModeling::RoleAssignment(ProductElementHasProperties.PropertyDomainRoleId, target)}, null)
		{
		}
		internal static DslModeling::LinkedElementCollection<Reference> GetReferences(ProductElement element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<Reference>, Reference>(element, ProductElementDomainRoleId);
		}
		internal static void SetOwner(Reference element, ProductElement newProductElement)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ReferenceDomainRoleId, newProductElement);
		}
		internal static DslModeling::LinkedElementCollection<Property> GetProperties(ProductElement element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<Property>, Property>(element, ProductElementDomainRoleId);
		}
		internal static void SetOwner(Property element, ProductElement newProductElement)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, PropertyDomainRoleId, newProductElement);
		}
            public void Initialize()
            {
                this.store = new DslTestStore<ProductStateStoreDomainModel>();

                using (var tx = this.store.TransactionManager.BeginTransaction())
                {
                    this.element = this.store.ElementFactory.CreateElement<Product>();
                    tx.Commit();
                }

                this.bindingContext = new Mock<IDynamicBindingContext> { DefaultValue = DefaultValue.Mock };

                Mock.Get(this.store.ServiceProvider)
                    .Setup(x => x.GetService(typeof(IBindingFactory)))
                    .Returns(Mock.Of<IBindingFactory>(factory =>
                        factory.CreateContext() == this.bindingContext.Object));

                this.element.InstanceName = "Hello";
                this.element.Info = Mock.Of<IElementInfo>(info =>
                    info.Name == "My" &&
                    info.ValidationSettings == new IBindingSettings[] { Mock.Of<IBindingSettings>() });
            }