Ejemplo n.º 1
0
 public void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.element = this.store.ElementFactory.CreateElement <ElementSchema>();
     });
     this.setting      = this.element.Policy.Create <CustomizableSettingSchema>();
     validationContext = new ValidationContext(ValidationCategories.Save, this.element);
 }
 public void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.element = this.store.ElementFactory.CreateElement<ElementSchema>();
     });
     this.setting = this.element.Policy.Create<CustomizableSettingSchema>();
     validationContext = new ValidationContext(ValidationCategories.Save, this.element);
 }
 public void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.element = this.store.ElementFactory.CreateElement <ElementSchema>();
     });
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.element.IsCustomizable = CustomizationState.True;
     });
 }
 public void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.element = this.store.ElementFactory.CreateElement<ElementSchema>();
     });
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         this.element.IsCustomizable = CustomizationState.True;
     });
 }
        /// <summary>
        /// Ensures the customization policy and default settings are created.
        /// </summary>
        public static void EnsurePolicyAndDefaultSettings(this CustomizableElementSchema element)
        {
            // Add the customization policy
            if (element.Policy == null)
            {
                element.WithTransaction(elem => elem.Create <CustomizationPolicySchema>());
            }

            // Add the customizable settings derived from attributes on this model.
            CustomizableSettingSchema.EnsurePolicyPopulated(element);
        }
Ejemplo n.º 6
0
        /// <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();
                }
            }
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        /// <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);
            }
        }
