Exemplo n.º 1
0
        internal static string ConvertRuleExpressionCondition(RuleExpressionCondition expression)
        {
            var builder = new StringBuilder();

            builder.Append(ConvertCodeExpression(expression.Expression));
            return(builder.ToString());
        }
Exemplo n.º 2
0
        protected override void UpdateListViewItem(object ruleObject, ListViewItem listViewItem)
        {
            RuleExpressionCondition declarativeRuleDefinition = ruleObject as RuleExpressionCondition;

            ITypeProvider typeProvider = (ITypeProvider)this.Activity.Site.GetService(typeof(ITypeProvider));

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

            RuleValidation validator = new RuleValidation(this.Activity, typeProvider, false);
            bool           valid     = declarativeRuleDefinition.Validate(validator);

            listViewItem.Tag  = declarativeRuleDefinition;
            listViewItem.Text = declarativeRuleDefinition.Name;

            string validText = valid ? Messages.Yes : Messages.No;

            if (listViewItem.SubItems.Count == 1)
            {
                listViewItem.SubItems.Add(validText);
            }
            else
            {
                listViewItem.SubItems[1].Text = validText;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// BaseRuleSetFilterExpressionProvider must interpret all collection expression to string call
        /// one of methods ( ValidateAll, ValidateAny, ConditionCollectionCount ) with CodeExpression for one of collection item
        /// Example: ConditionCollectionAll(this.CustomerAccount.Addresses, "this.Organization == "Org1" && this.Line1 = "line"")
        /// exactly second parameter must be converted to CodeExpression statement by Parser in provider.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="codeExpr">The code expr.</param>
        /// <example>ConditionCollectionAll(this.CustomerAccount.Addresses, "this.Organization == \"Org1\" && this.Line1 = \"line\"");</example>
        /// <returns></returns>
        private static bool PredicateFunction(object item, System.CodeDom.CodeExpression codeExpr)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (codeExpr == null)
            {
                throw new ArgumentNullException("codeExpr");
            }

            bool    retVal = false;
            RuleSet rs     = new RuleSet();
            Rule    rule   = new Rule("collection expression rule");

            RuleExpressionCondition cond       = new RuleExpressionCondition(codeExpr);
            RuleValidation          validation = new RuleValidation(item.GetType(), null);

            rule.Condition = cond;
            rs.Rules.Add(rule);
            rs.Validate(validation);
            if (validation.Errors.Count > 0)
            {
                throw new Exception("Error count " + validation.Errors.Count);
            }
            RuleExecution execution = new RuleExecution(validation, item);

            retVal = cond.Evaluate(execution);

            return(retVal);
        }
        public override object GetValue(object component)
        {
            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");
            }

            if (conditionDecl.ConditionName != null)
            {
                RuleDefinitions rules = GetRuleDefinitions(component);
                if (rules != null)
                {
                    RuleConditionCollection conditionDefs = rules.Conditions;
                    if (conditionDefs != null && conditionDefs.Contains(conditionDecl.ConditionName))
                    {
                        //in this case, RuleExpressionCondition is the only type allowed in the ruleConditionCollection
                        RuleExpressionCondition conditionDefinition = (RuleExpressionCondition)conditionDefs[conditionDecl.ConditionName];
                        return(conditionDefinition.Expression);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 5
0
        public override void SetValue(object component, object value)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            RuleConditionReference reference = component as RuleConditionReference;

            if (reference == null)
            {
                throw new ArgumentNullException("component");
            }
            CodeExpression expression = value as CodeExpression;

            if (reference.ConditionName != null)
            {
                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) && conditions.Contains(reference.ConditionName))
                {
                    RuleExpressionCondition condition = (RuleExpressionCondition)conditions[reference.ConditionName];
                    condition.Expression = expression;
                    ConditionHelper.Flush_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity));
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Modify a single rule condition
        /// </summary>
        /// <param name="instance"></param>
        private static void ModifyRuleCondition(WorkflowInstance instance)
        {
            //create a workflow changes object
            WorkflowChanges wfChanges = new WorkflowChanges(
                instance.GetWorkflowDefinition());

            //retrieve the RuleDefinitions for the workflow
            RuleDefinitions ruleDefinitions
                = (RuleDefinitions)wfChanges.TransientWorkflow.GetValue(
                      RuleDefinitions.RuleDefinitionsProperty);

            if (ruleDefinitions != null)
            {
                if (ruleDefinitions.Conditions.Contains("conditionOne"))
                {
                    //retrieve the rule that we want to change
                    RuleExpressionCondition condition
                        = ruleDefinitions.Conditions["conditionOne"]
                          as RuleExpressionCondition;

                    //change the rule by setting the right side of the
                    //operation to 300 instead of the original value of 100.
                    //was:  this.TestNumber > 100
                    //now:  this.TestNumber > 300
                    CodeBinaryOperatorExpression codeExpression =
                        condition.Expression as CodeBinaryOperatorExpression;
                    codeExpression.Right = new CodePrimitiveExpression(300);

                    ValidateAndApplyChanges(instance, wfChanges);
                }
            }
        }
Exemplo n.º 7
0
        static void OnWorkflowIdle(object sender, WorkflowEventArgs e)
        {
            if (wasChanged)
            {
                return;
            }

            wasChanged = true;

            WorkflowInstance workflowInstance = e.WorkflowInstance;

            Int32 newAmount = 15000;

            Console.WriteLine("Dynamically change approved amount to {0:c}", newAmount);

            // Dynamic update of order rule
            WorkflowChanges workflowchanges = new WorkflowChanges(workflowInstance.GetWorkflowDefinition());

            CompositeActivity       transient       = workflowchanges.TransientWorkflow;
            RuleDefinitions         ruleDefinitions = (RuleDefinitions)transient.GetValue(RuleDefinitions.RuleDefinitionsProperty);
            RuleConditionCollection conditions      = ruleDefinitions.Conditions;
            RuleExpressionCondition condition1      = (RuleExpressionCondition)conditions["Check"];

            (condition1.Expression as CodeBinaryOperatorExpression).Right = new CodePrimitiveExpression(newAmount);

            workflowInstance.ApplyWorkflowChanges(workflowchanges);
        }
Exemplo n.º 8
0
        protected override void UpdateListViewItem(object ruleObject, ListViewItem listViewItem)
        {
            RuleExpressionCondition condition = ruleObject as RuleExpressionCondition;
            ITypeProvider           service   = (ITypeProvider)base.Activity.Site.GetService(typeof(ITypeProvider));

            if (service == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingService, new object[] { typeof(ITypeProvider).FullName }));
            }
            RuleValidation validation = new RuleValidation(base.Activity, service, false);
            bool           flag       = condition.Validate(validation);

            listViewItem.Tag  = condition;
            listViewItem.Text = condition.Name;
            string text = flag ? Messages.Yes : Messages.No;

            if (listViewItem.SubItems.Count == 1)
            {
                listViewItem.SubItems.Add(text);
            }
            else
            {
                listViewItem.SubItems[1].Text = text;
            }
        }
