示例#1
0
        public virtual bool CheckParameters(WorkFlowContext context, Condition cond, IList <ValidationResult> results = null)
        {
            var conditions = cond.Parameters.ToDictionary(x => x.Key, y => y.Value);
            //first verifying if parameters keys supply all conditions keys
            bool keysmatch = (context.Count >= conditions.Keys.Count) &&
                             (context.Keys.Intersect(conditions.Keys).Count() == conditions.Keys.Count);

            if (!keysmatch)
            {
                return(false);
            }

            foreach (var parameter in cond.Parameters)
            {
                if (!evaluator.Execute(parameter, context))
                {
                    if (results == null)
                    {
                        return(false);
                    }
                    results.Add(new ValidationResult(cond, parameter));
                }
            }

            if (results == null)
            {
                return(true);
            }

            return(!results.Any());
        }
示例#2
0
        public void SameOriginForDifferentConditions()
        {
            WorkFlowContext context = work.GetContext();

            context.AddElements("EMITTED", "AreaPURCHASEASK");
            context["Objective"] = new List <string> {
                "4"
            };                                              //deposito
            context["Departament"] = new List <string> {
                "1"
            };
            IList <Activity> lista = work.GetActivities(context);

            Assert.IsTrue(lista.Count == 2 && lista.Any(x => x.Operation.Equals("INICIO_ANALYSIS_EXPORTATION")));
            /*testing another condition*/

            WorkFlowContext context2 = work.GetContext();

            context2.AddElements("EMITTED", "AreaPURCHASEASK");
            context2["Objective"] = new List <string> {
                "2"
            };                                               //deposito
            context2["Departament"] = new List <string> {
                "1"
            };
            IList <Activity> atividades = work.GetActivities(context2);

            Assert.IsTrue(atividades.Count == 2 && atividades.Any(x => x.Operation.Equals("TakePURCHASEASK")));
        }
        public ActionResult Index(string Command,string Step)
        {
            host = new WizardHost(new Workflow1(), bookmarkhistory);

            Dictionary<string, object> input = new Dictionary<string, object>();
             IDictionary<string, object> output=new Dictionary<string,object>();
            input["Context"] = workflowcontext;
            switch (Command)
            {
                case "Start":
                    output=host.Start(input);
                    break;
                case "Next":
               output=host.Next(input);
                    break;
                case "Back":
               output=host.Back(input);
                    break;
                case "GoTo":
                    output = host.GoTo(input,Step);
                    break;
                default:
                    output = host.Start(input);
                    break;
            }
            bookmarkhistory = host.GetBookmarkHistory();
            workflowcontext = output["Context"] as WorkFlowContext;
            ViewData = workflowcontext.ViewData;
            ViewData["bookmarkhistory"] = bookmarkhistory;
            ViewData["currentbookmark"] = host.GetCurrentBookmark();
            ViewData["PartialViewName"] = workflowcontext.ViewName;
            return View();
        }
示例#4
0
        public override object Run(WorkFlowContext context, SearchMode mode, WorkFlow.Visitors.IVisitor visitor = null)
        {
            if (visitor == null)
            {
                visitor = new DefaultVisitor();
            }

            Queue <string> fila = new Queue <string>();
            List <string>  mark = new List <string>();

            fila.Enqueue(context.SourceState);
            mark.Add(context.SourceState);

            while (fila.Count != 0)
            {
                string statusfila = fila.Dequeue();
                context.SourceState = statusfila;
                foreach (var item in this.GetActivities(context).OrderBy(x => x.Operation))
                {
                    context.Operation = item.Operation;
                    string newstatus = this.GetNextStatus(context);
                    visitor.Visit(statusfila, new Activity {
                        Operation = item.Operation, Description = item.Description
                    }, newstatus);

                    if (!mark.Contains(newstatus))
                    {
                        fila.Enqueue(newstatus);
                        mark.Add(newstatus);
                    }
                }
            }

            return(visitor.EndVisit());
        }
