public override void SetValue(object component, object value)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            RuleConditionReference conditionDecl = component as RuleConditionReference;

            if (conditionDecl == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.NotARuleConditionReference, "component"), "component");
            }

            string conditionName = value as string;

            if ((conditionName == null) || (conditionName.TrimEnd().Length == 0))
            {
                conditionName = string.Empty;
            }

            ISite site = PropertyDescriptorUtils.GetSite(this.ServiceProvider, component);

            if (site == null)
            {
                string message = string.Format(CultureInfo.CurrentCulture, Messages.MissingService, typeof(ISite).FullName);
                throw new InvalidOperationException(message);
            }

            RuleConditionCollection conditionDefinitions = null;
            RuleDefinitions         rules = ConditionHelper.Load_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity));

            if (rules != null)
            {
                conditionDefinitions = rules.Conditions;
            }

            if (conditionDefinitions != null && conditionName.Length != 0 && !conditionDefinitions.Contains(conditionName))
            {
                //in this case, RuleExpressionCondition is the only type allowed in the ruleConditionCollection
                RuleExpressionCondition newCondition = new RuleExpressionCondition();
                newCondition.Name = conditionName;
                conditionDefinitions.Add(newCondition);
                ConditionHelper.Flush_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity));
            }

            // Cause component change events to be fired.
            PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(component)["ConditionName"];

            if (propertyDescriptor != null)
            {
                PropertyDescriptorUtils.SetPropertyValue(site, propertyDescriptor, component, conditionName);
            }
        }
Ejemplo n.º 2
0
        public override void SetValue(object component, object value)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (!(component is RuleConditionReference))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.NotARuleConditionReference, new object[] { "component" }), "component");
            }
            string key = value as string;

            if ((key == null) || (key.TrimEnd(new char[0]).Length == 0))
            {
                key = string.Empty;
            }
            ISite serviceProvider = PropertyDescriptorUtils.GetSite(base.ServiceProvider, component);

            if (serviceProvider == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingService, new object[] { typeof(ISite).FullName }));
            }
            RuleConditionCollection conditions  = null;
            RuleDefinitions         definitions = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity));

            if (definitions != null)
            {
                conditions = definitions.Conditions;
            }
            if (((conditions != null) && (key.Length != 0)) && !conditions.Contains(key))
            {
                RuleExpressionCondition item = new RuleExpressionCondition {
                    Name = key
                };
                conditions.Add(item);
                ConditionHelper.Flush_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity));
            }
            PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(component)["ConditionName"];

            if (propertyDescriptor != null)
            {
                PropertyDescriptorUtils.SetPropertyValue(serviceProvider, propertyDescriptor, component, key);
            }
        }