Exemplo n.º 9
0
        public WorkFlowIfElseRule()
        {
            IfElseActivity ifelse_activity = new IfElseActivity();

            branch1 = new IfElseBranchActivity();

            CodeActivity code_branch1 = new CodeActivity();
            CodeActivity code_branch2 = new CodeActivity();

            branch2 = new IfElseBranchActivity();

            code_branch1.Name         = "Code1";
            code_branch2.Name         = "Code2";
            code_branch1.ExecuteCode += new EventHandler(ExecuteCode1);
            code_branch2.ExecuteCode += new EventHandler(ExecuteCode2);

            branch1.Activities.Add(code_branch1);
            branch2.Activities.Add(code_branch2);

            RuleConditionReference condition1 = new RuleConditionReference();

            condition1.ConditionName = "Condition1";
            RuleExpressionCondition rc = new RuleExpressionCondition("Condition1",
                                                                     RulesBinaryOpTest.check_condition);

            definitions.Conditions.Add(rc);
            branch1.Condition = condition1;

            ifelse_activity.Activities.Add(branch1);
            ifelse_activity.Activities.Add(branch2);

            SetValue(RuleDefinitions.RuleDefinitionsProperty, definitions);
            Activities.Add(ifelse_activity);
        }
Exemplo n.º 10
0
        public override object GetValue(object component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            RuleConditionReference reference = component as RuleConditionReference;

            if (reference == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.NotARuleConditionReference, new object[] { "component" }), "component");
            }
            if (reference.ConditionName != null)
            {
                RuleDefinitions ruleDefinitions = base.GetRuleDefinitions(component);
                if (ruleDefinitions != null)
                {
                    RuleConditionCollection conditions = ruleDefinitions.Conditions;
                    if ((conditions != null) && conditions.Contains(reference.ConditionName))
                    {
                        RuleExpressionCondition condition = (RuleExpressionCondition)conditions[reference.ConditionName];
                        return(condition.Expression);
                    }
                }
            }
            return(null);
        }
        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);
            }
        }
