예제 #1
0
파일: Builder.cs 프로젝트: mchnry/flow
        private void  Do(Action <IActionBuilder <T> > builder, Func <WorkDefine.ActionDefinition> overrideName = null)
        {
            ActionBuilder <T> builderRef = new ActionBuilder <T>(this);

            builder.Invoke(builderRef);

            WorkDefine.ActionRef        ToDo      = builderRef.actionRef;
            WorkDefine.ActionDefinition actionDef = new ActionDefinition();

            if (overrideName != null)
            {
                actionDef    = overrideName();
                actionDef.Id = ConventionHelper.EnsureConvention(NamePrefixOptions.Action, actionDef.Id, this.config.Convention);
                ToDo         = actionDef.Id;
            }
            else
            {
                ToDo.Id = ConventionHelper.EnsureConvention(NamePrefixOptions.Action, ToDo.Id, this.config.Convention);

                string actionName  = builderRef.action.GetType().Name;
                string description = ConventionHelper.ParseMethodName(actionName, this.config.Convention.ParseMethodNamesAs).Literal;

                var descAttr = builderRef.action.GetType().GetCustomAttributes(typeof(ArticulateOptionsAttribute), true)
                               .OfType <ArticulateOptionsAttribute>()
                               .FirstOrDefault();
                if (descAttr != null)
                {
                    description = descAttr.Description;
                }
                actionDef = new WorkDefine.ActionDefinition()
                {
                    Id = ToDo.Id, Description = description
                };
            }


            this.workflowManager.AddAction(actionDef);

            if (!this.actions.ContainsKey(ToDo.Id))
            {
                this.actions.Add(ToDo.Id, builderRef.action);
            }
            else
            {
                //if attmpeting to add another implementation with the same id, throw an exception
                //we can't handle this
                if ((this.actions[ToDo.Id].GetType()) != builderRef.action.GetType())
                {
                    throw new BuilderException(ToDo.Id);
                }
            }

            this.created = ToDo;
        }
예제 #2
0
파일: Builder.cs 프로젝트: mchnry/flow
        void IFluentExpressionBuilder <T> .Rule(Action <IRuleBuilder <T> > action)
        {
            RuleBuilder <T> builderRef = new RuleBuilder <T>(this);

            action.Invoke(builderRef);

            LogicDefine.Rule evaluatorId = builderRef.rule;



            evaluatorId.Id = ConventionHelper.EnsureConvention(NamePrefixOptions.Evaluator, evaluatorId.Id, this.config.Convention);

            string actionName  = builderRef.evaluatorx.GetType().Name;
            string description = ConventionHelper.ParseMethodName(actionName, this.config.Convention.ParseMethodNamesAs).Literal;

            var descAttr = builderRef.evaluatorx.GetType().GetCustomAttributes(typeof(ArticulateOptionsAttribute), true)
                           .OfType <ArticulateOptionsAttribute>()
                           .FirstOrDefault();

            if (descAttr != null)
            {
                description = descAttr.Description;
            }

            this.workflowManager.AddEvaluator(new LogicDefine.Evaluator()
            {
                Id = evaluatorId.Id, Description = description
            });
            bool isRoot = this.epxressionStack.Count == 0;

            if (!this.evaluators.ContainsKey(evaluatorId.Id))
            {
                this.evaluators.Add(evaluatorId.Id, builderRef.evaluatorx);
            }                //if attmpeting to add another implementation with the same id, throw an exception
                             //we can't handle this
            else if (this.evaluators[evaluatorId.Id].GetType() != builderRef.evaluatorx.GetType())
            {
                throw new BuilderException(evaluatorId.Id);
            }

            if (isRoot)
            {
                string equationId = ConventionHelper.ChangePrefix(NamePrefixOptions.Evaluator, NamePrefixOptions.Equation, evaluatorId.Id, this.config.Convention);
                bool   trueCond   = true;;
                if (!evaluatorId.TrueCondition)
                {
                    equationId = ConventionHelper.NegateEquationName(equationId, this.config.Convention);
                    trueCond   = false;
                }
                LogicDefine.Equation toAdd = new LogicDefine.Equation()
                {
                    Condition = Logic.Operand.And,
                    First     = evaluatorId,
                    Id        = equationId,
                    Second    = ConventionHelper.TrueEvaluator(this.config.Convention),
                    //TrueCondition = trueCond
                };
                this.epxressionStack.Push(toAdd);

                this.workflowManager.AddEquation(toAdd);
            }
            else
            {
                this.epxressionStack.Push(evaluatorId);
            }
            //if root... then create euqations
            //otherwise, just use as evaluator
        }