コード例 #1
0
        /// <summary>
        /// Deletes all the contract properties for the given providedExtension point.
        /// </summary>
        private static void ClearAllProvidedContractProperties(this PatternElementSchema element)
        {
            Guard.NotNull(() => element, element);

            var contractProperties = element.GetContractProperties();

            foreach (var vp in contractProperties)
            {
                vp.SetLocks(Locks.None);
                element.Properties.Remove(vp);
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a copy of the given property as a <see cref="PropertyUsages.ExtensionContract"/> property.
        /// </summary>
        public static PropertySchema CloneAsExtensionContractProperty(this PropertySchema source, PatternElementSchema owner)
        {
            Guard.NotNull(() => source, source);
            Guard.NotNull(() => owner, owner);

            PropertySchema newProperty = null;
            owner.Store.TransactionManager.DoWithinTransaction(() =>
                {
                    newProperty = owner.Store.ElementFactory.CreateElement<PropertySchema>()
                        .With(p =>
                        {
                            p.BaseId = source.BaseId;
                            p.Category = source.Category;
                            p.RawDefaultValue = source.RawDefaultValue;
                            p.Description = source.Description;
                            p.DisplayName = source.DisplayName;
                            p.EditorTypeName = source.EditorTypeName;
                            p.IsCustomizable = source.IsCustomizable;
                            p.IsReadOnly = source.IsReadOnly;
                            p.IsSystem = source.IsSystem;
                            p.IsVisible = source.IsVisible;
                            p.Name = source.Name;
                            p.Type = source.Type;
                            p.TypeConverterTypeName = source.TypeConverterTypeName;
                            p.RawValidationRules = source.RawValidationRules;
                            p.EnsurePolicyAndDefaultSettings();
                        });
                });

            // Copy customization settings
            foreach (var srcSetting in source.Policy.Settings)
            {
                var setting = newProperty.Policy.Settings.First(s => s.PropertyId == srcSetting.PropertyId);
                setting.Value = srcSetting.Value;
                if (!setting.Value)
                {
                    setting.Disable();
                }
            }

            // Apply Tailoring customization rules
            if (source.IsCustomizable == CustomizationState.False
                || (source.IsCustomizable == CustomizationState.Inherited && source.GetAncestorCustomizationState() == CustomizationState.False))
            {
                newProperty.DisableCustomization();
            }

            // Convert to a contract property
            newProperty.MakeContractProperty(source.Id.ToString());

            return newProperty;
        }
コード例 #3
0
        /// <summary>
        /// Returns the value of the property projected from the containing link to the element.
        /// </summary>
        /// <returns></returns>
        public static TResult GetProjectedLinkProperty <TResult>(this PatternElementSchema element, Func <IContainingLinkSchema, TResult> property)
        {
            if (element is AbstractElementSchema)
            {
                var viewLink = DomainRoleInfo.GetElementLinks <ViewHasElements>(element, ViewHasElements.AbstractElementSchemaDomainRoleId).FirstOrDefault();
                if (viewLink != null)
                {
                    return(property(viewLink));
                }

                var elementLink = DomainRoleInfo.GetElementLinks <ElementHasElements>(element, ElementHasElements.ChildElementDomainRoleId).FirstOrDefault();
                if (elementLink == null)
                {
                    throw new InvalidOperationException(Resources.AutoCreate_NoParentLinkFound);
                }

                return(property(elementLink));
            }

            if (element is ExtensionPointSchema)
            {
                var viewLink = DomainRoleInfo.GetElementLinks <ViewHasExtensionPoints>(element, ViewHasExtensionPoints.ExtensionPointSchemaDomainRoleId).FirstOrDefault();
                if (viewLink != null)
                {
                    return(property(viewLink));
                }

                var elementLink = DomainRoleInfo.GetElementLinks <ElementHasExtensionPoints>(element, ElementHasExtensionPoints.ChildElementDomainRoleId).FirstOrDefault();
                if (elementLink == null)
                {
                    throw new InvalidOperationException(Resources.AutoCreate_NoParentLinkFound);
                }

                return(property(elementLink));
            }


            throw new NotImplementedException();
        }
コード例 #4
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, PatternElementSchema element, global::System.Xml.XmlWriter writer)
		{
			// PatternElementHasProperties
			global::System.Collections.ObjectModel.ReadOnlyCollection<PatternElementHasProperties> allPatternElementHasPropertiesInstances = PatternElementHasProperties.GetLinksToProperties(element);
			if (!serializationContext.Result.Failed && allPatternElementHasPropertiesInstances.Count > 0)
			{
				writer.WriteStartElement("properties");
				global::System.Type typeofPatternElementHasProperties = typeof(PatternElementHasProperties);
				foreach (PatternElementHasProperties eachPatternElementHasPropertiesInstance in allPatternElementHasPropertiesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachPatternElementHasPropertiesInstance.GetType() != typeofPatternElementHasProperties)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachPatternElementHasPropertiesInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachPatternElementHasPropertiesInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachPatternElementHasPropertiesInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachPatternElementHasPropertiesInstance.PropertySchema;
						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();
			}
	
			// PatternElementHasAutomationSettings
			global::System.Collections.ObjectModel.ReadOnlyCollection<PatternElementHasAutomationSettings> allPatternElementHasAutomationSettingsInstances = PatternElementHasAutomationSettings.GetLinksToAutomationSettings(element);
			if (!serializationContext.Result.Failed && allPatternElementHasAutomationSettingsInstances.Count > 0)
			{
				writer.WriteStartElement("automationSettings");
				global::System.Type typeofPatternElementHasAutomationSettings = typeof(PatternElementHasAutomationSettings);
				foreach (PatternElementHasAutomationSettings eachPatternElementHasAutomationSettingsInstance in allPatternElementHasAutomationSettingsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachPatternElementHasAutomationSettingsInstance.GetType() != typeofPatternElementHasAutomationSettings)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachPatternElementHasAutomationSettingsInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachPatternElementHasAutomationSettingsInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachPatternElementHasAutomationSettingsInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachPatternElementHasAutomationSettingsInstance.AutomationSettingsSchema;
						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();
			}
	
		}
コード例 #5
0
		private static void WritePropertiesAsElements(DslModeling::SerializationContext serializationContext, PatternElementSchema element, global::System.Xml.XmlWriter writer)
		{
			// ValidationRules
			if (!serializationContext.Result.Failed)
			{
				global::System.String propValue = element.ValidationRules;
				if (!serializationContext.Result.Failed)
				{
					if (!string.IsNullOrEmpty(propValue))
					PatternModelSerializationHelper.Instance.WriteElementString(serializationContext, element, writer, "validationRules", propValue);
	
				}
			}
		} 
コード例 #6
0
		/// <summary>
		/// Reads all instances of relationship PatternElementHasAutomationSettings.
		/// </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 PatternElementSchema instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadPatternElementHasAutomationSettingsInstances(DslModeling::SerializationContext serializationContext, PatternElementSchema element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newAutomationSettingsSchemaOfPatternElementHasAutomationSettingsSerializer = serializationContext.Directory.GetSerializer(AutomationSettingsSchema.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newAutomationSettingsSchemaOfPatternElementHasAutomationSettingsSerializer != null, "Cannot find serializer for AutomationSettingsSchema!");
				AutomationSettingsSchema newAutomationSettingsSchemaOfPatternElementHasAutomationSettings = newAutomationSettingsSchemaOfPatternElementHasAutomationSettingsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as AutomationSettingsSchema;
				if (newAutomationSettingsSchemaOfPatternElementHasAutomationSettings != null)
				{
					element.AutomationSettings.Add(newAutomationSettingsSchemaOfPatternElementHasAutomationSettings);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newAutomationSettingsSchemaOfPatternElementHasAutomationSettings.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newAutomationSettingsSchemaOfPatternElementHasAutomationSettings.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newAutomationSettingsSchemaOfPatternElementHasAutomationSettings, reader);
				}
				else
				{
					global::System.Type typeofPatternElementHasAutomationSettings = typeof(PatternElementHasAutomationSettings);
					DslModeling::DomainRelationshipXmlSerializer newPatternElementHasAutomationSettingsSerializer = serializationContext.Directory.GetSerializer(PatternElementHasAutomationSettings.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newPatternElementHasAutomationSettingsSerializer != null, "Cannot find serializer for PatternElementHasAutomationSettings!");
					PatternElementHasAutomationSettings newPatternElementHasAutomationSettings = newPatternElementHasAutomationSettingsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as PatternElementHasAutomationSettings;
					if (newPatternElementHasAutomationSettings != null)
					{
						if (newPatternElementHasAutomationSettings.GetType() == typeofPatternElementHasAutomationSettings)
						{	// The relationship should be serialized in short-form.
							PatternModelSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(PatternElementHasAutomationSettings));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newPatternElementHasAutomationSettings, PatternElementHasAutomationSettings.PatternElementSchemaDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newPatternElementHasAutomationSettings.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newPatternElementHasAutomationSettings.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newPatternElementHasAutomationSettings, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
コード例 #7
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 PatternElementSchema instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, PatternElementSchema 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 "PatternElementHasProperties"
						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>
							ReadPatternElementHasPropertiesInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </properties>
						}
						break;
					case "automationSettings":	// Relationship "PatternElementHasAutomationSettings"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <automationSettings>
							ReadPatternElementHasAutomationSettingsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </automationSettings>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}
