/// <summary>
        /// Clears the collection of provided extension points in the pattern.
        /// </summary>
        internal static void ClearProvidedExtensionPoints(this PatternSchema product)
        {
            Guard.NotNull(() => product, product);

            product.ClearAllProvidedContractProperties();
            product.ProvidedExtensionPoints.Clear();
        }
        /// <summary>
        /// Adds the provided extension point to the given pattern.
        /// </summary>
        internal static void AddProvidedExtensionPoint(this PatternSchema product, IExtensionPointSchema extensionPoint)
        {
            Guard.NotNull(() => product, product);

            product.ProvidedExtensionPoints.Add(
                product.Store.ElementFactory.CreateElement <ProvidedExtensionPointSchema>()
                .With(ext => ext.ExtensionPointId = extensionPoint.RequiredExtensionPointId));
        }
 public void InitializeContext()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
         this.product = patternModel.Create<PatternSchema>();
         var automationSettings = this.product.Create<AutomationSettingsSchema>();
         this.settings = automationSettings.AddExtension<TemplateSettings>();
     });
     validationContext = new ValidationContext(ValidationCategories.Save, this.settings);
 }
            public void InitializeContext()
            {
                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    var patternModel = store.ElementFactory.CreateElement<PatternModelSchema>();
                    this.product = patternModel.Create<PatternSchema>();
                    this.product.Name = "WebService";
                });

                this.guidanceExtension = ExtensionElement.GetExtension<GuidanceExtension>(this.product);
            }
            public void InitializeContext()
            {
                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
                    this.product = patternModel.Create<PatternSchema>();
                    var automationSettings = product.Create<AutomationSettingsSchema>();
                    this.settings = automationSettings.AddExtension<CommandSettings>();
                });

                validationContext = new ValidationContext(ValidationCategories.Save, this.settings);

                this.validators = new CommandSettingsValidations(Mock.Of<INuPatternCompositionService>());
            }
        /// <summary>
        /// Adds the contract properties from the given extension point to the pattern.
        /// </summary>
        internal static void CopyProvidedContractProperties(this PatternSchema product, IExtensionPointSchema extensionPoint)
        {
            Guard.NotNull(() => product, product);
            Guard.NotNull(() => extensionPoint, extensionPoint);

            foreach (var property in extensionPoint.Properties)
            {
                if (!product.Properties.Any(
                        p => p.Name.Equals(property.Name, StringComparison.OrdinalIgnoreCase) &&
                        p.Type.Equals(property.Type, StringComparison.OrdinalIgnoreCase)))
                {
                    var prop = property as PropertySchema;
                    product.Properties.Add(prop.CloneAsExtensionContractProperty(product));
                }
            }
        }
        private static void SetCurrentDiagram(SingleDiagramDocView docview, PatternModelSchemaDiagram diagram, PatternSchema pattern)
        {
            docview.Diagram = diagram;

            pattern.WithTransaction(prod => prod.CurrentDiagramId = diagram.Id.ToString());
        }
        private static void SetCurrentDiagram(SingleDiagramDocView docview, PatternModelSchemaDiagram diagram, PatternSchema pattern)
        {
            docview.Diagram = diagram;

            pattern.WithTransaction(prod => prod.CurrentDiagramId = diagram.Id.ToString());
        }
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, PatternSchema element, global::System.Xml.XmlWriter writer)
		{
			// PatternHasViews
			global::System.Collections.ObjectModel.ReadOnlyCollection<PatternHasViews> allPatternHasViewsInstances = PatternHasViews.GetLinksToViews(element);
			if (!serializationContext.Result.Failed && allPatternHasViewsInstances.Count > 0)
			{
				writer.WriteStartElement("views");
				global::System.Type typeofPatternHasViews = typeof(PatternHasViews);
				foreach (PatternHasViews eachPatternHasViewsInstance in allPatternHasViewsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachPatternHasViewsInstance.GetType() != typeofPatternHasViews)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachPatternHasViewsInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachPatternHasViewsInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachPatternHasViewsInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachPatternHasViewsInstance.ViewSchema;
						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();
			}
	
			// PatternHasProvidedExtensionPoints
			global::System.Collections.ObjectModel.ReadOnlyCollection<PatternHasProvidedExtensionPoints> allPatternHasProvidedExtensionPointsInstances = PatternHasProvidedExtensionPoints.GetLinksToProvidedExtensionPoints(element);
			if (!serializationContext.Result.Failed && allPatternHasProvidedExtensionPointsInstances.Count > 0)
			{
				writer.WriteStartElement("providedExtensionPoints");
				global::System.Type typeofPatternHasProvidedExtensionPoints = typeof(PatternHasProvidedExtensionPoints);
				foreach (PatternHasProvidedExtensionPoints eachPatternHasProvidedExtensionPointsInstance in allPatternHasProvidedExtensionPointsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachPatternHasProvidedExtensionPointsInstance.GetType() != typeofPatternHasProvidedExtensionPoints)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachPatternHasProvidedExtensionPointsInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachPatternHasProvidedExtensionPointsInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachPatternHasProvidedExtensionPointsInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachPatternHasProvidedExtensionPointsInstance.ProvidedExtensionPointSchema;
						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>
		/// Reads all instances of relationship PatternHasProvidedExtensionPoints.
		/// </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 PatternSchema instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadPatternHasProvidedExtensionPointsInstances(DslModeling::SerializationContext serializationContext, PatternSchema element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPointsSerializer = serializationContext.Directory.GetSerializer(ProvidedExtensionPointSchema.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPointsSerializer != null, "Cannot find serializer for ProvidedExtensionPointSchema!");
				ProvidedExtensionPointSchema newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPoints = newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPointsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as ProvidedExtensionPointSchema;
				if (newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPoints != null)
				{
					element.ProvidedExtensionPoints.Add(newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPoints);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPoints.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPoints.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newProvidedExtensionPointSchemaOfPatternHasProvidedExtensionPoints, reader);
				}
				else
				{
					global::System.Type typeofPatternHasProvidedExtensionPoints = typeof(PatternHasProvidedExtensionPoints);
					DslModeling::DomainRelationshipXmlSerializer newPatternHasProvidedExtensionPointsSerializer = serializationContext.Directory.GetSerializer(PatternHasProvidedExtensionPoints.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newPatternHasProvidedExtensionPointsSerializer != null, "Cannot find serializer for PatternHasProvidedExtensionPoints!");
					PatternHasProvidedExtensionPoints newPatternHasProvidedExtensionPoints = newPatternHasProvidedExtensionPointsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as PatternHasProvidedExtensionPoints;
					if (newPatternHasProvidedExtensionPoints != null)
					{
						if (newPatternHasProvidedExtensionPoints.GetType() == typeofPatternHasProvidedExtensionPoints)
						{	// The relationship should be serialized in short-form.
							PatternModelSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(PatternHasProvidedExtensionPoints));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newPatternHasProvidedExtensionPoints, PatternHasProvidedExtensionPoints.PatternSchemaDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newPatternHasProvidedExtensionPoints.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newPatternHasProvidedExtensionPoints.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newPatternHasProvidedExtensionPoints, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
		/// <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 PatternSchema instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, PatternSchema element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "views":	// Relationship "PatternHasViews"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <views>
							ReadPatternHasViewsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </views>
						}
						break;
					case "providedExtensionPoints":	// Relationship "PatternHasProvidedExtensionPoints"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <providedExtensionPoints>
							ReadPatternHasProvidedExtensionPointsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </providedExtensionPoints>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}