Exemplo n.º 12
0
        private void OnItemClick(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            RuleNode node = (RuleNode)item.Tag;
            RuleExpressionCondition expressionCondition = (RuleExpressionCondition)node.Rule;

            WorkflowNode workflowNode = (WorkflowNode)node.Parent;

            EvaluateRuleDialog dialog = new EvaluateRuleDialog(expressionCondition.Expression, workflowNode.WorkflowType);

            dialog.ShowDialog();
        }
Exemplo n.º 13
0
        public RuleConditionDialog(System.Type activityType, ITypeProvider typeProvider, CodeExpression expression)
        {
            this.ruleExpressionCondition = new RuleExpressionCondition();
            if (activityType == null)
            {
                throw new ArgumentNullException("activityType");
            }
            this.InitializeComponent();
            RuleValidation validation = new RuleValidation(activityType, typeProvider);

            this.ruleParser = new Parser(validation);
            this.InitializeDialog(expression);
        }
Exemplo n.º 14
0
 protected override object OnNewInternal()
 {
     using (RuleConditionDialog dlg = new RuleConditionDialog(this.Activity, null))
     {
         if (DialogResult.OK == dlg.ShowDialog(this))
         {
             RuleExpressionCondition declarativeRuleDefinition = new RuleExpressionCondition();
             declarativeRuleDefinition.Expression = dlg.Expression;
             declarativeRuleDefinition.Name       = this.CreateNewName();
             this.declarativeConditionCollection.Add(declarativeRuleDefinition);
             return(declarativeRuleDefinition);
         }
     }
     return(null);
 }
Exemplo n.º 15
0
 protected override object OnNewInternal()
 {
     using (RuleConditionDialog dialog = new RuleConditionDialog(base.Activity, null))
     {
         if (DialogResult.OK == dialog.ShowDialog(this))
         {
             RuleExpressionCondition item = new RuleExpressionCondition {
                 Expression = dialog.Expression,
                 Name       = this.CreateNewName()
             };
             this.declarativeConditionCollection.Add(item);
             return(item);
         }
     }
     return(null);
 }
Exemplo n.º 16
0
        protected override string OnRenameInternal(object ruleObject)
        {
            RuleExpressionCondition item = ruleObject as RuleExpressionCondition;

            using (RenameRuleObjectDialog dialog = new RenameRuleObjectDialog(base.Activity.Site, item.Name, new RenameRuleObjectDialog.NameValidatorDelegate(this.IsUniqueName), this))
            {
                if ((dialog.ShowDialog(this) == DialogResult.OK) && (dialog.RuleObjectName != item.Name))
                {
                    this.declarativeConditionCollection.Remove(item);
                    item.Name = dialog.RuleObjectName;
                    this.declarativeConditionCollection.Add(item);
                    return(dialog.RuleObjectName);
                }
            }
            return(null);
        }