示例#5
0
        /// <summary>
        /// Update a task.
        /// </summary>
        /// <param name="taskToUpdate"></param>
        /// <returns></returns>
        public async Task <int> Update(int taskId, TaskDto taskToUpdate)
        {
            try
            {
                using (var context = new WorkFlowContext())
                {
                    Entities.Task taskToUpdateFromDb = await context.Task.FindAsync(taskId);

                    if (taskToUpdateFromDb != null)
                    {
                        taskToUpdateFromDb.Description          = taskToUpdate.Description;
                        taskToUpdateFromDb.Assignee             = taskToUpdate.Assignee;
                        taskToUpdateFromDb.AssignedBy           = taskToUpdate.AssignedBy;
                        taskToUpdateFromDb.Status               = taskToUpdate.Status;
                        taskToUpdateFromDb.AgreedCompletionDate = taskToUpdate.AgreedCompletionDate;

                        return(await context.SaveChangesAsync());
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#6
0
        private void RunInDepth(WorkFlowContext context, IVisitor visitor)
        {
            if (string.IsNullOrEmpty(context.SourceState))
            {
                return;
            }
            else
            {
                foreach (var item in this.GetActivities(context).OrderBy(x => x.Operation))
                {
                    context.Operation = item.Operation;
                    string newstatus  = this.GetNextStatus(context);
                    string laststate  = context.SourceState;
                    string transition = string.Format("{0},{1},{2}", context.SourceState, item.Description, newstatus);

                    if (NotPresent(transition))
                    {
                        visitor.Visit(context.SourceState, new Activity {
                            Operation = item.Operation, Description = item.Description
                        }, newstatus);
                        context.SourceState = newstatus;
                        RunInDepth(context, visitor);
                        context.SourceState = laststate;
                    }
                }
            }
        }
示例#7
0
        public override void Execute()
        {
            if (WorkFlowContext.Canceled)
            {
                throw new WorkflowCanceledException();
            }

            _branch(this);

            do
            {
                if (WorkFlowContext.Canceled)
                {
                    throw new WorkflowCanceledException();
                }

                WorkFlowContext.RemoveInstructions(this);

                foreach (var step in Nodes)
                {
                    step.Execute();

                    if (WorkFlowContext.HasInstruction <BreakInstruction>(this))
                    {
                        break;
                    }
                }
            } while(WorkFlowContext.HasInstruction <RestartInstruction>(this));

            WorkFlowContext.RemoveInstructions(this);
        }
示例#8
0
        public static List <UI_WFEntity_Info> GetWFEntityByHistoryDone(System.Linq.Expressions.Expression <Func <Mission, bool> > condition)
        {
            List <UI_WFEntity_Info> wfe_info = new List <UI_WFEntity_Info>();

            WorkFlows wfs = new WorkFlows();

            List <WorkFlow_Entity> wfes = null;

            //List<WorkFlow_Entity> wfes = wfs.GetWFEntityByConditon(s => s.Process_Info.wh );
            try
            {
                using (var db = new WorkFlowContext())
                {
                    wfes = db.mission.Where(condition).Select(a => a.Miss_WFentity).Distinct().Where(s => s.WE_Status == WE_STATUS.DONE).ToList();
                }
            }
            catch (Exception e)
            {
                return(null);
            }

            foreach (WorkFlow_Entity fe in wfes)
            {
                UI_WFEntity_Info fe_info = new UI_WFEntity_Info();
                fe_info.name        = wfs.GetWorkFlowEntityName(fe.WE_Id);
                fe_info.Status      = fe.WE_Status;
                fe_info.EntityID    = fe.WE_Id;
                fe_info.description = wfs.GetWorkFlowEntityDesc(fe.WE_Id);
                fe_info.serial      = fe.WE_Ser;
                wfe_info.Add(fe_info);
            }
            return(wfe_info);
        }
示例#9
0
        public void ConditionWithDifferentOperatorsWithCustomEvaluator()
        {
            IWorkFlow workteste = WorkFlowManager.GetManager();

            WorkFlowContext context = workteste.GetContext()
                                      .AddEvaluator(new CustomEvaluator())
                                      .SetArea("TESTCONDITIONSICK")
                                      .SetSourceState("INITIAL");


            context["TESTCONDITIONEQUAL"] = new List <string> {
                "COLD"
            };
            context["TESTCONDITIONLT"] = new List <string> {
                "4"
            };
            context["CUSTOM"] = new List <string> {
                "http://"
            };
            context["TESTCONDITIONIN"] = new List <string> {
                "5", "8"
            };


            var activities = workteste.GetActivities(context);

            Assert.AreEqual(2, activities.Count);
        }
示例#10
0
        /// <summary>
        /// Retrieve a task if taskId is specified. If taskId is null then retrieve all the tasks.
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public async Task <IEnumerable <TaskDto> > Retrieve(int?taskId)
        {
            try
            {
                using (var context = new WorkFlowContext())
                {
                    IEnumerable <Entities.Task> taskEntities = taskId.HasValue
                        ? await context.Task.Where(t => t.TaskId == taskId && t.IsDeleted == false).ToListAsync()
                        : await context.Task.Where(t => t.IsDeleted == false).ToListAsync();

                    if (taskEntities.Count() > 0)
                    {
                        IEnumerable <TaskDto> taskDtos = Mapper.Map <IEnumerable <TaskDto> >(taskEntities);
                        return(taskDtos);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#11
0
        private void RunInWidth(WorkFlowContext context, IVisitor visitor)
        {
            Queue <string> fila = new Queue <string>();
            List <string>  mark = new List <string>();

            fila.Enqueue(context.SourceState);
            mark.Add(context.SourceState);

            while (fila.Count != 0)
            {
                string statusfila = fila.Dequeue();
                context.SourceState = statusfila;
                foreach (var item in this.GetActivities(context).OrderBy(x => x.Operation))
                {
                    context.Operation = item.Operation;
                    string newstatus = this.GetNextStatus(context);
                    visitor.Visit(statusfila, new Activity {
                        Operation = item.Operation, Description = item.Description
                    }, newstatus);

                    if (!mark.Contains(newstatus))
                    {
                        fila.Enqueue(newstatus);
                        mark.Add(newstatus);
                    }
                }
            }
        }
示例#12
0
        public void GetAtivities()
        {
            WorkFlowContext context = work.GetContext().SetArea("AreaPURCHASEASK")
                                      .SetSourceState("ATDRAFT");
            IList <Activity> act = work.GetActivities(context);

            Assert.AreEqual(2, act.Count);
        }
示例#13
0
        public void GetNextStatus()
        {
            WorkFlowContext context = work.GetContext().SetArea("AreaPURCHASEASK")
                                      .SetOperation("AskAprovePURCHASEASK")
                                      .SetSourceState("ATDRAFT");
            string status = work.GetNextStatus(context);

            Assert.AreEqual("WAITINGALLOW", status);
        }
示例#14
0
        public void GetDestinyWithNoOrigin()
        {
            WorkFlowContext context = work.GetContext().Reset().SetArea("Automatic")
                                      .SetOperation("LAST_ITEM_CANCELLED_PURCHASEASK");

            string destiny = work.GetNextStatus(context);

            Assert.AreEqual("CANCELLEDPURCHASEASK", destiny);
        }
示例#15
0
        public override void Execute()
        {
            var current = Parent;

            while (current != null)
            {
                WorkFlowContext.AddInstruction(current, new BreakInstruction());
                current = current.Parent;
            }
        }
示例#16
0
        public override void Execute()
        {
            var current = Parent;

            for (int i = 0; i < _levels && current != null; i++)
            {
                WorkFlowContext.AddInstruction(current, new BreakInstruction());
                current = current.Parent;
            }
        }
示例#17
0
        public void ExecuteCommand()
        {
            IWorkFlow workteste = WorkFlowManager.GetManager();

            WorkFlowContext context = workteste
                                      .GetContext()
                                      .AddElements("ATDRAFT", "AreaPURCHASEASK")
                                      .SetCommand(typeof(DefaultWorkFlowCommand))
                                      .Execute();
        }
示例#18
0
        public bool Execute(Evaluate item, WorkFlowContext context)
        {
            bool result = false;

            string[] operators = new string[] { "lt", "le", "gt", "ge" };

            if (operators.Any(x => x == item.Operator))
            {
                decimal valuejson, valuecontext;
                if (decimal.TryParse(item.Value.FirstOrDefault(), out valuejson) &&
                    decimal.TryParse(context[item.Key].FirstOrDefault(), out valuecontext))
                {
                    switch (item.Operator)
                    {
                    case "lt":
                        if (valuecontext < valuejson)
                        {
                            return(true);
                        }
                        break;

                    case "le":
                        if (valuecontext <= valuejson)
                        {
                            return(true);
                        }
                        break;

                    case "gt":
                        if (valuecontext > valuejson)
                        {
                            return(true);
                        }
                        break;

                    case "ge":
                        if (valuecontext >= valuejson)
                        {
                            return(true);
                        }
                        break;
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                result = Successor.Execute(item, context);
            }

            return(result);
        }
示例#19
0
        private TReturn ExecuteStep(IStep <TState, TReturn> step)
        {
            var result = WorkFlowContext.Lock(() => WorkFlowContext.Path.AddLast(step));

            if (!result)
            {
                return(default(TReturn));
            }

            return(step.Execute(WorkFlowContext.State));
        }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            //pupolate the model and context
            workflowcontext = (TempData["context"] ?? new WorkFlowContext()) as WorkFlowContext;

            TryUpdateModel(workflowcontext);

            bookmarkhistory = (TempData["bookmarkhistory"] ?? new List<CustomBookmark>()) as List<CustomBookmark>;
        }
示例#21
0
        public void CheckConditionsKeyAndAtLeastOneValueMatch()
        {
            WorkFlowContext context = work.GetContext();

            context["Objective"] = new List <string> {
                "3"
            };                                              //destruction
            context["Departament"] = new List <string> {
                "1"
            };
            Assert.IsTrue(context.Match.CheckConditions("DESTRUCTION", context));
        }
示例#22
0
        public void CheckConditionsKeyMatchButValueDoesnt()
        {
            WorkFlowContext context = work.GetContext();

            context["Objective"] = new List <string> {
                "2"
            };                                              //deposito
            context["Departament"] = new List <string> {
                "1"
            };
            Assert.IsFalse(context.Match.CheckConditions("EXTINTION", context));
        }
示例#23
0
        public virtual IList <Activity> GetActivities(WorkFlowContext context, IControlAccess access = null)
        {
            var atividades = from w in GetNode().WorkFlow
                             from i in w.Transitions
                             where w.Area.Equals(context.Area) &&
                             (w.SourceState.Equals(context.SourceState) || context.Match.CheckExcludeAtivity(context.SourceState, w, i)) &&
                             context.Match.CheckConditions(i.Condition, context)
                             select new Activity {
                Operation = i.Operation, Description = i.Description
            };

            return((access != null) ? access.checkAccessActivity(atividades.ToList()) : atividades.ToList());
        }
示例#24
0
        public override void Execute()
        {
            var containerNode = Parent;
            var branchNode    = containerNode.Parent;

            WorkFlowContext.AddInstruction(containerNode, new BreakInstruction());
            WorkFlowContext.AddInstruction(branchNode, new BreakInstruction());

            if (_retries++ < _maxRetries)
            {
                WorkFlowContext.AddInstruction(branchNode, new RetryInstruction());
            }
        }
示例#25
0
        public virtual bool CheckParameters(WorkFlowContext context, Condition cond)
        {
            var conditions = cond.Parameters.ToDictionary(x => x.Key, y => y.Value);
            //first verifying if parameters keys supply all conditions keys
            bool keysmatch = (context.Count >= conditions.Keys.Count) &&
                             (context.Keys.Intersect(conditions.Keys).Count() == conditions.Keys.Count);
            //verifying if parameter values are in condition values
            int numbervaluesmatches = context.Keys
                                      .Where(k => conditions.ContainsKey(k) && conditions[k].Intersect(context[k]).Count() == context[k].Count)
                                      .Count();

            return(keysmatch && (numbervaluesmatches == conditions.Count));
        }
示例#26
0
        public void PrintRunnerStrategy()
        {
            IWorkFlow workteste = WorkFlowManager.GetManager(typeof(RunnerCustom));

            WorkFlowContext context = workteste
                                      .GetContext()
                                      .AddElements("ATDRAFT", "AreaPURCHASEASK");

            var    lista      = (List <string>)workteste.Run(context, SearchMode.Breadth, new ListVisitor());
            string transicoes = string.Join(",", lista.ToArray());

            Assert.AreEqual("ATDRAFT--[Ask Aproving]-->WAITINGALLOW ,ATDRAFT--[Erase Draft]-->None ,WAITINGALLOW--[Emit PURCHASEASK]-->EMITTED ,WAITINGALLOW--[Não Aprove PURCHASEASK]-->ATREVISION ,WAITINGALLOW--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,EMITTED--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,EMITTED--[Take PURCHASEASK]-->ATANALYSIS ,ATREVISION--[Ask Aproving]-->WAITINGALLOW ,ATREVISION--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,CANCELASKEDPURCHASEASK--[Recusar Cancelling]-->None ,ATANALYSIS--[Associate PURCHASEORDER]-->PURCHASEORDERCREATED ,ATANALYSIS--[Correct PURCHASEASK]-->ATREVISION ,ATANALYSIS--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,PURCHASEORDERCREATED--[Encerrando PURCHASEASK]-->PROCESSFINISHED ,PURCHASEORDERCREATED--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ", transicoes);
        }
示例#27
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            //pupolate the model and context
            workflowcontext = (TempData["context"] ?? new WorkFlowContext()) as WorkFlowContext;

            TryUpdateModel(workflowcontext);



            bookmarkhistory = (TempData["bookmarkhistory"] ?? new List <CustomBookmark>()) as List <CustomBookmark>;
        }
示例#28
0
        public IList <ValidationResult> ValidateNextStatus(WorkFlowContext context)
        {
            var results = new List <ValidationResult>();
            var nodes   = GetNode().WorkFlow.Where(x => x.Area == context.Area);

            var retorno = (from w in nodes
                           from i in w.Transitions
                           where context.Match.IsOriginStateNotNeeded(w, context.SourceState) &&
                           i.Operation.Equals(context.Operation) &&
                           context.Match.CheckConditions(i.Condition, context, results)
                           select i.DestinyState).ToList();

            return(results);
        }
示例#29
0
        public void ConditionAndStatusAllTogetherWithStatusInBut()
        {
            WorkFlowContext context = work.GetContext().AddElements("WAITMOVEMENT", "PURCHASEORDEROperation");

            context["Objective"] = new List <string> {
                "2"
            };                                              //deposito
            context["Departament"] = new List <string> {
                "1"
            };
            IList <Activity> lista = work.GetActivities(context);

            Assert.AreEqual(0, lista.Count);
        }
示例#30
0
        public void ConditionMatchAndStatusAllTogetherStatusNotInBut()
        {
            WorkFlowContext context = work.GetContext().AddElements("WAITMOVEMENTDESTINY", "PURCHASEORDEROperation");

            context["Objective"] = new List <string> {
                "3"
            };                                              //destruction
            context["Departament"] = new List <string> {
                "1"
            };
            IList <Activity> lista = work.GetActivities(context);

            Assert.IsTrue(lista.Count == 2 && lista.Any(x => x.Operation.Equals("RELEASE_EXTINTION")));
        }
示例#31
0
        public void PrintPURCHASEASKParaDepositContext()
        {
            WorkFlowContext context = work.GetContext().AddElements("ATDRAFT", "AreaPURCHASEASK");

            context["Objective"] = new List <string> {
                "2"
            };                                              //deposito
            context["Departament"] = new List <string> {
                "2"
            };

            var    lista      = (List <string>)work.Run(context, SearchMode.Breadth, new ListVisitor());
            string transicoes = string.Join(",", lista.ToArray());

            Assert.AreEqual("ATDRAFT--[Ask Aproving]-->WAITINGALLOW ,ATDRAFT--[Erase Draft]-->None ,WAITINGALLOW--[Emit PURCHASEASK]-->EMITTED ,WAITINGALLOW--[Não Aprove PURCHASEASK]-->ATREVISION ,WAITINGALLOW--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,EMITTED--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,EMITTED--[Take PURCHASEASK]-->ATANALYSIS ,ATREVISION--[Ask Aproving]-->WAITINGALLOW ,ATREVISION--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,CANCELASKEDPURCHASEASK--[Recusar Cancelling]-->None ,ATANALYSIS--[Associate PURCHASEORDER]-->PURCHASEORDERCREATED ,ATANALYSIS--[Correct PURCHASEASK]-->ATREVISION ,ATANALYSIS--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,PURCHASEORDERCREATED--[Encerrando PURCHASEASK]-->PROCESSFINISHED ,PURCHASEORDERCREATED--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ", transicoes);
        }
示例#32
0
        public void GetNextStatusWithAll()
        {
            WorkFlowContext context = work.GetContext().SetArea("AreaPURCHASEASK")
                                      .SetOperation("SOLICITAR_CANCEL")
                                      .SetSourceState("EMITTED");

            context["Objective"] = new List <string> {
                "2"
            };                                              //deposito
            context["Departament"] = new List <string> {
                "1"
            };
            string status = work.GetNextStatus(context);

            Assert.AreEqual("CANCELASKEDPURCHASEASK", status);
        }