예제 #1
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);
        }
        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);
        }
예제 #3
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));
                }
            }
        }
예제 #4
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 ConditionBrowserDialog(Activity activity, string name)
            : base(activity, name)
        {
            RuleDefinitions rules = ConditionHelper.Load_Rules_DT(activity.Site, Helpers.GetRootActivity(activity));
            if (rules != null)
                this.declarativeConditionCollection = rules.Conditions;

            InitializeListView(this.declarativeConditionCollection, name);
        }
예제 #6
0
        public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            object obj2 = o;
            RuleConditionReference instance = typeDescriptorContext.Instance as RuleConditionReference;

            if (((instance == null) || (instance.ConditionName == null)) || (instance.ConditionName.Length <= 0))
            {
                throw new ArgumentException(Messages.ConditionNameNotSet);
            }
            Activity          component = null;
            IReferenceService service   = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;

            if (service != null)
            {
                component = service.GetComponent(typeDescriptorContext.Instance) as Activity;
            }
            RuleConditionCollection conditions  = null;
            RuleDefinitions         definitions = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(component));

            if (definitions != null)
            {
                conditions = definitions.Conditions;
            }
            if ((conditions != null) && !conditions.Contains(instance.ConditionName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, new object[] { instance.ConditionName }));
            }
            this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
            if (this.editorService != null)
            {
                CodeExpression expression = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as CodeExpression;
                try
                {
                    using (RuleConditionDialog dialog = new RuleConditionDialog(component, expression))
                    {
                        if (DialogResult.OK == this.editorService.ShowDialog(dialog))
                        {
                            obj2 = dialog.Expression;
                        }
                    }
                }
                catch (NotSupportedException)
                {
                    DesignerHelpers.DisplayError(Messages.Error_ExpressionNotSupported, Messages.ConditionEditor, serviceProvider);
                }
            }
            return(obj2);
        }
예제 #7
0
        public ConditionBrowserDialog(Activity activity, string name) : base(activity, name)
        {
            RuleDefinitions definitions = ConditionHelper.Load_Rules_DT(activity.Site, Helpers.GetRootActivity(activity));

            if (definitions != null)
            {
                this.declarativeConditionCollection = definitions.Conditions;
            }
            base.InitializeListView(this.declarativeConditionCollection, name);
        }
        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);
            }
        }
예제 #9
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);
            }
        }
        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));
                }
            }
        }
예제 #11
0
        public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            object returnVal = o;

            // Do not allow editing expression if the name is not set.
            RuleConditionReference conditionDeclaration = typeDescriptorContext.Instance as RuleConditionReference;

            if (conditionDeclaration == null || conditionDeclaration.ConditionName == null || conditionDeclaration.ConditionName.Length <= 0)
            {
                throw new ArgumentException(Messages.ConditionNameNotSet);
            }

            Activity baseActivity = null;

            IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;

            if (rs != null)
            {
                baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
            }

            RuleConditionCollection conditionDefinitions = null;
            RuleDefinitions         rules = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(baseActivity));

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

            if (conditionDefinitions != null && !conditionDefinitions.Contains(conditionDeclaration.ConditionName))
            {
                string message = string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, conditionDeclaration.ConditionName);
                throw new ArgumentException(message);
            }

            this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
            if (editorService != null)
            {
                CodeExpression experssion = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as CodeExpression;
                try
                {
                    using (RuleConditionDialog dlg = new RuleConditionDialog(baseActivity, experssion))
                    {
                        if (DialogResult.OK == editorService.ShowDialog(dlg))
                        {
                            returnVal = dlg.Expression;
                        }
                    }
                }
                catch (NotSupportedException)
                {
                    DesignerHelpers.DisplayError(Messages.Error_ExpressionNotSupported, Messages.ConditionEditor, serviceProvider);
                }
            }

            return(returnVal);
        }
예제 #12
0
		public RuleDefinitions ()
		{
			conditions = new RuleConditionCollection ();
			rulesets = new RuleSetCollection ();
		}