Ejemplo n.º 9
0
        /// <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>
        /// Returns a descriptor for the customization policy.
        /// </summary>
        /// <returns>
        /// An ExpandableObjectConverter descriptor, that has attributes copied from the CustomizationPolicy relationship and
        /// the CustomizationPolicy domain class.
        /// </returns>
        private static PropertyDescriptor GetDescriptorForPolicy(CustomizableElementSchema element)
        {
            var attributes = new List <Attribute>();

            //// Get the attributes of the domain role between element and policy.
            var sourceRole = element.GetDomainClass().AllDomainRolesPlayed.Single(
                role => role.DomainRelationship.Name == typeof(CustomizableElementHasPolicy).Name);

            //// Copy meta-attributes from CustomizationPolicy MEL
            var category = typeof(CustomizationPolicySchema).Category();

            if (!string.IsNullOrEmpty(category))
            {
                attributes.Add(new CategoryAttribute(category));
            }

            //// Add presentation attributes
            attributes.Add(new TypeConverterAttribute(typeof(CustomizationPolicyConverter)));

            return(new CustomizationPolicyRolePlayerDescriptor(element, sourceRole.OppositeDomainRole, attributes.ToArray()));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the value of the DomainElementSettingType property.
        /// </summary>
        internal CustomizableDomainElementSettingType GetDomainElementSettingTypeValue()
        {
            // Determine whether the current name is a DomainProperty or a DomainRole
            CustomizableElementSchema element = this.Policy.Owner;

            if (element != null)
            {
                DomainPropertyInfo domainPropertyInfo = element.GetDomainClass().FindDomainProperty(this.PropertyId, true);
                if (domainPropertyInfo != null)
                {
                    return(CustomizableDomainElementSettingType.DomainProperty);
                }
                else
                {
                    // Must be a domain role property
                    return(CustomizableDomainElementSettingType.DomainRole);
                }
            }

            return(CustomizableDomainElementSettingType.DomainProperty);
        }
Ejemplo n.º 12
0
        /// <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>
        /// Applies the rules for customization of this element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="properties"></param>
        private static PropertyDescriptorCollection ApplyCustomizationRules(CustomizableElementSchema element, IEnumerable <PropertyDescriptor> properties)
        {
            var descriptors = properties.ToDictionary(property => property.Name);

            // Add read-only attribute to IsCustomizable property, when the element customization is disabled.
            if (!element.IsCustomizationEnabled)
            {
                if (element.Policy != null)
                {
                    // Hide the policy
                    var policyProperty = descriptors[Reflector <CustomizableElementSchema> .GetProperty(elem => elem.Policy).Name];
                    descriptors[policyProperty.Name] = new DelegatingPropertyDescriptor(
                        policyProperty, new BrowsableAttribute(false));
                }

                // Element.IsCustomizable property is displayed as read-only to author/tailor with its current value.
                var isCustomizableProperty = descriptors[Reflector <CustomizableElementSchema> .GetProperty(elem => elem.IsCustomizable).Name];
                descriptors[isCustomizableProperty.Name] = new DelegatingPropertyDescriptor(
                    isCustomizableProperty,
                    new ReadOnlyAttribute(true));
            }

            if (element.Policy != null)
            {
                // Add read-only attribute to the property of the element that the policy.setting refers to, when the setting is not customizable.
                foreach (var disabledSetting in element.Policy.Settings.Where(setting => !setting.IsEnabled))
                {
                    // Disable the referred to property of this element
                    descriptors[disabledSetting.PropertyId] = new DelegatingPropertyDescriptor(
                        descriptors[disabledSetting.PropertyId],
                        new ReadOnlyAttribute(true));
                }
            }

            return(new PropertyDescriptorCollection(descriptors.Values.ToArray()));
        }
        /// <summary>
        /// Applies the rules for customization of this element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="properties"></param>
        private static PropertyDescriptorCollection ApplyCustomizationRules(CustomizableElementSchema element, IEnumerable<PropertyDescriptor> properties)
        {
            var descriptors = properties.ToDictionary(property => property.Name);

            // Add read-only attribute to IsCustomizable property, when the element customization is disabled.
            if (!element.IsCustomizationEnabled)
            {
                if (element.Policy != null)
                {
                    // Hide the policy
                    var policyProperty = descriptors[Reflector<CustomizableElementSchema>.GetProperty(elem => elem.Policy).Name];
                    descriptors[policyProperty.Name] = new DelegatingPropertyDescriptor(
                        policyProperty, new BrowsableAttribute(false));
                }

                // Element.IsCustomizable property is displayed as read-only to author/tailor with its current value.
                var isCustomizableProperty = descriptors[Reflector<CustomizableElementSchema>.GetProperty(elem => elem.IsCustomizable).Name];
                descriptors[isCustomizableProperty.Name] = new DelegatingPropertyDescriptor(
                    isCustomizableProperty,
                    new ReadOnlyAttribute(true));
            }

            if (element.Policy != null)
            {
                // Add read-only attribute to the property of the element that the policy.setting refers to, when the setting is not customizable.
                foreach (var disabledSetting in element.Policy.Settings.Where(setting => !setting.IsEnabled))
                {
                    // Disable the referred to property of this element
                    descriptors[disabledSetting.PropertyId] = new DelegatingPropertyDescriptor(
                        descriptors[disabledSetting.PropertyId],
                        new ReadOnlyAttribute(true));
                }
            }

            return new PropertyDescriptorCollection(descriptors.Values.ToArray());
        }
        /// <summary>
        /// Returns a descriptor for the customization policy.
        /// </summary>
        /// <returns>
        /// An ExpandableObjectConverter descriptor, that has attributes copied from the CustomizationPolicy relationship and 
        /// the CustomizationPolicy domain class.
        /// </returns>
        private static PropertyDescriptor GetDescriptorForPolicy(CustomizableElementSchema element)
        {
            var attributes = new List<Attribute>();

            //// Get the attributes of the domain role between element and policy.
            var sourceRole = element.GetDomainClass().AllDomainRolesPlayed.Single(
                role => role.DomainRelationship.Name == typeof(CustomizableElementHasPolicy).Name);

            //// Copy meta-attributes from CustomizationPolicy MEL
            var category = typeof(CustomizationPolicySchema).Category();
            if (!string.IsNullOrEmpty(category))
            {
                attributes.Add(new CategoryAttribute(category));
            }

            //// Add presentation attributes
            attributes.Add(new TypeConverterAttribute(typeof(CustomizationPolicyConverter)));

            return new CustomizationPolicyRolePlayerDescriptor(element, sourceRole.OppositeDomainRole, attributes.ToArray());
        }
 /// <summary>
 /// Returns the first ancestor customizable element that has a customization value.
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 public static CustomizableElementSchema FindYoungestNonInheritingAncestor(this CustomizableElementSchema element)
 {
     return(element.Traverse(
                c => DomainClassInfo.FindEmbeddingElement(c) as CustomizableElementSchema,
                c => c == null || c.IsCustomizable != CustomizationState.Inherited));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomizationPolicyRolePlayerDescriptor"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="domainRoleInfo">The domain role info.</param>
 /// <param name="attributes">The attributes.</param>
 public CustomizationPolicyRolePlayerDescriptor(CustomizableElementSchema element, DomainRoleInfo domainRoleInfo, Attribute[] attributes)
     : base(element, domainRoleInfo, attributes)
 {
 }
        /// <summary>
        /// Returns the first ancestor customizable element that has a customization value.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static CustomizationState GetAncestorCustomizationState(this CustomizableElementSchema element)
        {
            var ancestor = element.FindYoungestNonInheritingAncestor();

            return(ancestor.IsCustomizable);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomizationPolicyRolePlayerDescriptor"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="domainRoleInfo">The domain role info.</param>
 /// <param name="attributes">The attributes.</param>
 public CustomizationPolicyRolePlayerDescriptor(CustomizableElementSchema element, DomainRoleInfo domainRoleInfo, Attribute[] attributes)
     : base(element, domainRoleInfo, attributes)
 {
 }