Exemplo n.º 17
0
        protected override bool OnEditInternal(object currentRuleObject, out object updatedRuleObject)
        {
            RuleExpressionCondition condition = currentRuleObject as RuleExpressionCondition;

            updatedRuleObject = null;
            using (RuleConditionDialog dialog = new RuleConditionDialog(base.Activity, condition.Expression))
            {
                if (DialogResult.OK == dialog.ShowDialog(this))
                {
                    updatedRuleObject = new RuleExpressionCondition(condition.Name, dialog.Expression);
                    this.declarativeConditionCollection.Remove(condition.Name);
                    this.declarativeConditionCollection.Add(updatedRuleObject as RuleExpressionCondition);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 18
0
        protected override void UpdatePreview(TextBox previewBox, object ruleObject)
        {
            RuleExpressionCondition condition = ruleObject as RuleExpressionCondition;

            if ((condition != null) && (condition.Expression != null))
            {
                RuleExpressionCondition condition2 = new RuleExpressionCondition(condition.Expression);
                System.Workflow.Activities.Common.NativeMethods.SendMessage(previewBox.Handle, 11, IntPtr.Zero, IntPtr.Zero);
                previewBox.Lines = condition2.ToString().Split(new char[] { '\n' });
                System.Workflow.Activities.Common.NativeMethods.SendMessage(previewBox.Handle, 11, new IntPtr(1), IntPtr.Zero);
                previewBox.Invalidate();
            }
            else
            {
                previewBox.Text = string.Empty;
            }
        }
Exemplo n.º 19
0
        protected override void UpdatePreview(TextBox previewBox, object ruleObject)
        {
            RuleExpressionCondition declarativeRuleDefinition = ruleObject as RuleExpressionCondition;

            if (declarativeRuleDefinition != null && declarativeRuleDefinition.Expression != null)
            {
                RuleExpressionCondition ruleExpressionCondition = new RuleExpressionCondition(declarativeRuleDefinition.Expression);
                NativeMethods.SendMessage(previewBox.Handle, NativeMethods.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);
                previewBox.Lines = ruleExpressionCondition.ToString().Split('\n');
                NativeMethods.SendMessage(previewBox.Handle, NativeMethods.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);
                previewBox.Invalidate();
            }
            else
            {
                previewBox.Text = string.Empty;
            }
        }
Exemplo n.º 20
0
 private void conditionTextBox_Validating(object sender, CancelEventArgs e)
 {
     try
     {
         this.ruleExpressionCondition = this.ruleParser.ParseCondition(this.conditionTextBox.Text);
         if (!string.IsNullOrEmpty(this.conditionTextBox.Text))
         {
             this.conditionTextBox.Text = this.ruleExpressionCondition.ToString().Replace("\n", "\r\n");
         }
         this.conditionErrorProvider.SetError(this.conditionTextBox, string.Empty);
         this.syntaxException = null;
     }
     catch (Exception exception)
     {
         this.syntaxException = exception;
         this.conditionErrorProvider.SetError(this.conditionTextBox, exception.Message);
     }
 }
Exemplo n.º 21
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);
            }
        }