コード例 #8
0
		private static void ReadPropertiesFromElements(DslModeling::SerializationContext serializationContext, PatternElementSchema element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "validationRules":	// ValidationRules
						if (reader.IsEmptyElement)
						{	// No serialized value, must be default one.
							DslModeling::SerializationUtilities.Skip(reader);  // Skip this tag.
						}
						else
						{
							string strValidationRules = PatternModelSerializationHelper.Instance.ReadElementContentAsString(serializationContext, element, reader);
							global::System.String valueOfValidationRules;
							if (DslModeling::SerializationUtilities.TryGetValue<global::System.String>(serializationContext, strValidationRules, out valueOfValidationRules))
							{
								element.ValidationRules = valueOfValidationRules;
							}
							else
							{	// Invalid property value, ignored.
								PatternModelSerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "validationRules", typeof(global::System.String), strValidationRules);
							}
	
							DslModeling::SerializationUtilities.SkipToNextElement(reader);
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}
コード例 #9
0
        /// <summary>
        /// Creates a copy of the given property as a <see cref="PropertyUsages.ExtensionContract"/> property.
        /// </summary>
        public static PropertySchema CloneAsExtensionContractProperty(this PropertySchema source, PatternElementSchema owner)
        {
            Guard.NotNull(() => source, source);
            Guard.NotNull(() => owner, owner);

            PropertySchema newProperty = null;

            owner.Store.TransactionManager.DoWithinTransaction(() =>
            {
                newProperty = owner.Store.ElementFactory.CreateElement <PropertySchema>()
                              .With(p =>
                {
                    p.BaseId                = source.BaseId;
                    p.Category              = source.Category;
                    p.RawDefaultValue       = source.RawDefaultValue;
                    p.Description           = source.Description;
                    p.DisplayName           = source.DisplayName;
                    p.EditorTypeName        = source.EditorTypeName;
                    p.IsCustomizable        = source.IsCustomizable;
                    p.IsReadOnly            = source.IsReadOnly;
                    p.IsSystem              = source.IsSystem;
                    p.IsVisible             = source.IsVisible;
                    p.Name                  = source.Name;
                    p.Type                  = source.Type;
                    p.TypeConverterTypeName = source.TypeConverterTypeName;
                    p.RawValidationRules    = source.RawValidationRules;
                    p.EnsurePolicyAndDefaultSettings();
                });
            });

            // Copy customization settings
            foreach (var srcSetting in source.Policy.Settings)
            {
                var setting = newProperty.Policy.Settings.First(s => s.PropertyId == srcSetting.PropertyId);
                setting.Value = srcSetting.Value;
                if (!setting.Value)
                {
                    setting.Disable();
                }
            }

            // Apply Tailoring customization rules
            if (source.IsCustomizable == CustomizationState.False ||
                (source.IsCustomizable == CustomizationState.Inherited && source.GetAncestorCustomizationState() == CustomizationState.False))
            {
                newProperty.DisableCustomization();
            }

            // Convert to a contract property
            newProperty.MakeContractProperty(source.Id.ToString());

            return(newProperty);
        }
コード例 #10
0
 /// <summary>
 /// Returns the contract properties for this element.
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 private static IEnumerable <PropertySchema> GetContractProperties(this PatternElementSchema element)
 {
     return(element.Properties.Where(vp => vp.IsUsageExtensionPoint()).ToList());
 }