public IContainerStepBuilder <TData, Schedule, TStepBody> Schedule(Expression <Func <TData, TimeSpan> > time)
        {
            var newStep = new WorkflowStep <Schedule>();
            Expression <Func <Schedule, TimeSpan> > inputExpr = (x => x.Interval);

            newStep.Inputs.Add(new MemberMapParameter(time, inputExpr));

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new ReturnStepBuilder <TData, Schedule, TStepBody>(WorkflowBuilder, newStep, this);

            Step.Outcomes.Add(new ValueOutcome {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
        public IStepBuilder <TData, TStepBody> Branch <TStep>(Expression <Func <TData, object, bool> > outcomeExpression, IStepBuilder <TData, TStep> branch) where TStep : IStepBody
        {
            if (branch.WorkflowBuilder.Steps.Count == 0)
            {
                return(this);
            }

            WorkflowBuilder.AttachBranch(branch.WorkflowBuilder);

            Step.Outcomes.Add(new ExpressionOutcome <TData>(outcomeExpression)
            {
                NextStep = branch.WorkflowBuilder.Steps[0].Id
            });

            return(this);
        }
        public IStepBuilder <TData, Sequence> Saga(Action <IWorkflowBuilder <TData> > builder)
        {
            var newStep = new SagaContainer <Sequence>();

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, Sequence>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new StepOutcome()
            {
                NextStep = newStep.Id
            });
            builder.Invoke(WorkflowBuilder);
            stepBuilder.Step.Children.Add(stepBuilder.Step.Id + 1); //TODO: make more elegant

            return(stepBuilder);
        }
        public IStepBuilder <TData, InlineStepBody> Then(Func <IStepExecutionContext, ExecutionResult> body)
        {
            WorkflowStepInline newStep = new WorkflowStepInline
            {
                Body = body
            };

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, InlineStepBody>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new StepOutcome()
            {
                NextStep = newStep.Id
            });
            return(stepBuilder);
        }
        public IStepBuilder <TData, Decide> Decide(Expression <Func <TData, object> > expression)
        {
            var newStep = new WorkflowStep <Decide>();

            Expression <Func <Decide, object> > inputExpr = (x => x.Expression);

            newStep.Inputs.Add(new MemberMapParameter(expression, inputExpr));

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, Decide>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new ValueOutcome {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
        public IStepBuilder <TData, Delay> Delay(Expression <Func <TData, TimeSpan> > period)
        {
            var newStep = new WorkflowStep <Delay>();

            Expression <Func <Delay, TimeSpan> > inputExpr = (x => x.Period);

            newStep.Inputs.Add(new MemberMapParameter(period, inputExpr));

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, Delay>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new ValueOutcome {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
        public IContainerStepBuilder <TData, Foreach, Foreach> ForEach(Expression <Func <TData, IEnumerable> > collection)
        {
            var newStep = new WorkflowStep <Foreach>();

            Expression <Func <Foreach, IEnumerable> > inputExpr = (x => x.Collection);

            newStep.Inputs.Add(new MemberMapParameter(collection, inputExpr));

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, Foreach>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new ValueOutcome {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
Exemple #8
0
        public IStepBuilder <TData, TStepBody> CompensateWith <TStep>(Action <IStepBuilder <TData, TStep> > stepSetup = null) where TStep : IStepBody
        {
            WorkflowStep <TStep> newStep = new WorkflowStep <TStep>();

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, TStep>(WorkflowBuilder, newStep);

            if (stepSetup != null)
            {
                stepSetup.Invoke(stepBuilder);
            }

            newStep.Name            = newStep.Name ?? typeof(TStep).Name;
            Step.CompensationStepId = newStep.Id;

            return(this);
        }
        public IContainerStepBuilder <TData, If, If> If(Expression <Func <TData, bool> > condition)
        {
            var newStep = new WorkflowStep <If>();

            Expression <Func <If, bool> > inputExpr = (x => x.Condition);

            newStep.Inputs.Add(new MemberMapParameter(condition, inputExpr));

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, If>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new ValueOutcome {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
Exemple #10
0
        public IStepBuilder <TData, TStep> Then <TStep>(Action <IStepBuilder <TData, TStep> > stepSetup = null)
            where TStep : IStepBody
        {
            WorkflowStep <TStep> step = new WorkflowStep <TStep>();

            WorkflowBuilder.AddStep(step);
            var stepBuilder = new StepBuilder <TData, TStep>(WorkflowBuilder, step);

            if (stepSetup != null)
            {
                stepSetup.Invoke(stepBuilder);
            }

            step.Name        = step.Name ?? typeof(TStep).Name;
            Outcome.NextStep = step.Id;

            return(stepBuilder);
        }
Exemple #11
0
        public IStepBuilder <TData, TStepBody> Branch <TStep>(object outcomeValue, IStepBuilder <TData, TStep> branch) where TStep : IStepBody
        {
            if (branch.WorkflowBuilder.Steps.Count == 0)
            {
                return(this);
            }

            WorkflowBuilder.AttachBranch(branch.WorkflowBuilder);
            Expression <Func <object, object> > expr = x => outcomeValue;

            Step.Outcomes.Add(new ValueOutcome
            {
                Value    = expr,
                NextStep = branch.WorkflowBuilder.Steps[0].Id
            });

            return(this);
        }
        public IStepBuilder <TData, TStep> Then <TStep>(Action <IStepBuilder <TData, TStep> > stepSetup = null)
            where TStep : IStepBody
        {
            WorkflowStep <TStep> newStep = new WorkflowStep <TStep>();

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, TStep>(WorkflowBuilder, newStep);

            if (stepSetup != null)
            {
                stepSetup.Invoke(stepBuilder);
            }

            newStep.Name = newStep.Name ?? typeof(TStep).Name;
            Step.Outcomes.Add(new ValueOutcome {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
        public IContainerStepBuilder <TData, Recur, TStepBody> Recur(Expression <Func <TData, TimeSpan> > interval, Expression <Func <TData, bool> > until)
        {
            var newStep = new WorkflowStep <Recur>();

            newStep.CancelCondition = until;

            Expression <Func <Recur, TimeSpan> > intervalExpr = (x => x.Interval);
            Expression <Func <Recur, bool> >     untilExpr    = (x => x.StopCondition);

            newStep.Inputs.Add(new MemberMapParameter(interval, intervalExpr));
            newStep.Inputs.Add(new MemberMapParameter(until, untilExpr));

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new ReturnStepBuilder <TData, Recur, TStepBody>(WorkflowBuilder, newStep, this);

            Step.Outcomes.Add(new ValueOutcome {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
Exemple #14
0
        public IStepBuilder <TData, WaitFor> WaitFor(string eventName, Expression <Func <TData, IStepExecutionContext, string> > eventKey, Expression <Func <TData, DateTime> > effectiveDate = null)
        {
            var newStep = new WorkflowStep <WaitFor>();

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, WaitFor>(WorkflowBuilder, newStep);

            stepBuilder.Input((step) => step.EventName, (data) => eventName);
            stepBuilder.Input((step) => step.EventKey, eventKey);

            if (effectiveDate != null)
            {
                stepBuilder.Input((step) => step.EffectiveDate, effectiveDate);
            }

            Step.Outcomes.Add(new StepOutcome()
            {
                NextStep = newStep.Id
            });
            return(stepBuilder);
        }
        public IStepBuilder <TData, WaitFor> WaitFor(string eventName, Expression <Func <TData, string> > eventKey, Expression <Func <TData, DateTime> > effectiveDate = null, Expression <Func <TData, bool> > cancelCondition = null)
        {
            var newStep = new WorkflowStep <WaitFor>();

            newStep.CancelCondition = cancelCondition;

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, WaitFor>(WorkflowBuilder, newStep);

            stepBuilder.Input((step) => step.EventName, (data) => eventName);
            stepBuilder.Input((step) => step.EventKey, eventKey);

            if (effectiveDate != null)
            {
                stepBuilder.Input((step) => step.EffectiveDate, effectiveDate);
            }

            Step.Outcomes.Add(new ValueOutcome {
                NextStep = newStep.Id
            });
            return(stepBuilder);
        }
Exemple #16
0
        private WorkflowStep IterateParents(int id, string name)
        {
            //todo: filter out circular paths
            var upstream = WorkflowBuilder.GetUpstreamSteps(id);

            foreach (var parent in upstream)
            {
                if (parent.Name == name)
                {
                    return(parent);
                }
            }

            foreach (var parent in upstream)
            {
                var result = IterateParents(parent.Id, name);
                if (result != null)
                {
                    return(result);
                }
            }
            return(null);
        }
Exemple #17
0
        public IContainerStepBuilder <TData, Schedule, TStepBody> Schedule(Expression <Func <TData, TimeSpan> > time)
        {
            var newStep = new WorkflowStep <Schedule>();
            Expression <Func <Schedule, TimeSpan> > inputExpr = (x => x.Interval);

            var mapping = new DataMapping()
            {
                Source = time,
                Target = inputExpr
            };

            newStep.Inputs.Add(mapping);

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new ReturnStepBuilder <TData, Schedule, TStepBody>(WorkflowBuilder, newStep, this);

            Step.Outcomes.Add(new StepOutcome()
            {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
Exemple #18
0
        public IContainerStepBuilder <TData, When, OutcomeSwitch> When(Expression <Func <TData, object> > outcomeValue, string label = null)
        {
            var newStep = new WorkflowStep <When>();
            Expression <Func <When, object> > inputExpr = (x => x.ExpectedOutcome);
            var mapping = new DataMapping()
            {
                Source = outcomeValue,
                Target = inputExpr
            };

            newStep.Inputs.Add(mapping);

            IStepBuilder <TData, OutcomeSwitch> switchBuilder;

            if (Step.BodyType != typeof(OutcomeSwitch))
            {
                var switchStep = new WorkflowStep <OutcomeSwitch>();
                WorkflowBuilder.AddStep(switchStep);
                Step.Outcomes.Add(new StepOutcome()
                {
                    NextStep = switchStep.Id,
                    Label    = label
                });
                switchBuilder = new StepBuilder <TData, OutcomeSwitch>(WorkflowBuilder, switchStep);
            }
            else
            {
                switchBuilder = (this as IStepBuilder <TData, OutcomeSwitch>);
            }

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new SkipStepBuilder <TData, When, OutcomeSwitch>(WorkflowBuilder, newStep, switchBuilder);

            switchBuilder.Step.Children.Add(newStep.Id);

            return(stepBuilder);
        }
Exemple #19
0
        public IContainerStepBuilder <TData, If, If> If(Expression <Func <TData, bool> > condition)
        {
            var newStep = new WorkflowStep <If>();

            Expression <Func <If, bool> > inputExpr = (x => x.ConditionResult);

            var mapping = new DataMapping()
            {
                Source = condition,
                Target = inputExpr
            };

            newStep.Inputs.Add(mapping);

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, If>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new StepOutcome()
            {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
Exemple #20
0
        public IContainerStepBuilder <TData, Foreach, Foreach> ForEach(Expression <Func <TData, IEnumerable> > collection)
        {
            var newStep = new WorkflowStep <Foreach>();

            Expression <Func <Foreach, IEnumerable> > inputExpr = (x => x.Collection);

            var mapping = new DataMapping()
            {
                Source = collection,
                Target = inputExpr
            };

            newStep.Inputs.Add(mapping);

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, Foreach>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new StepOutcome()
            {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
Exemple #21
0
        public IStepBuilder <TData, Delay> Delay(Expression <Func <TData, TimeSpan> > period)
        {
            var newStep = new WorkflowStep <Delay>();

            Expression <Func <Delay, TimeSpan> > inputExpr = (x => x.Period);

            var mapping = new DataMapping()
            {
                Source = period,
                Target = inputExpr
            };

            newStep.Inputs.Add(mapping);

            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, Delay>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new StepOutcome()
            {
                NextStep = newStep.Id
            });

            return(stepBuilder);
        }
Exemple #22
0
        public IWorkflowBuilder <T> UseData <T>()
        {
            IWorkflowBuilder <T> result = new WorkflowBuilder <T>(Steps);

            return(result);
        }