Esempio n. 1
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();
        }
Esempio n. 2
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);
                    }
                }
            }
        }
Esempio n. 3
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;
                    }
                }
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public virtual string GetNextStatus(WorkFlowContext context)
        {
            var retorno = (from w in GetNode().WorkFlow
                           from i in w.Transitions
                           where w.Area.Equals(context.Area)
                           && context.Match.IsOriginStateNotNeeded(w, context.SourceState)
                           && i.Operation.Equals(context.Operation)
                           && context.Match.CheckConditions(i.Condition, context)
                           select i.DestinyState).ToList();

            if (retorno.Count == 0) throw new StatusNotFoundException("There is no destiny for this source.");
            if (retorno.Count > 1) throw new StatusNotFoundException("There are 2 or more destinies.");

            return retorno[0].ToString();
        }
Esempio n. 7
0
        public override bool CheckConditions(string condition, WorkFlowContext context)
        {
            if (condition == null) return true;

            if (condition.StartsWith("!"))
            {
                Condition cond = GetNode().Conditions.Where(x => x.Name.Equals(condition.Substring(1))).FirstOrDefault();
                return !CheckParameters(context, cond);
            }
            else
            {
                Condition cond = GetNode().Conditions.Where(x => x.Name.Equals(condition)).FirstOrDefault();
                return CheckParameters(context, cond);
            }
        }
Esempio n. 8
0
        public override object Run(WorkFlowContext context, SearchMode mode, IVisitor visitor = null)
        {
            if (visitor == null)
                visitor = new DefaultVisitor();

            if (mode == SearchMode.Depth)
            {
                RunInDepth(context, visitor);
            }
            else if (mode == SearchMode.Breadth)
            {
                RunInWidth(context, visitor);
            }

            return visitor.EndVisit();
        }
Esempio n. 9
0
 public abstract object Run(WorkFlowContext context, SearchMode mode, IVisitor visitor = null);
Esempio n. 10
0
        static void Main(string[] args)
        {
            //put this line in a global.asax for web
            WorkFlowConfiguration.Binder.SetRepository(typeof(DAOEmbeddedResource))
                .Setup(x => x.TypeName, "WorkFlow.Json.workflow.json , LightWorkFlow");

            IWorkFlow work = WorkFlowManager.GetManager();//getting instance of workflow. 
            
 /*
 {
 "Id": 36,     
 "SourceState": "ATDRAFT",
 "StateOrder": "Initial",
 "Transitions": [{ Operation:"AskAprovePURCHASEASK", Description:"Ask Aproving" , "DestinyState": "WAITINGALLOW"},
					  { Operation:"CancelDraft", Description:"Erase Draft" , "DestinyState": "None"}],        
              
 "Area": "AreaPURCHASEASK"
    },
*/
            //1) Getting Initial State

            string initialstate = work.GetInitialStatus("AreaPURCHASEASK");//ATDRAFT            
//======================================================================================================
            //2) listing operations that can be done from a specific state.

            WorkFlowContext workoperation = work.GetContext()
               .SetArea("AreaPURCHASEASK")
               .SetSourceState("ATDRAFT");

            IList<Activity> operations = work.GetActivities(workoperation);//AskAprovePURCHASEASK, CancelDraft

            string description = work.GetActivityDescription("AskAprovePURCHASEASK");//Ask Aproving
//=======================================================================================================
            //3) Get Next Status

            WorkFlowContext workgetnextstatus = work.GetContext()
               .SetArea("AreaPURCHASEASK")
               .SetSourceState("ATDRAFT")
               .SetOperation("AskAprovePURCHASEASK");

            string nextstatus = work.GetNextStatus(workgetnextstatus);//WAITINGALLOW
//========================================================================================================
            //4)Runner - walk throughout workflow in depth and breadth

            //setting area and initial state from which runner will start to look at.
            WorkFlowContext workc = work.GetContext()
                .SetArea("AreaPURCHASEASK")
                .SetSourceState("ATDRAFT");

            var depth = work.Run(workc, SearchMode.Depth);//all transitions printed in a depth search mode.

            work.GetContext()
                .SetArea("AreaPURCHASEASK")
                .SetSourceState("ATDRAFT");

            var breadth = (IList<string>)work.Run(workc, SearchMode.Breadth);//all transitions printed in a breadth search mode.


            //4.1 configuring visitor

            WorkFlowContext workvisitor = work.GetContext()
               .SetArea("AreaPURCHASEASK")
               .SetSourceState("ATDRAFT");

            var workvisitordepth = work.Run(workc, SearchMode.Depth, new CustomVisitor());//ok

//========================================================================================================
            //5) setting conditions
            /*
             * {
                  "Name": "EXTINTION",
                  "Parameters": [
                    {
                      "Key": "Objective",
                      "Value": [
                        "4",
                        "3",
                        "7",
                        "5",
                        "9",
                        "8"
                      ]
                    }
                  ]
                },
            {
             "Id": 10,      
             "SourceState": "WAITMOVEMENTDESTINY",
             "Transitions": [{ Condition:"!EXTINTION", Operation:"PURCHASEORDER_CONFIRM_ARRIVE_DESTINY", Description:"Confirm chegada" , "DestinyState": "WAITRETURN"},					  
                            { Condition: "EXTINTION", Operation:"PROTOCOLR_REQUIREMENT", Description:"Protocolar Requerimento" , "DestinyState": "PROTOCOLREQUIREMENT"}],    
             "Area": "AreaPURCHASEORDER"
             },
                        */

            WorkFlowContext workoperationcond = work.GetContext()
               .SetArea("AreaPURCHASEORDER")
               .SetSourceState("WAITMOVEMENTDESTINY");

            workoperationcond["Objective"] = new List<string> { "4" };

            IList<Activity> operationsExtintion = work.GetActivities(workoperationcond);
            //PROTOCOLR_REQUIREMENT,PURCHASEORDER_CANCEL

            workoperationcond["Objective"] = new List<string> { "1" };

            IList<Activity> operationsNoExtintion = work.GetActivities(workoperationcond);
            //PURCHASEORDER_CONFIRM_ARRIVE_DESTINY,PURCHASEORDER_CANCEL


            //PURCHASEORDER_CANCEL shows up here because SourceState is configured with "All" in the area "AreaPURCHASEORDER".
            //if you dont want this operation shows up in a set of states, use "But" inside operation.

            //6) Setting a new condition match class

            WorkFlowContext context = new WorkFlowContext {                 
                 Area = "AreaPURCHASEORDER",
                 Operation = "PURCHASEORDER_CONFIRM_ARRIVE_DESTINY",
                 SourceState = "WAITMOVEMENTDESTINY"
            }.SetCondition(typeof(NewMatch));

            context["Objective"] = new List<string> { "2" };
           
            string state = work.GetNextStatus(context);
        }
Esempio n. 11
0
 public abstract bool CheckConditions(string p, WorkFlowContext context);