Exemplo n.º 22
0
        public RuleConditionDialog(Activity activity, CodeExpression expression)
        {
            ITypeProvider provider;

            this.ruleExpressionCondition = new RuleExpressionCondition();
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            this.InitializeComponent();
            this.serviceProvider = activity.Site;
            if (this.serviceProvider != null)
            {
                IUIService service = this.serviceProvider.GetService(typeof(IUIService)) as IUIService;
                if (service != null)
                {
                    this.Font = (Font)service.Styles["DialogFont"];
                }
                provider = (ITypeProvider)this.serviceProvider.GetService(typeof(ITypeProvider));
                if (provider == null)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingService, new object[] { typeof(ITypeProvider).FullName }));
                }
                WorkflowDesignerLoader loader = this.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                if (loader != null)
                {
                    loader.Flush();
                }
            }
            else
            {
                TypeProvider provider2 = new TypeProvider(null);
                foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    provider2.AddAssembly(assembly);
                }
                provider = provider2;
            }
            RuleValidation validation = new RuleValidation(activity, provider, false);

            this.ruleParser = new Parser(validation);
            this.InitializeDialog(expression);
        }
        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 ArgumentNullException("component");
            }

            CodeExpression expression = value as CodeExpression;

            if (conditionDecl.ConditionName != null)
            {
                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 conditionDefs = null;
                RuleDefinitions         rules         = ConditionHelper.Load_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity));
                if (rules != null)
                {
                    conditionDefs = rules.Conditions;
                }

                if (conditionDefs != null && conditionDefs.Contains(conditionDecl.ConditionName))
                {
                    //in this case, RuleExpressionCondition is the only type allowed in the ruleConditionCollection
                    RuleExpressionCondition conditionDefinition = (RuleExpressionCondition)conditionDefs[conditionDecl.ConditionName];
                    conditionDefinition.Expression = expression;
                    ConditionHelper.Flush_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity));
                }
            }
        }
        protected virtual Rule CreateRule2(string expressionKey, FilterExpressionNodeCollection filters)
        {
            Rule rule = new Rule();

            rule.Active = true;

            //Mediachase.Web.Console.Providers.DomParser
            string expr = ConvertNodesToStringExpression(filters);
            RuleExpressionCondition conditionExpr = new RuleExpressionCondition();

            if (!String.IsNullOrEmpty(expr))
            {
                Parser p = new Parser();
                conditionExpr.Expression = p.ParseExpression(expr);
                rule.Name = expressionKey;
            }
            else
            {
                CodePrimitiveExpression truePrimitive = new CodePrimitiveExpression(true);
                conditionExpr.Expression = truePrimitive;
                rule.Name = "AlwaysTrue";
            }

            rule.Condition            = conditionExpr;
            rule.Priority             = 9999; //Nust be first evaluate
            rule.ReevaluationBehavior = RuleReevaluationBehavior.Never;

            // Create succeeded assignment
            // this.ValidationResult.IsValid = True
            CodeThisReferenceExpression     thisRef           = new CodeThisReferenceExpression();
            CodePropertyReferenceExpression resultRef         = new CodePropertyReferenceExpression(thisRef, "ValidationResult");
            CodePropertyReferenceExpression validRef          = new CodePropertyReferenceExpression(resultRef, "IsValid");
            CodeAssignStatement             ruleIsValidAction = new CodeAssignStatement(validRef, new CodePrimitiveExpression(true));

            rule.ThenActions.Add(new RuleStatementAction(ruleIsValidAction));

            return(rule);
        }
        private void conditionTextBox_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                this.ruleExpressionCondition = (RuleExpressionCondition)this.ruleParser.ParseCondition(this.conditionTextBox.Text);

                if (!string.IsNullOrEmpty(this.conditionTextBox.Text))
                    this.conditionTextBox.Text = this.ruleExpressionCondition.ToString().Replace("\n", "\r\n");
                conditionErrorProvider.SetError(this.conditionTextBox, string.Empty);
                syntaxException = null;
            }
            catch (Exception ex)
            {
                syntaxException = ex;
                conditionErrorProvider.SetError(this.conditionTextBox, ex.Message);
            }
        }
        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);
        }
Exemplo n.º 27
0
        protected override void OnDeleteInternal(object ruleObject)
        {
            RuleExpressionCondition condition = ruleObject as RuleExpressionCondition;

            this.declarativeConditionCollection.Remove(condition.Name);
        }
Exemplo n.º 28
0
        protected override string GetObjectName(object ruleObject)
        {
            RuleExpressionCondition condition = ruleObject as RuleExpressionCondition;

            return(condition.Name);
        }