/// <summary> /// Populates the customization settings for the given customizable element, /// from the attributes on attributed DomainProperties and DomainRoles in this domain model. /// </summary> internal static void EnsurePolicyPopulated(CustomizableElementSchema element) { if (element == null) { return; } // Populate settings from domain properties which are attributed. PopulateFromOwnedDomainProperties(element); // Populate settings from domain roles which are attributed. PopulateFromEmbeddedRelationshipDomainRoleProperties(element); }
/// <summary> /// Repaints the compartment shape for the given element. /// </summary> private static void RepaintCompartmentShape(CustomizableElementSchema element) { Guard.NotNull(() => element, element); foreach (var shape in PresentationViewsSubject.GetPresentation(element)) { CompartmentShape compartment = shape as CompartmentShape; if (compartment != null) { compartment.Invalidate(); } } }
private static void WriteChildElements(DslModeling::SerializationContext serializationContext, CustomizableElementSchema element, global::System.Xml.XmlWriter writer) { // CustomizableElementHasPolicy CustomizableElementHasPolicy theCustomizableElementHasPolicyInstance = CustomizableElementHasPolicy.GetLinkToPolicy(element); if (!serializationContext.Result.Failed && theCustomizableElementHasPolicyInstance != null) { global::System.Type typeofCustomizableElementHasPolicy = typeof(CustomizableElementHasPolicy); if (theCustomizableElementHasPolicyInstance.GetType() != typeofCustomizableElementHasPolicy) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(theCustomizableElementHasPolicyInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + theCustomizableElementHasPolicyInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, theCustomizableElementHasPolicyInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = theCustomizableElementHasPolicyInstance.CustomizationPolicySchema; 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); } } }
/// <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 CustomizableElementSchema instance that will get the deserialized data.</param> private static void ReadChildElements(DslModeling::SerializationContext serializationContext, CustomizableElementSchema element, global::System.Xml.XmlReader reader) { if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { if (DslModeling::DomainRoleInfo.GetElementLinks<CustomizableElementHasPolicy> (element, CustomizableElementHasPolicy.CustomizableElementSchemaDomainRoleId).Count == 0) { DslModeling::DomainClassXmlSerializer newCustomizationPolicySchemaOfCustomizableElementHasPolicySerializer = serializationContext.Directory.GetSerializer(CustomizationPolicySchema.DomainClassId); global::System.Diagnostics.Debug.Assert(newCustomizationPolicySchemaOfCustomizableElementHasPolicySerializer != null, "Cannot find serializer for CustomizationPolicySchema!"); CustomizationPolicySchema newCustomizationPolicySchemaOfCustomizableElementHasPolicy = newCustomizationPolicySchemaOfCustomizableElementHasPolicySerializer.TryCreateInstance(serializationContext, reader, element.Partition) as CustomizationPolicySchema; if (newCustomizationPolicySchemaOfCustomizableElementHasPolicy != null) { element.Policy = newCustomizationPolicySchemaOfCustomizableElementHasPolicy; DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newCustomizationPolicySchemaOfCustomizableElementHasPolicy.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newCustomizationPolicySchemaOfCustomizableElementHasPolicy.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newCustomizationPolicySchemaOfCustomizableElementHasPolicy, reader); } else { DslModeling::DomainRelationshipXmlSerializer newCustomizableElementHasPolicySerializer = serializationContext.Directory.GetSerializer(CustomizableElementHasPolicy.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(newCustomizableElementHasPolicySerializer != null, "Cannot find serializer for CustomizableElementHasPolicy!"); CustomizableElementHasPolicy newCustomizableElementHasPolicy = newCustomizableElementHasPolicySerializer.TryCreateDerivedInstance (serializationContext, reader, element.Partition) as CustomizableElementHasPolicy; if (newCustomizableElementHasPolicy != null) { DslModeling::DomainRoleInfo.SetRolePlayer (newCustomizableElementHasPolicy, CustomizableElementHasPolicy.CustomizableElementSchemaDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newCustomizableElementHasPolicy.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newCustomizableElementHasPolicy.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newCustomizableElementHasPolicy, reader); } } } } }
/// <summary> /// Searches for the customizable attribute and if found creates a new setting uisng the name of the given member. /// </summary> private static void CreateSettingForAttribute(CustomizableElementSchema element, MemberInfo attributedMember, MemberInfo namedMember) { // Query the attributes of the instance, for a customization attribute. CustomizableDomainElementSettingAttribute[] attributes = (CustomizableDomainElementSettingAttribute[])attributedMember.GetCustomAttributes(typeof(CustomizableDomainElementSettingAttribute), true); if (attributes.Count() > 0) { var propertyId = (namedMember != null) ? namedMember.Name : attributedMember.Name; // Create a new corresponding setting (for the first attribute only: AllowMultiple=false) CustomizableDomainElementSettingAttribute attribute = attributes[0]; if (!element.Policy.Settings.Any(s => s.PropertyId == propertyId)) { element.Store.TransactionManager.DoWithinTransaction(() => { var setting = element.Policy.Create<CustomizableSettingSchema>(); setting.PropertyId = propertyId; setting.DefaultValue = attribute.DefaultValue; }); } } }
/// <summary> /// Populates the collection of settings by searching for <see cref="CustomizableDomainElementSettingAttribute"/> attributes /// on the embedded relationships of the given element. /// </summary> private static void PopulateFromEmbeddedRelationshipDomainRoleProperties(CustomizableElementSchema element) { DomainClassInfo currentElementInfo = element.GetDomainClass(); // Traverse all embedded domain relationships IEnumerable<DomainRoleInfo> sourceDomainRoleInfos = currentElementInfo.AllDomainRolesPlayed.Where(role => role.IsEmbedding); foreach (DomainRoleInfo sourceDomainRole in sourceDomainRoleInfos) { PropertyInfo sourceRolePropertyType = sourceDomainRole.RolePlayer.ImplementationClass.GetProperty(sourceDomainRole.PropertyName); PropertyInfo attributedRelationshipPropertyType = sourceDomainRole.DomainRelationship.ImplementationClass.GetProperty(sourceDomainRole.Name); if (attributedRelationshipPropertyType != null) { // Create the setting, if the property of the relationsip on the opposite side is attributed CreateSettingForAttribute(element, attributedRelationshipPropertyType, sourceRolePropertyType); } } }
/// <summary> /// Populates the collection of settings by searching for <see cref="CustomizableDomainElementSettingAttribute"/> attributes /// on the domain properties of the given element. /// </summary> private static void PopulateFromOwnedDomainProperties(CustomizableElementSchema element) { DomainClassInfo currentElementInfo = element.GetDomainClass(); // Traverse all domain properties IEnumerable<DomainPropertyInfo> domainPropertyInfos = currentElementInfo.AllDomainProperties; foreach (DomainPropertyInfo domainPropertyInfo in domainPropertyInfos) { PropertyInfo domainPropertyType = domainPropertyInfo.PropertyInfo; // Create the setting, if domain property is attributed CreateSettingForAttribute(element, domainPropertyType, null); } }