├── .gitignore ├── .vs ├── JsonWorkFlow │ └── v14 │ │ └── .suo └── config │ └── applicationhost.config ├── JsonWorkFlow.sln ├── JsonWorkFlow.v12.suo ├── README.md ├── WorkFlow ├── BpActivity.cs ├── Business │ ├── BusinessProcess │ │ ├── ActivityManager.cs │ │ └── Runner.cs │ └── Search │ │ └── SearchMode.cs ├── Classificador.cs ├── Command │ ├── DefaultWorkFlowCommand.cs │ ├── IEvaluatorCommand.cs │ └── IWorkFlowCommand.cs ├── ConcreteCondition │ ├── ConditionBase.cs │ └── MatchCondition.cs ├── Configuration │ ├── WorkFlowConfiguration.cs │ └── WorkFlowSettings.cs ├── Context │ ├── IMatchCondition.cs │ └── WorkFlowContext.cs ├── ControlAccess │ └── IControlAccess.cs ├── DAO │ ├── DAODataBase.cs │ ├── DAOEmbeddedResource.cs │ ├── DAOOracleDataBase.cs │ └── IDAO.cs ├── Entities │ ├── Activity.cs │ ├── Condition.cs │ ├── Evaluate.cs │ ├── Node.cs │ ├── Structure.cs │ └── Transition.cs ├── Evaluators │ ├── CompEvaluator.cs │ ├── EqEvaluator.cs │ └── InEvaluator.cs ├── Exceptions │ ├── DuplicatedNodeException.cs │ ├── RepositoryNotFoundException.cs │ ├── StatusException.cs │ ├── StatusNotFoundException.cs │ ├── TypeNameNotFoundException.cs │ └── WorkFlowNotFoundException.cs ├── IWorkFlow.cs ├── Json │ └── workflow.json ├── Movimentacao │ └── WorkFlowImpl.cs ├── Properties │ └── AssemblyInfo.cs ├── Singleton │ └── WorkFlowSingleton.cs ├── Utils │ └── WorkFlowUtils.cs ├── Validation │ ├── IValidator.cs │ ├── ValidationResult.cs │ └── ValidatorDefault.cs ├── Visitors │ ├── DefaultVisitor.cs │ └── IVisitor.cs ├── WorkFlow.csproj ├── WorkFlow.csproj.vspscc ├── WorkflowService.cs └── packages.config ├── WorkFlowClient ├── App.config ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── WorkFlowClient.csproj └── WorkFlowClient.csproj.vspscc ├── WorkFlowTest ├── Properties │ └── AssemblyInfo.cs ├── Visitor │ └── ListVisitor.cs ├── WorkFlowTest.cs ├── WorkFlowTest.csproj └── WorkFlowTest.csproj.vspscc ├── WorkFlowTestException ├── ExceptionsWorkFlowTest.cs ├── Json │ ├── conditionException.json │ ├── idException.json │ └── sourceAreaException.json ├── Properties │ └── AssemblyInfo.cs └── WorkFlowTestException.csproj └── packages ├── Newtonsoft.Json.6.0.1 ├── Newtonsoft.Json.6.0.1.nupkg ├── Newtonsoft.Json.6.0.1.nuspec ├── lib │ ├── net20 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── net35 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── net40 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── net45 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── netcore45 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── portable-net40+sl5+wp80+win8+monotouch+monoandroid │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ └── portable-net45+wp80+win8 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml └── tools │ └── install.ps1 └── repositories.config /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio. 3 | ################################################################################ 4 | 5 | /WorkFlowTestException/bin/Debug 6 | /WorkFlowTest/bin/Debug 7 | /WorkFlowTest/obj/Debug 8 | /WorkFlowTestException/obj/Debug 9 | /WorkFlowClient/obj/Debug 10 | /WorkFlowClient/bin/Debug 11 | /WorkFlow/bin/Debug 12 | /WorkFlow/obj/Debug 13 | -------------------------------------------------------------------------------- /.vs/JsonWorkFlow/v14/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/.vs/JsonWorkFlow/v14/.suo -------------------------------------------------------------------------------- /JsonWorkFlow.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkFlowTest", "WorkFlowTest\WorkFlowTest.csproj", "{15111F02-02BD-4639-893C-C939ADFC367D}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkFlow", "WorkFlow\WorkFlow.csproj", "{BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkFlowClient", "WorkFlowClient\WorkFlowClient.csproj", "{F546445F-1FCD-4442-ACA1-2F7E932A8286}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkFlowTestException", "WorkFlowTestException\WorkFlowTestException.csproj", "{0A285418-EEA9-48DE-8A0D-73A161DA9DE5}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | DESENVOLVIMENTO|Any CPU = DESENVOLVIMENTO|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | TESTE|Any CPU = TESTE|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {15111F02-02BD-4639-893C-C939ADFC367D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {15111F02-02BD-4639-893C-C939ADFC367D}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {15111F02-02BD-4639-893C-C939ADFC367D}.DESENVOLVIMENTO|Any CPU.ActiveCfg = Debug|Any CPU 25 | {15111F02-02BD-4639-893C-C939ADFC367D}.DESENVOLVIMENTO|Any CPU.Build.0 = Debug|Any CPU 26 | {15111F02-02BD-4639-893C-C939ADFC367D}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {15111F02-02BD-4639-893C-C939ADFC367D}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {15111F02-02BD-4639-893C-C939ADFC367D}.TESTE|Any CPU.ActiveCfg = Release|Any CPU 29 | {15111F02-02BD-4639-893C-C939ADFC367D}.TESTE|Any CPU.Build.0 = Release|Any CPU 30 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}.DESENVOLVIMENTO|Any CPU.ActiveCfg = DESENVOLVIMENTO|Any CPU 33 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}.DESENVOLVIMENTO|Any CPU.Build.0 = DESENVOLVIMENTO|Any CPU 34 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}.TESTE|Any CPU.ActiveCfg = TESTE|Any CPU 37 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F}.TESTE|Any CPU.Build.0 = TESTE|Any CPU 38 | {F546445F-1FCD-4442-ACA1-2F7E932A8286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {F546445F-1FCD-4442-ACA1-2F7E932A8286}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {F546445F-1FCD-4442-ACA1-2F7E932A8286}.DESENVOLVIMENTO|Any CPU.ActiveCfg = Debug|Any CPU 41 | {F546445F-1FCD-4442-ACA1-2F7E932A8286}.DESENVOLVIMENTO|Any CPU.Build.0 = Debug|Any CPU 42 | {F546445F-1FCD-4442-ACA1-2F7E932A8286}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {F546445F-1FCD-4442-ACA1-2F7E932A8286}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {F546445F-1FCD-4442-ACA1-2F7E932A8286}.TESTE|Any CPU.ActiveCfg = Release|Any CPU 45 | {F546445F-1FCD-4442-ACA1-2F7E932A8286}.TESTE|Any CPU.Build.0 = Release|Any CPU 46 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5}.DESENVOLVIMENTO|Any CPU.ActiveCfg = Debug|Any CPU 49 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5}.DESENVOLVIMENTO|Any CPU.Build.0 = Debug|Any CPU 50 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5}.Release|Any CPU.ActiveCfg = Release|Any CPU 51 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5}.Release|Any CPU.Build.0 = Release|Any CPU 52 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5}.TESTE|Any CPU.ActiveCfg = Release|Any CPU 53 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5}.TESTE|Any CPU.Build.0 = Release|Any CPU 54 | EndGlobalSection 55 | GlobalSection(SolutionProperties) = preSolution 56 | HideSolutionNode = FALSE 57 | EndGlobalSection 58 | EndGlobal 59 | -------------------------------------------------------------------------------- /JsonWorkFlow.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/JsonWorkFlow.v12.suo -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LightWorkFlow 2 | ============= 3 | 4 | The first question is: why a new workflow engine instead using WF, that´s supported by Microsoft? 5 | 6 | 1) You are working with legacy applications, whose code was not built inside a good architecture approach. So, adapting the code and architecture to use WF is not an option. 7 | 8 | 1.1) By refactoring legacy applications, in order to avoid "ifs" statements. 9 | 10 | 2) You need to test your workflow using unit tests. WF is so dependent on infrastructure, that does this task really painful. 11 | 12 | 3) There's no infrastructure to use WF in your company. It happens, you can believe. 13 | 14 | 4) You don't want to see that ugly XML built by WF design tool. Instead, you'd rather a json file. (That's a good reason) 15 | 16 | What's LightWorkFlow? 17 | 18 | A lightweight workflow to handle activities and status. 19 | 20 | A easy way to handle with workflow. There's no need of a big infrastructure as WF. 21 | A good way to avoid big and heavy design tools, it fits perfectly for simple cases. 22 | 23 | Become familiar with lightworkflow seeing WorkflowClient project examples. 24 | 25 | There are unit tests to help you as well. 26 | 27 | http://lordinateurandme.wordpress.com/2014/02/13/tutorial-lightworkflow-part-1-motivations/ 28 | 29 | http://lordinateurandme.wordpress.com/2014/02/27/tutorial-lightworkflow-part-2-setting-up-json-file/ 30 | 31 | http://lordinateurandme.wordpress.com/2014/03/19/lightworkflow-setting-oracle-repository/ 32 | 33 | For good samples, see links below: 34 | 35 | https://github.com/xblader/LightWorkFlow/blob/master/WorkFlowTestException/ExceptionsWorkFlowTest.cs 36 | 37 | https://github.com/xblader/LightWorkFlow/blob/master/WorkFlowTest/WorkFlowTest.cs 38 | 39 | https://github.com/xblader/LightWorkFlow/blob/master/WorkFlowClient/Program.cs 40 | -------------------------------------------------------------------------------- /WorkFlow/BpActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WorkFlow.Entities; 7 | using System.Linq; 8 | using WorkFlow.Exceptions; 9 | using Newtonsoft.Json; 10 | using WorkFlow.Visitors; 11 | using WorkFlow.ControlAccess; 12 | 13 | namespace WorkFlow 14 | { 15 | public class BpActivity 16 | { 17 | private List transitions = new List(); 18 | private Structure node = WorkFlow.Singleton.WorkFlowSingleton.Instance().GetStructure(); 19 | 20 | public string GetNextStatus(string area, string operacao, string statusOrigem = null, Dictionary> parameters = null) 21 | { 22 | var retorno = (from w in node.WorkFlow 23 | from i in w.Transitions 24 | where w.Area.Equals(area) 25 | && IsOriginStateNotNeeded(w, statusOrigem) 26 | && i.Operacao.Equals(operacao) 27 | && CheckConditions(i.Condicao, parameters) 28 | select i.StatusDestino).ToList(); 29 | 30 | if (retorno.Count == 0) throw new StatusException("Não foi encontrado um destino para esta origem."); 31 | if (retorno.Count > 1) throw new StatusException("Foram encontrados 2 ou mais Status de destino."); 32 | 33 | return retorno[0].ToString(); 34 | } 35 | 36 | private bool IsOriginStateNotNeeded(Node node, string statusOrigem) 37 | { 38 | if (string.IsNullOrEmpty(statusOrigem)) 39 | return true; 40 | 41 | return (node.StatusOrigem.Equals(statusOrigem) || node.StatusOrigem.Equals("All")); 42 | } 43 | 44 | public IList GetActivities(string origem, string area, Dictionary> parameters = null, IControlAccess access = null) 45 | { 46 | var atividades = from w in node.WorkFlow 47 | from i in w.Transitions 48 | where w.Area.Equals(area) 49 | && (w.StatusOrigem.Equals(origem) || CheckExcludeAtivity(origem, w, i)) 50 | && CheckConditions(i.Condicao, parameters) 51 | select new Activity { Operacao = i.Operacao, Descricao = i.Descricao }; 52 | 53 | return (access != null) ? access.checkAccessActivity(atividades.ToList()) : atividades.ToList(); 54 | } 55 | 56 | /// 57 | /// 58 | /// 59 | /// 60 | /// 61 | /// 62 | public bool CheckExcludeAtivity(string origem, Node node, Transition trans) 63 | { 64 | if (node.StatusOrigem.Equals("All") && trans.But == null) 65 | { 66 | return true; 67 | } 68 | 69 | return (node.StatusOrigem.Equals("All") && !trans.But.Any(x => x.Equals(origem))); 70 | } 71 | 72 | public bool CheckConditions(string condition, Dictionary> parameters) 73 | { 74 | if (condition == null) return true; 75 | 76 | Condition cond = node.Conditions.Where(x => x.Name.Equals(condition)).FirstOrDefault(); 77 | 78 | var conditions = cond.Parameters.ToDictionary(x => x.Key, y => y.Value); 79 | //first verifying if parameters keys supply all conditions keys 80 | bool keysmatch = (parameters.Keys.Count >= conditions.Keys.Count) && 81 | (parameters.Keys.Intersect(conditions.Keys).Count() == conditions.Keys.Count); 82 | //verifying if parameter values are in condition values 83 | int numbervaluesmatches = parameters.Keys 84 | .Where(k => conditions.ContainsKey(k) && conditions[k].Intersect(parameters[k]).Count() == parameters[k].Count) 85 | .Count(); 86 | 87 | return keysmatch && (numbervaluesmatches == conditions.Count); 88 | } 89 | 90 | public object RunInDepth(string status, string area, Dictionary> parameters, IVisitor visitor = null) 91 | { 92 | Run(status, area, parameters, visitor); 93 | return (visitor ?? new DefaultVisitor()).EndVisit(); 94 | } 95 | 96 | private void Run(string status, string area, Dictionary> parameters, IVisitor visitor) 97 | { 98 | if (string.IsNullOrEmpty(status)) 99 | { 100 | return; 101 | } 102 | else 103 | { 104 | foreach (var item in this.GetActivities(status, area, parameters).OrderBy(x => x.Operacao)) 105 | { 106 | string novostatus = this.GetNextStatus(area, item.Operacao, status, parameters); 107 | string transicao = string.Format("{0},{1},{2}", status, item.Descricao, novostatus); 108 | 109 | if (NotPresent(transicao)) 110 | { 111 | (visitor ?? new DefaultVisitor()).Visit(status, new Activity { Operacao = item.Operacao, Descricao = item.Descricao }, novostatus); 112 | RunInDepth(novostatus, area, parameters, visitor); 113 | } 114 | } 115 | } 116 | } 117 | 118 | private bool NotPresent(string transicao) 119 | { 120 | if (!transitions.Any(x => x.Equals(transicao))) 121 | { 122 | transitions.Add(transicao); 123 | return true; 124 | } 125 | 126 | return false; 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /WorkFlow/Business/BusinessProcess/ActivityManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using WorkFlow; 5 | using WorkFlow.Entities; 6 | using System.Linq; 7 | using WorkFlow.Exceptions; 8 | using System.Data; 9 | using WorkFlow.Visitors; 10 | using WorkFlow.ControlAccess; 11 | using WorkFlow.Business.Search; 12 | using WorkFlow.Context; 13 | using WorkFlow.Validation; 14 | using WorkFlow.Command; 15 | //using WorkFlow.Business; 16 | namespace WorkFlow.Business.BusinessProcess 17 | { 18 | 19 | /// 20 | /// Classe para os processos do WorkFlow. 21 | /// 22 | public abstract class ActivityManager : WorkFlowContext, IWorkFlow 23 | { 24 | private List transitions = new List(); 25 | 26 | public virtual string GetNextStatus(WorkFlowContext context) 27 | { 28 | var retorno = (from w in GetNode().WorkFlow 29 | from i in w.Transitions 30 | where w.Area.Equals(context.Area) 31 | && context.Match.IsOriginStateNotNeeded(w, context.SourceState) 32 | && i.Operation.Equals(context.Operation) 33 | && context.Match.CheckConditions(i.Condition, context) 34 | select i.DestinyState).ToList(); 35 | 36 | if (retorno.Count == 0) throw new StatusNotFoundException("There is no destiny for this source."); 37 | if (retorno.Count > 1) throw new StatusNotFoundException("There are 2 or more destinies."); 38 | 39 | return retorno[0].ToString(); 40 | } 41 | public IList ValidateNextStatus(WorkFlowContext context) 42 | { 43 | var results = new List(); 44 | var nodes = GetNode().WorkFlow.Where(x => x.Area == context.Area); 45 | 46 | var retorno = (from w in nodes 47 | from i in w.Transitions 48 | where context.Match.IsOriginStateNotNeeded(w, context.SourceState) 49 | && i.Operation.Equals(context.Operation) 50 | && context.Match.CheckConditions(i.Condition, context, results) 51 | select i.DestinyState).ToList(); 52 | return results; 53 | } 54 | 55 | public virtual IList GetActivities(WorkFlowContext context, IControlAccess access = null) 56 | { 57 | var nodes = GetNode().WorkFlow.Where(x => x.Area == context.Area); 58 | 59 | var atividades = from w in nodes 60 | from i in w.Transitions 61 | where (w.SourceState.Equals(context.SourceState) || context.Match.CheckExcludeAtivity(context.SourceState, w, i)) 62 | && context.Match.CheckConditions(i.Condition, context) 63 | select new Activity { Operation = i.Operation, Description = i.Description }; 64 | 65 | return (access != null) ? access.checkAccessActivity(atividades.ToList()) : atividades.ToList(); 66 | } 67 | 68 | public virtual string GetInitialStatus(string area) 69 | { 70 | string retorno = (from i in GetNode().WorkFlow 71 | where i.Area.Equals(area) && (!string.IsNullOrEmpty(i.StateOrder) && i.StateOrder.Equals("Initial")) 72 | select i.SourceState).FirstOrDefault(); 73 | 74 | return retorno; 75 | } 76 | 77 | public virtual IList ListAreas() 78 | { 79 | return GetNode().WorkFlow.Select(x => x.Area).Distinct().ToList(); 80 | } 81 | 82 | public virtual string GetActivityDescription(string operation) 83 | { 84 | return (from i in GetNode().WorkFlow 85 | from atc in i.Transitions 86 | where atc.Operation.Equals(operation) 87 | select atc.Description).FirstOrDefault(); 88 | } 89 | 90 | public abstract object Run(WorkFlowContext context, SearchMode mode, IVisitor visitor = null); 91 | 92 | 93 | public virtual WorkFlowContext GetContext() 94 | { 95 | return this; 96 | } 97 | 98 | public WorkFlowContext SetNewEvaluator(IEvaluatorCommand evaluator) 99 | { 100 | 101 | return this; 102 | } 103 | } 104 | } 105 | 106 | -------------------------------------------------------------------------------- /WorkFlow/Business/BusinessProcess/Runner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Business.Search; 6 | using WorkFlow.Context; 7 | using WorkFlow.Entities; 8 | using WorkFlow.Visitors; 9 | 10 | namespace WorkFlow.Business.BusinessProcess 11 | { 12 | public class RunnerManager : ActivityManager 13 | { 14 | private List transitions = new List(); 15 | 16 | public override object Run(WorkFlowContext context, SearchMode mode, IVisitor visitor = null) 17 | { 18 | if (visitor == null) 19 | visitor = new DefaultVisitor(); 20 | 21 | if (mode == SearchMode.Depth) 22 | { 23 | RunInDepth(context, visitor); 24 | } 25 | else if (mode == SearchMode.Breadth) 26 | { 27 | RunInWidth(context, visitor); 28 | } 29 | 30 | return visitor.EndVisit(); 31 | } 32 | 33 | private void RunInDepth(WorkFlowContext context, IVisitor visitor) 34 | { 35 | if (string.IsNullOrEmpty(context.SourceState)) 36 | { 37 | return; 38 | } 39 | else 40 | { 41 | foreach (var item in this.GetActivities(context).OrderBy(x => x.Operation)) 42 | { 43 | context.Operation = item.Operation; 44 | string newstatus = this.GetNextStatus(context); 45 | string laststate = context.SourceState; 46 | string transition = string.Format("{0},{1},{2}", context.SourceState, item.Description, newstatus); 47 | 48 | if (NotPresent(transition)) 49 | { 50 | visitor.Visit(context.SourceState, new Activity { Operation = item.Operation, Description = item.Description }, newstatus); 51 | context.SourceState = newstatus; 52 | RunInDepth(context, visitor); 53 | context.SourceState = laststate; 54 | } 55 | } 56 | } 57 | } 58 | 59 | private void RunInWidth(WorkFlowContext context, IVisitor visitor) 60 | { 61 | Queue fila = new Queue(); 62 | List mark = new List(); 63 | 64 | fila.Enqueue(context.SourceState); 65 | mark.Add(context.SourceState); 66 | 67 | while (fila.Count != 0) 68 | { 69 | string statusfila = fila.Dequeue(); 70 | context.SourceState = statusfila; 71 | foreach (var item in this.GetActivities(context).OrderBy(x => x.Operation)) 72 | { 73 | context.Operation = item.Operation; 74 | string newstatus = this.GetNextStatus(context); 75 | visitor.Visit(statusfila, new Activity { Operation = item.Operation, Description = item.Description }, newstatus); 76 | 77 | if (!mark.Contains(newstatus)) 78 | { 79 | fila.Enqueue(newstatus); 80 | mark.Add(newstatus); 81 | } 82 | } 83 | } 84 | 85 | } 86 | 87 | private bool NotPresent(string transition) 88 | { 89 | if (!transitions.Any(x => x.Equals(transition))) 90 | { 91 | transitions.Add(transition); 92 | return true; 93 | } 94 | 95 | return false; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /WorkFlow/Business/Search/SearchMode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Business.Search 7 | { 8 | public enum SearchMode 9 | { 10 | Depth = 0, 11 | Breadth = 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WorkFlow/Classificador.cs: -------------------------------------------------------------------------------- 1 |  2 | using Classificador; 3 | 4 | namespace Workflow 5 | { 6 | public class Classe : IClassificador 7 | { 8 | public virtual string Codigo { get; set; } 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /WorkFlow/Command/DefaultWorkFlowCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Impl; 6 | 7 | namespace WorkFlow.Command 8 | { 9 | public class DefaultWorkFlowCommand : IWorkFlowCommand 10 | { 11 | public void Execute(Context.WorkFlowContext context) 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WorkFlow/Command/IEvaluatorCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Context; 6 | using WorkFlow.Entities; 7 | 8 | namespace WorkFlow.Command 9 | { 10 | public interface IEvaluatorCommand 11 | { 12 | IEvaluatorCommand Successor { get; set; } 13 | bool Execute(Evaluate item, WorkFlowContext context); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WorkFlow/Command/IWorkFlowCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Context; 6 | 7 | namespace WorkFlow.Command 8 | { 9 | public interface IWorkFlowCommand 10 | { 11 | void Execute(WorkFlowContext context); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WorkFlow/ConcreteCondition/ConditionBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Command; 6 | using WorkFlow.Context; 7 | using WorkFlow.Entities; 8 | using WorkFlow.Evaluators; 9 | using WorkFlow.Validation; 10 | 11 | namespace WorkFlow.ConcreteCondition 12 | { 13 | public abstract class ConditionBase : WorkFlowContext , IMatchCondition 14 | { 15 | // Setup Chain of Responsibility 16 | private IEvaluatorCommand evaluator = 17 | new EqEvaluator { 18 | Successor = new CompEvaluator { Successor = new InEvaluator() } 19 | }; 20 | 21 | public virtual bool CheckParameters(WorkFlowContext context, Condition cond, IList results = null) 22 | { 23 | var conditions = cond.Parameters.ToDictionary(x => x.Key, y => y.Value); 24 | //first verifying if parameters keys supply all conditions keys 25 | bool keysmatch = (context.Count >= conditions.Keys.Count) && 26 | (context.Keys.Intersect(conditions.Keys).Count() == conditions.Keys.Count); 27 | 28 | if (!keysmatch) return false; 29 | 30 | foreach (var parameter in cond.Parameters) 31 | { 32 | if (!evaluator.Execute(parameter, context)) 33 | { 34 | if (results == null) return false; 35 | results.Add(new ValidationResult(cond, parameter)); 36 | } 37 | } 38 | 39 | if (results == null) return true; 40 | 41 | return !results.Any(); 42 | } 43 | 44 | public abstract bool IsOriginStateNotNeeded(Node node, string sourceState); 45 | 46 | public abstract bool CheckConditions(string p, WorkFlowContext context, IList results = null); 47 | 48 | public abstract bool CheckExcludeAtivity(string sourceState, Entities.Node w, Entities.Transition i); 49 | 50 | public IMatchCondition AddOperator(IEvaluatorCommand evaluator) 51 | { 52 | this.evaluator = InsertEvaluator(this.evaluator, evaluator); 53 | return this; 54 | } 55 | 56 | private IEvaluatorCommand InsertEvaluator(IEvaluatorCommand evaluatorSet, IEvaluatorCommand NewEvaluator) 57 | { 58 | if (evaluatorSet == null) 59 | return NewEvaluator; 60 | else 61 | { 62 | evaluatorSet.Successor = InsertEvaluator(evaluatorSet.Successor, NewEvaluator); 63 | return evaluatorSet; 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /WorkFlow/ConcreteCondition/MatchCondition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Context; 6 | using WorkFlow.Entities; 7 | using WorkFlow.Validation; 8 | 9 | namespace WorkFlow.ConcreteCondition 10 | { 11 | public class MatchCondition : ConditionBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public override bool CheckExcludeAtivity(string sourceState, Node node, Transition trans) 20 | { 21 | if (node.SourceState.Equals("All") && trans.But == null) 22 | { 23 | return true; 24 | } 25 | 26 | return (node.SourceState.Equals("All") && !trans.But.Any(x => x.Equals(sourceState))); 27 | } 28 | 29 | public override bool IsOriginStateNotNeeded(Node node, string sourceState) 30 | { 31 | if (string.IsNullOrEmpty(sourceState)) 32 | return true; 33 | 34 | return (node.SourceState.Equals(sourceState) || node.SourceState.Equals("All")); 35 | } 36 | 37 | public override bool CheckConditions(string condition, WorkFlowContext context, IList results = null) 38 | { 39 | if (condition == null) return true; 40 | 41 | if (condition.StartsWith("!")) 42 | { 43 | Condition cond = GetNode().Conditions.Where(x => x.Name.Equals(condition.Substring(1))).FirstOrDefault(); 44 | return !CheckParameters(context, cond, results); 45 | } 46 | else 47 | { 48 | Condition cond = GetNode().Conditions.Where(x => x.Name.Equals(condition)).FirstOrDefault(); 49 | return CheckParameters(context, cond, results); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /WorkFlow/Configuration/WorkFlowConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.DAO; 6 | using System.Linq.Expressions; 7 | using System.Reflection; 8 | 9 | namespace WorkFlow.Configuration 10 | { 11 | public class WorkFlowConfiguration 12 | { 13 | private static WorkFlowConfiguration _instance; 14 | private static object syncRoot = new Object(); 15 | internal WorkFlowSettings Setting { get; set; } 16 | 17 | public static WorkFlowConfiguration Binder { 18 | get 19 | { 20 | if (_instance == null) 21 | { 22 | lock (syncRoot) 23 | { 24 | if (_instance == null) 25 | _instance = new WorkFlowConfiguration(); 26 | } 27 | } 28 | 29 | return _instance; 30 | } 31 | } 32 | 33 | public WorkFlowSettings SetRepository(Type repository) 34 | { 35 | Setting = new WorkFlowSettings(); 36 | Setting.Repository = repository; 37 | return Setting; 38 | } 39 | 40 | internal Type GetRepository() 41 | { 42 | return Setting.Repository; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /WorkFlow/Configuration/WorkFlowSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Linq.Expressions; 6 | using System.Reflection; 7 | using WorkFlow.Validation; 8 | 9 | namespace WorkFlow.Configuration 10 | { 11 | public class WorkFlowSettings 12 | { 13 | internal Type Repository { get; set; } 14 | internal WorkFlowSettingParameter Parameter { get; set; } 15 | internal IValidator Validator { get; set; } 16 | public WorkFlowSettings() 17 | { 18 | Parameter = new WorkFlowSettingParameter(); 19 | Validator = new ValidatorDefault(); 20 | } 21 | 22 | public WorkFlowSettings SetValidator(Type validator) 23 | { 24 | Validator = (IValidator)Activator.CreateInstance(validator); 25 | return this; 26 | } 27 | 28 | public WorkFlowSettings Setup(Expression> memberLamda, string value) 29 | { 30 | var memberSelectorExpression = memberLamda.Body as MemberExpression; 31 | if (memberSelectorExpression != null) 32 | { 33 | var property = memberSelectorExpression.Member as PropertyInfo; 34 | if (property != null) 35 | { 36 | property.SetValue(Parameter, value, null); 37 | } 38 | } 39 | return this; 40 | } 41 | } 42 | 43 | public class WorkFlowSettingParameter 44 | { 45 | public string ConnectionString { get; set; } 46 | public string Query { get; set; } 47 | public string TypeName { get; set; } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /WorkFlow/Context/IMatchCondition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Command; 6 | using WorkFlow.Entities; 7 | using WorkFlow.Validation; 8 | 9 | namespace WorkFlow.Context 10 | { 11 | public interface IMatchCondition 12 | { 13 | IMatchCondition AddOperator(IEvaluatorCommand evaluator); 14 | bool IsOriginStateNotNeeded(Node node, string sourceState); 15 | bool CheckConditions(string p, WorkFlowContext context, IList results = null); 16 | bool CheckExcludeAtivity(string sourceState, Entities.Node w, Entities.Transition i); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WorkFlow/Context/WorkFlowContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Command; 6 | using WorkFlow.ConcreteCondition; 7 | using WorkFlow.Entities; 8 | 9 | namespace WorkFlow.Context 10 | { 11 | public class WorkFlowContext 12 | { 13 | Dictionary> parameter = new Dictionary>(); 14 | 15 | private Structure node; 16 | private IWorkFlowCommand commandtype; 17 | public IMatchCondition Match { get; set; } 18 | 19 | public string Area { get; set; } 20 | public string Operation { get; set; } 21 | public string SourceState { get; set; } 22 | 23 | public WorkFlowContext() 24 | { 25 | node = WorkFlow.Singleton.WorkFlowSingleton.Instance().GetStructure(); 26 | } 27 | 28 | /// 29 | /// Reset WorkFlow Context 30 | /// 31 | /// 32 | public WorkFlowContext Reset() 33 | { 34 | this.Area = String.Empty; 35 | this.Operation = String.Empty; 36 | this.SourceState = String.Empty; 37 | parameter.Clear(); 38 | return this; 39 | } 40 | 41 | public WorkFlowContext SetArea(string area) 42 | { 43 | this.Area = area; 44 | return this; 45 | } 46 | 47 | public WorkFlowContext SetSourceState(string source) 48 | { 49 | this.SourceState = source; 50 | return this; 51 | } 52 | 53 | public WorkFlowContext SetOperation(string operation) 54 | { 55 | this.Operation = operation; 56 | return this; 57 | } 58 | 59 | public Structure GetNode() 60 | { 61 | return node; 62 | } 63 | 64 | public List this[string index] 65 | { 66 | get 67 | { 68 | return parameter[index]; 69 | } 70 | 71 | set 72 | { 73 | parameter[index] = value; 74 | } 75 | } 76 | 77 | public int Count 78 | { 79 | get { return parameter.Count; } 80 | } 81 | 82 | public Dictionary>.KeyCollection Keys 83 | { 84 | get { 85 | return parameter.Keys; 86 | } 87 | } 88 | 89 | public WorkFlowContext SetCondition(Type type) 90 | { 91 | this.Match = (IMatchCondition)Activator.CreateInstance(type); 92 | return this; 93 | } 94 | 95 | public WorkFlowContext SetCondition(IMatchCondition matchCondition) 96 | { 97 | this.Match = matchCondition; 98 | return this; 99 | } 100 | 101 | public WorkFlowContext AddElements(string sourceState, string area) 102 | { 103 | this.SourceState = sourceState; 104 | this.Area = area; 105 | return this; 106 | } 107 | 108 | public WorkFlowContext SetCommand(Type type) 109 | { 110 | this.commandtype = (IWorkFlowCommand)Activator.CreateInstance(type); 111 | return this; 112 | } 113 | 114 | public WorkFlowContext Execute() 115 | { 116 | commandtype.Execute(this); 117 | return this; 118 | } 119 | 120 | public WorkFlowContext AddEvaluator(IEvaluatorCommand customEvaluator) 121 | { 122 | this.Match.AddOperator(customEvaluator); 123 | return this; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /WorkFlow/ControlAccess/IControlAccess.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.ControlAccess 7 | { 8 | public interface IControlAccess 9 | { 10 | IList checkAccessActivity(IList ativities); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /WorkFlow/DAO/DAODataBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.DAO 7 | { 8 | internal class DAODataBase : IDAO 9 | { 10 | public string GetJson() 11 | { 12 | return String.Empty; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WorkFlow/DAO/DAOEmbeddedResource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using WorkFlow.Configuration; 7 | using WorkFlow.Exceptions; 8 | using System.Reflection; 9 | 10 | namespace WorkFlow.DAO 11 | { 12 | public class DAOEmbeddedResource : IDAO 13 | { 14 | public string GetJson() 15 | { 16 | string result; 17 | string typeName = WorkFlowConfiguration.Binder.Setting.Parameter.TypeName; 18 | if (typeName == null) { throw new TypeNameNotFoundException("TypeName was not found. Check configuration of the workflow."); } 19 | 20 | Assembly assembly = Assembly.Load(typeName.Split(',')[1].Trim()); 21 | 22 | if (assembly == null) throw new Exception("An error occurred in attempting to load assembly."); 23 | 24 | using (Stream stream = assembly.GetManifestResourceStream(typeName.Split(',')[0].Trim())) 25 | { 26 | using (StreamReader sr = new StreamReader(stream)) 27 | { 28 | result = sr.ReadToEnd(); 29 | } 30 | } 31 | 32 | return result; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /WorkFlow/DAO/DAOOracleDataBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using System.Data.OracleClient; 7 | using System.Data; 8 | using WorkFlow.Configuration; 9 | using WorkFlow.Utils; 10 | 11 | namespace WorkFlow.DAO 12 | { 13 | public class DAOOracleDataBase : IDAO 14 | { 15 | public string GetJson() 16 | { 17 | return GetBlob(); 18 | } 19 | 20 | private string GetBlob() 21 | { 22 | byte[] data = new byte[] { }; 23 | string sql = WorkFlowConfiguration.Binder.Setting.Parameter.Query; 24 | string strconn = WorkFlowConfiguration.Binder.Setting.Parameter.ConnectionString; 25 | 26 | using (OracleConnection conn = new OracleConnection(strconn)) 27 | { 28 | conn.Open(); 29 | using (OracleCommand cmd = new OracleCommand(sql, conn)) 30 | { 31 | using (IDataReader dataReader = cmd.ExecuteReader()) 32 | { 33 | while (dataReader.Read()) 34 | { 35 | data = (Byte[])dataReader[0]; 36 | } 37 | } 38 | } 39 | } 40 | 41 | return string.Join("", WorkFlowUtils.BinaryToStrings(data, 1024)); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /WorkFlow/DAO/IDAO.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.DAO 7 | { 8 | public interface IDAO 9 | { 10 | string GetJson(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /WorkFlow/Entities/Activity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace WorkFlow.Entities 5 | { 6 | public class Activity 7 | { 8 | public string Operation { get; set; } 9 | public string Description { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /WorkFlow/Entities/Condition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Entities 7 | { 8 | public class Condition 9 | { 10 | public string Name { get; set; } 11 | public IList Parameters { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WorkFlow/Entities/Evaluate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Entities 7 | { 8 | public class Evaluate 9 | { 10 | public string Key { get; set; } 11 | public string Operator { get; set; } 12 | public IList Value { get; set; } 13 | public string Message { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WorkFlow/Entities/Node.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Entities 7 | { 8 | public class Node 9 | { 10 | public int Id { get; set; } 11 | public IList Transitions { get; set; } 12 | public string SourceState { get; set; } 13 | public string StateOrder { get; set; } 14 | public string Area { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WorkFlow/Entities/Structure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Entities 7 | { 8 | public class Structure 9 | { 10 | public IList Conditions { get; set; } 11 | public IList WorkFlow { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WorkFlow/Entities/Transition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Entities 7 | { 8 | public class Transition 9 | { 10 | public string Condition { get; set; } 11 | public string[] But { get; set; } 12 | public string DestinyState { get; set; } 13 | public string Operation { get; set; } 14 | public string Description { get; set; } 15 | } 16 | } 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /WorkFlow/Evaluators/CompEvaluator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Command; 6 | using WorkFlow.Context; 7 | using WorkFlow.Entities; 8 | 9 | namespace WorkFlow.Evaluators 10 | { 11 | public class CompEvaluator : IEvaluatorCommand 12 | { 13 | public IEvaluatorCommand Successor 14 | { 15 | get;set; 16 | } 17 | 18 | public bool Execute(Evaluate item, WorkFlowContext context) 19 | { 20 | bool result = false; 21 | 22 | string[] operators = new string[] { "lt", "le", "gt", "ge" }; 23 | 24 | if (operators.Any(x => x == item.Operator)) 25 | { 26 | decimal valuejson, valuecontext; 27 | if (decimal.TryParse(item.Value.FirstOrDefault(), out valuejson) && 28 | decimal.TryParse(context[item.Key].FirstOrDefault(), out valuecontext)) 29 | { 30 | switch (item.Operator) 31 | { 32 | case "lt": 33 | if (valuecontext < valuejson) 34 | { 35 | return true; 36 | } 37 | break; 38 | case "le": 39 | if (valuecontext <= valuejson) 40 | { 41 | return true; 42 | } 43 | break; 44 | case "gt": 45 | if (valuecontext > valuejson) 46 | { 47 | return true; 48 | } 49 | break; 50 | case "ge": 51 | if (valuecontext >= valuejson) 52 | { 53 | return true; 54 | } 55 | break; 56 | } 57 | } 58 | else 59 | { 60 | return false; 61 | } 62 | } 63 | else 64 | { 65 | result = Successor.Execute(item, context); 66 | } 67 | 68 | return result; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /WorkFlow/Evaluators/EqEvaluator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Command; 6 | using WorkFlow.Context; 7 | using WorkFlow.Entities; 8 | 9 | namespace WorkFlow.Evaluators 10 | { 11 | public class EqEvaluator : IEvaluatorCommand 12 | { 13 | public IEvaluatorCommand Successor 14 | { 15 | get; set; 16 | } 17 | public bool Execute(Evaluate item, WorkFlowContext context) 18 | { 19 | bool result = false; 20 | 21 | if(item.Operator == "eq") 22 | { 23 | if (item.Value.Count != context[item.Key].Count) return false; 24 | if (item.Value.All(context[item.Key].Contains)) 25 | { 26 | return true; 27 | } 28 | } 29 | else 30 | { 31 | result = Successor.Execute(item, context); 32 | } 33 | 34 | return result; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /WorkFlow/Evaluators/InEvaluator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Command; 6 | using WorkFlow.Context; 7 | using WorkFlow.Entities; 8 | 9 | namespace WorkFlow.Evaluators 10 | { 11 | public class InEvaluator : IEvaluatorCommand 12 | { 13 | public IEvaluatorCommand Successor 14 | { 15 | get; set; 16 | } 17 | public bool Execute(Evaluate item, WorkFlowContext context) 18 | { 19 | bool result = false; 20 | 21 | if (item.Operator == "in" || string.IsNullOrEmpty(item.Operator)) 22 | { 23 | if (item.Value.Intersect(context[item.Key]).Count() == context[item.Key].Count()) 24 | { 25 | return true; 26 | } 27 | } 28 | else 29 | { 30 | result = Successor.Execute(item, context); 31 | } 32 | 33 | return result; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WorkFlow/Exceptions/DuplicatedNodeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Exceptions 7 | { 8 | public class DuplicatedNodeException : Exception 9 | { 10 | private string message; 11 | 12 | public DuplicatedNodeException(string message) 13 | : base(message) 14 | { 15 | this.message = message; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WorkFlow/Exceptions/RepositoryNotFoundException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Exceptions 7 | { 8 | public class RepositoryNotFoundException : Exception 9 | { 10 | private string message; 11 | 12 | public RepositoryNotFoundException(string message) 13 | : base(message) 14 | { 15 | this.message = message; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WorkFlow/Exceptions/StatusException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace WorkFlow.Exceptions 8 | { 9 | public class StatusException : Exception 10 | { 11 | private string message; 12 | 13 | public StatusException(string message) 14 | { 15 | this.message = message; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WorkFlow/Exceptions/StatusNotFoundException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Exceptions 7 | { 8 | public class StatusNotFoundException : Exception 9 | { 10 | private string message; 11 | 12 | public StatusNotFoundException(string message):base(message) 13 | { 14 | this.message = message; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /WorkFlow/Exceptions/TypeNameNotFoundException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Exceptions 7 | { 8 | public class TypeNameNotFoundException : Exception 9 | { 10 | private string message; 11 | 12 | public TypeNameNotFoundException(string message) 13 | : base(message) 14 | { 15 | this.message = message; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WorkFlow/Exceptions/WorkFlowNotFoundException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Exceptions 7 | { 8 | public class WorkFlowNotFoundException : Exception 9 | { 10 | private string message; 11 | 12 | public WorkFlowNotFoundException(string message) 13 | : base(message) 14 | { 15 | this.message = message; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WorkFlow/IWorkFlow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Entities; 6 | using WorkFlow.ControlAccess; 7 | using WorkFlow.Visitors; 8 | using WorkFlow.Business.Search; 9 | using WorkFlow.Context; 10 | using WorkFlow.Validation; 11 | using WorkFlow.Evaluators; 12 | using WorkFlow.Command; 13 | 14 | namespace WorkFlow 15 | { 16 | public interface IWorkFlow 17 | { 18 | string GetNextStatus(WorkFlowContext context); 19 | IList ValidateNextStatus(WorkFlowContext context); 20 | string GetInitialStatus(string area); 21 | IList GetActivities(WorkFlowContext context, IControlAccess access = null); 22 | IList ListAreas(); 23 | IMatchCondition Match { get; set; } 24 | object Run(WorkFlowContext context, SearchMode mode, IVisitor visitor = null); 25 | string GetActivityDescription(string operation); 26 | WorkFlowContext GetContext(); 27 | WorkFlowContext SetNewEvaluator(IEvaluatorCommand evaluator); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /WorkFlow/Json/workflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "Conditions": [ 3 | { 4 | "Name": "SICK", 5 | "Parameters": [ 6 | { 7 | "Key": "TESTCONDITIONEQUAL", 8 | "Operator": "eq", 9 | "Value": [ "COLD" ] 10 | }, 11 | { 12 | "Key": "TESTCONDITIONLT", 13 | "Operator": "lt", 14 | "Value": [ "5" ] 15 | }, 16 | { 17 | "Key": "CUSTOM", 18 | "Operator": "ENDPOINT", 19 | "Value": [ "http://" ] 20 | }, 21 | { 22 | "Key": "TESTCONDITIONIN", 23 | "Operator": "in", 24 | "Value": [ "5", "8", "9" ] 25 | } 26 | ] 27 | }, 28 | { 29 | "Name": "SICKNOVALID", 30 | "Parameters": [ 31 | { 32 | "Key": "TESTCONDITIONEQUAL", 33 | "Operator": "eq", 34 | "Value": [ "COLD" ], 35 | "Message": "TESTCONDITION NOT EQUAL COLD" 36 | }, 37 | { 38 | "Key": "TESTCONDITIONLT", 39 | "Operator": "lt", 40 | "Value": [ "5" ], 41 | "Message": "TESTCONDITIONLT NOT BIGGER THAN 5" 42 | }, 43 | { 44 | "Key": "TESTCONDITIONIN", 45 | "Operator": "in", 46 | "Value": [ "5", "8", "9" ] 47 | } 48 | ] 49 | }, 50 | { 51 | "Name": "EXTINTION", 52 | "Parameters": [ 53 | { 54 | "Key": "Objective", 55 | "Value": [ "4", "3", "7", "5", "9", "8" ] 56 | } 57 | ] 58 | }, 59 | { 60 | "Name": "DESTRUCTION", 61 | "Parameters": [ 62 | { 63 | "Key": "Objective", 64 | "Value": [ 65 | "3" 66 | ] 67 | } 68 | ] 69 | }, 70 | { 71 | "Name": "EXPORTATION", 72 | "Parameters": [ 73 | { 74 | "Key": "Objective", 75 | "Value": [ 76 | "4", 77 | "8" 78 | ] 79 | } 80 | ] 81 | }, 82 | { 83 | "Name": "ES", 84 | "Parameters": [ 85 | { 86 | "Key": "Departament", 87 | "Value": [ 88 | "40" 89 | ] 90 | } 91 | ] 92 | }, 93 | { 94 | "Name": "EHPARTE", 95 | "Parameters": [ 96 | { 97 | "Key": "Parte", 98 | "Value": [ 99 | "True" 100 | ] 101 | } 102 | ] 103 | }, 104 | { 105 | "Name": "NAOMOVED", 106 | "Parameters": [ 107 | { 108 | "Key": "MOVED", 109 | "Value": [ 110 | "false" 111 | ] 112 | } 113 | ] 114 | } 115 | ], 116 | "WorkFlow": [ 117 | { 118 | "Id": 1, 119 | "SourceState": "None", 120 | "Transitions": [{ Operation:"CANCEL_ASKED", Description:"None" , "DestinyState": "CANCELASKEDPURCHASEASK"}, 121 | { Operation:"ATUALIZA_PURCHASEASK_CANCEL", Description:"None" , "DestinyState": "PURCHASEORDERCREATED"}, 122 | { Operation:"PURCHASEORDER_CHECK_MATERIAL", Description:"None" , "DestinyState": "ATCHECKING"}, 123 | { Operation:"LAST_ITEM_CANCELLED_PURCHASEASK", Description:"None" , "DestinyState": "CANCELLEDPURCHASEASK"}, 124 | { Operation:"ITEM_CANCELLED_PURCHASEORDER", Description:"None" , "DestinyState": "ATANALYSIS"}, 125 | { Operation:"CancelPURCHASEASK", Description:"None" , "DestinyState": "CANCELLEDPURCHASEASK"}, 126 | { Operation:"LAST_ITEM_CANCELLED_PURCHASEORDER", Description:"None" , "DestinyState": "CANCELLEDPURCHASEORDER"}, 127 | { Operation:"CANCEL_ASKED_PURCHASEORDER", Description:"None" , "DestinyState": "CANCELASKEDPURCHASEORDER"}], 128 | 129 | "Area": "Automatic" 130 | }, 131 | { 132 | "Id": 2, 133 | "SourceState": "All", 134 | "Transitions": [{ But:["CANCELLEDPURCHASEORDER", "FINISHED", "None"], Operation:"PURCHASEORDER_CANCEL", Description:"Cancel PURCHASEORDER" , "DestinyState": "CANCELLEDPURCHASEORDER"}], 135 | "Area": "AreaPURCHASEORDER" 136 | }, 137 | { 138 | "Id": 8, 139 | "SourceState": "WAITMOVEMENT", 140 | "Transitions": [{ Operation:"PURCHASEORDER_LET_CHECK", Description:"Disponibilizar para Vistoria" , "DestinyState": "ATCHECKING"}, 141 | { Operation:"ASSOCIATE_RT", Description:"Associate RT" , "DestinyState": "None"}], 142 | "Area": "AreaPURCHASEORDER" 143 | }, 144 | { 145 | "Id": 10, 146 | "SourceState": "WAITMOVEMENTDESTINY", 147 | "Transitions": [{ Condition:"!EXTINTION", Operation:"PURCHASEORDER_CONFIRM_ARRIVE_DESTINY", Description:"Confirm chegada" , "DestinyState": "WAITRETURN"}, 148 | { Condition: "EXTINTION", Operation:"PROTOCOLR_REQUIREMENT", Description:"Protocolar Requerimento" , "DestinyState": "PROTOCOLREQUIREMENT"}], 149 | "Area": "AreaPURCHASEORDER" 150 | }, 151 | { 152 | "Id": 11, 153 | "SourceState": "WAITRETURN", 154 | "Transitions": [{ Operation:"RETURN_CONFIRMED", Description:"Confirm Return" , "DestinyState": "RETURNCONFIRMED"}], 155 | "Area": "AreaPURCHASEORDER" 156 | }, 157 | { 158 | "Id": 16, 159 | "SourceState": "RETURNCONFIRMED", 160 | "Transitions": [{ Operation:"CONFIRM_FINISHED", Description:"Confirmation Finishing" , "DestinyState": "FINISHED"}], 161 | "Area": "AreaPURCHASEORDER" 162 | }, 163 | { 164 | "Id": 12, 165 | "SourceState": "WAITINGDESTRUCTION", 166 | "Transitions": [{ Operation:"DESTRUCTION_EFETUADA", Description:"Destruição Efetuada" , "DestinyState": "FINISHEDPROCESS"}], 167 | "Area": "AreaPURCHASEORDER" 168 | }, 169 | { 170 | "Id": 13, 171 | "SourceState": "WAITINGIDENTIFICATION", 172 | "Transitions": [{ Operation:"PURCHASEORDER_INFORMAR_APOIO_TECNICO", Description:"Informar apoio técnico" , "DestinyState": "ATCHECKING"}], 173 | "Area": "AreaPURCHASEORDER" 174 | }, 175 | { 176 | "Id": 14, 177 | "SourceState": "CANCELASKEDPURCHASEORDER", 178 | "Transitions": [{ Operation:"RETURN_FLOW_PURCHASEORDER", Description:"Indeferir Solicitação" , "DestinyState": "None"}], 179 | "Area": "AreaPURCHASEORDER" 180 | }, 181 | { 182 | "Id": 15, 183 | "SourceState": "DIFFERENT", 184 | "Transitions": [{ Operation:"PURCHASEORDER_INFORMAR_TRANSPORTE", Description:"Informar Justificativa" , "DestinyState": "MOVEMENTALLOWED"}, 185 | { Operation:"PURCHASEORDER_DIFFERENT_CHECK", Description:"Confirm Acerto" , "DestinyState": "ATCHECKING"}], 186 | 187 | "Area": "AreaPURCHASEORDER" 188 | }, 189 | { 190 | "Id": 18, 191 | "SourceState": "ATCHECKING", 192 | "Transitions": [{ Operation:"WAITING_IDENTIFICACAO", Description:"Ask Apoio Técnico" , "DestinyState": "WAITINGIDENTIFICATION"}, 193 | { Operation:"PURCHASEORDER_DIFFERENT_ALTER", Description:"Informar Divergência" , "DestinyState": "DIFFERENT"}, 194 | { Operation:"PURCHASEORDER_CHECK_MATERIAL", Description:"Concluir Vistoria" , "DestinyState": "WAITMOVEMENTDESTINY"} ], 195 | 196 | "Area": "AreaPURCHASEORDER" 197 | }, 198 | { 199 | "Id": 21, 200 | "SourceState": "MOVEMENTALLOWED", 201 | "Transitions": [{ Operation:"PURCHASEORDER_DESEMBARCAR_MATERIAL", Description:"Move Material" , "DestinyState": "WAITMOVEMENT"}, 202 | { Operation:"ASSOCIATE_RT", Description:"Associate RT" , "DestinyState": "None"}], 203 | 204 | "Area": "AreaPURCHASEORDER" 205 | }, 206 | { 207 | "Id": 23, 208 | "SourceState": "PURCHASEORDERANALYZINGREJECTION", 209 | "Transitions": [{ Operation:"PURCHASEORDER_PROTOCOLR_BUDGET", Description:"Protocolar na Receita" , "DestinyState": "PROTOCOLPURCHASEORDERBUDGET"}, 210 | { Operation:"PURCHASEORDER_CANCEL", Description:"Cancel PURCHASEORDER" , "DestinyState": "CANCELLEDPURCHASEORDER"}], 211 | 212 | "Area": "AreaPURCHASEORDER" 213 | }, 214 | { 215 | "Id": 25, 216 | "SourceState": "PURCHASEORDEREMITTED", 217 | "StateOrder": "Initial", 218 | "Transitions": [{ Operation:"PURCHASEORDER_PERMIT_DESEMBARQUE", Description:"Autorizar Movement" , "DestinyState": "MOVEMENTALLOWED"}, 219 | { Condition:"ES", Operation:"PURCHASEORDER_PROTOCOLR_BUDGET", Description:"Protocolar na Receita" , "DestinyState": "PROTOCOLPURCHASEORDERBUDGET"}], 220 | 221 | "Area": "AreaPURCHASEORDER" 222 | }, 223 | { 224 | "Id": 26, 225 | "SourceState": "PROTOCOLPURCHASEORDERBUDGET", 226 | "Transitions": [{ Operation:"PURCHASEORDER_INDEFERIR_BUDGET", Description:"Indeferir PURCHASEORDER na Receita" , "DestinyState": "PURCHASEORDERANALYZINGREJECTION"}, 227 | { Operation:"PURCHASEORDER_PERMIT_DESEMBARQUE", Description:"Autorizar Desembarque" , "DestinyState": "MOVEMENTALLOWED"}], 228 | 229 | "Area": "AreaPURCHASEORDER" 230 | }, 231 | { 232 | "Id": 30, 233 | "SourceState": "FINISHEDPROCESS", 234 | "Transitions": [{ Condition: "DESTRUCTION", Operation:"FINISH_DESTRUCTION", Description:"Encerrar Destruição" , "DestinyState": "FINISHED"}], 235 | 236 | "Area": "AreaPURCHASEORDER" 237 | }, 238 | { 239 | "Id": 31, 240 | "SourceState": "PROTOCOLREQUIREMENT", 241 | "Transitions": [{ Condition: "DESTRUCTION", Operation:"WAITR_DESTRUCTION", Description:"Aguardar Destruição" , "DestinyState": "WAITINGDESTRUCTION"}, 242 | { Condition: "!DESTRUCTION", Operation:"PURCHASEORDER_CONFIRM_ARRIVE_DESTINY", Description:"Confimar Chegada" , "DestinyState": "WAITRETURN"}], 243 | 244 | "Area": "AreaPURCHASEORDER" 245 | }, 246 | { 247 | "Id": 32, 248 | "SourceState": "WAITINGALLOW", 249 | "Transitions": [{ Operation:"EmitPURCHASEASK", Description:"Emit PURCHASEASK" , "DestinyState": "EMITTED"}, 250 | { Operation:"INDEFERIR_PURCHASEASK", Description:"Não Aprove PURCHASEASK" , "DestinyState": "ATREVISION"}], 251 | 252 | "Area": "AreaPURCHASEASK" 253 | }, 254 | { 255 | "Id": 33, 256 | "SourceState": "CANCELASKEDPURCHASEASK", 257 | "Transitions": [{ Operation:"INDEFERIR_PEDIDO_CANCELA_PURCHASEASK", Description:"Recusar Cancelling" , "DestinyState": "None"}], 258 | 259 | "Area": "AreaPURCHASEASK" 260 | }, 261 | { 262 | "Id": 34, 263 | "SourceState": "ATANALYSIS", 264 | "Transitions": [{ Operation:"ASSOCIATE_PURCHASEORDER", Description:"Associate PURCHASEORDER" , "DestinyState": "PURCHASEORDERCREATED"}, 265 | { Operation:"CorrectPURCHASEASK", Description:"Correct PURCHASEASK" , "DestinyState": "ATREVISION"}], 266 | 267 | "Area": "AreaPURCHASEASK" 268 | }, 269 | { 270 | "Id": 36, 271 | "SourceState": "ATDRAFT", 272 | "StateOrder": "Initial", 273 | "Transitions": [{ Operation:"AskAprovePURCHASEASK", Description:"Ask Aproving" , "DestinyState": "WAITINGALLOW"}, 274 | { Operation:"CancelDraft", Description:"Erase Draft" , "DestinyState": "None"}], 275 | 276 | "Area": "AreaPURCHASEASK" 277 | }, 278 | { 279 | "Id": 38, 280 | "SourceState": "ATREVISION", 281 | "Transitions": [{ Operation:"AskAprovePURCHASEASK", Description:"Ask Aproving" , "DestinyState": "WAITINGALLOW"}], 282 | 283 | "Area": "AreaPURCHASEASK" 284 | }, 285 | { 286 | "Id": 39, 287 | "SourceState": "EMITTED", 288 | "Transitions": [{ "Condition": "!EXPORTATION", Operation:"TakePURCHASEASK", Description:"Take PURCHASEASK" , "DestinyState": "ATANALYSIS"}, 289 | { "Condition": "EXPORTATION", Operation:"INICIO_ANALYSIS_EXPORTATION", Description:"Take PURCHASEASK" , "DestinyState": "ANALYSISPURCHASEASKEXPORTAÇÃO"}], 290 | 291 | "Area": "AreaPURCHASEASK" 292 | }, 293 | { 294 | "Id": 44, 295 | "SourceState": "All", 296 | "Transitions": [{ But:["ATDRAFT", "CANCELLEDPURCHASEASK", "CANCELASKEDPURCHASEASK", "PROCESSFINISHED", "None"], Operation:"SOLICITAR_CANCEL", Description:"Ask Cancelling" , "DestinyState": "CANCELASKEDPURCHASEASK"}], 297 | "Area": "AreaPURCHASEASK" 298 | }, 299 | { 300 | "Id": 40, 301 | "SourceState": "PURCHASEORDERCREATED", 302 | "Transitions": [{ Operation:"FINISH_PROCESS", Description:"Encerrando PURCHASEASK" , "DestinyState": "PROCESSFINISHED"}], 303 | 304 | "Area": "AreaPURCHASEASK" 305 | }, 306 | { 307 | "Id": 41, 308 | "SourceState": "WAITINGQUESTIONÁRIO", 309 | "Transitions": [{"Condition": "EXPORTATION", Operation:"RETURN_ANALYSIS_REXPORTATION", Description:"Questionario Preenchido" , "DestinyState": "ANALYSISPURCHASEASKEXPORTAÇÃO"}], 310 | 311 | "Area": "AreaPURCHASEASK" 312 | }, 313 | { 314 | "Id": 42, 315 | "SourceState": "ANALYSISPURCHASEASKEXPORTAÇÃO", 316 | "Transitions": [{ "Condition": "EXPORTATION", Operation:"RETURN_ANALYSIS", Description:"Retornar Análise" , "DestinyState": "ATANALYSIS"}, 317 | { "Condition": "EXPORTATION", Operation:"AGUADAR_QUESTIONARY", Description:"Enviar Questionario" , "DestinyState": "WAITINGQUESTIONÁRIO"}], 318 | 319 | "Area": "AreaPURCHASEASK" 320 | }, 321 | { 322 | "Id": 46, 323 | "Condition": null, 324 | "SourceState": "All", 325 | "Transitions": [{ "But": ["EMITTED","WAITINGALLOW","PURCHASEORDERCREATED", "None"], Operation:"ALTER_ITEM_PURCHASEASK", Description:"Alterar Item" , "DestinyState": "None"}, 326 | { "But": ["ATDRAFT","EMITTED","WAITINGALLOW","PURCHASEORDERCREATED", "None"], "DestinyState": "None", "Operation": "CANCEL_ITEM_PURCHASEASK", "Description": "Cancel Item" } ], 327 | 328 | "Area": "GridPURCHASEASK" 329 | }, 330 | { 331 | "Id": 47, 332 | "SourceState": "ATDRAFT", 333 | "Transitions": [{ Operation:"EXCLUDE_ITEM_PURCHASEASK", Description:"Exclude Item" , "DestinyState": "None"}], 334 | 335 | "Area": "GridPURCHASEASK" 336 | }, 337 | { 338 | "Id": 48, 339 | "SourceState": "All", 340 | "Transitions": [{ Condition:"EHPARTE" ,But:["CANCELLEDPURCHASEORDER", "FINISHED"] , Operation:"ALTER_ITEM_PURCHASEORDER", Description:"Update Item" , "DestinyState": "None"}, 341 | { Condition:"NAOMOVED" ,But:["CANCELLEDPURCHASEORDER", "FINISHED"] , Operation:"CANCEL_ITEM_PURCHASEORDER", Description:"Cancel Item" , "DestinyState": "None"}], 342 | 343 | "Area": "GridPURCHASEORDER" 344 | }, 345 | { 346 | "Id": 49, 347 | "SourceState": "All", 348 | "Transitions": [ 349 | { 350 | "But": [ 351 | "WAITMOVEMENT", 352 | "WAITINGIDENTIFICATION", 353 | "CANCELASKEDPURCHASEORDER", 354 | "DIFFERENT", 355 | "ATCHECKING", 356 | "MOVEMENTALLOWED", 357 | "PURCHASEORDERANALYZINGREJECTION", 358 | "PURCHASEORDEREMITTED", 359 | "PROTOCOLPURCHASEORDERBUDGET", 360 | "FINISHED", 361 | "CANCELLEDPURCHASEORDER", 362 | "None" 363 | ], 364 | "DestinyState": "None", 365 | "Operation": "RELEASE_MOVIMENTACAO", 366 | "Description": "Move Itens" 367 | }, 368 | 369 | { 370 | Condition: "EXTINTION", 371 | "But": [ 372 | "WAITMOVEMENT", 373 | "WAITINGIDENTIFICATION", 374 | "CANCELASKEDPURCHASEORDER", 375 | "DIFFERENT", 376 | "ATCHECKING", 377 | "MOVEMENTALLOWED", 378 | "PURCHASEORDERANALYZINGREJECTION", 379 | "PURCHASEORDEREMITTED", 380 | "PROTOCOLPURCHASEORDERBUDGET", 381 | "FINISHED", 382 | "CANCELLEDPURCHASEORDER", 383 | "None" 384 | ], 385 | "DestinyState": "None", 386 | "Operation": "RELEASE_EXTINTION", 387 | "Description": "Extinguish Itens" 388 | } 389 | 390 | ], 391 | 392 | "Area": "PURCHASEORDEROperation" 393 | }, 394 | { 395 | "Id": 65, 396 | "SourceState": "INITIAL", 397 | "StateOrder": "Initial", 398 | "Transitions": [ 399 | { 400 | "Operation": "DONTMAKEEFFORT", 401 | "Description": "Dont make effort", 402 | "DestinyState": "TIRED" 403 | }, 404 | { 405 | "Condition": "SICK", 406 | "Operation": "MAKE EFFORT", 407 | "Description": "MAKE EFFORT", 408 | "DestinyState": "WILLING" 409 | } 410 | ], 411 | 412 | "Area": "TESTCONDITIONSICK" 413 | }, 414 | { 415 | "Id": 66, 416 | "SourceState": "INITIAL", 417 | "StateOrder": "Initial", 418 | "Transitions": [ 419 | { 420 | "Operation": "DONTMAKEEFFORT", 421 | "Description": "Dont make effort", 422 | "DestinyState": "TIRED" 423 | }, 424 | { 425 | "Condition": "SICKNOVALID", 426 | "Operation": "MAKEEFFORT", 427 | "Description": "MAKE EFFORT", 428 | "DestinyState": "WILLING" 429 | } 430 | ], 431 | 432 | "Area": "TESTCONDITIONSICKNOVALID" 433 | } 434 | ] 435 | } 436 | -------------------------------------------------------------------------------- /WorkFlow/Movimentacao/WorkFlowImpl.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/WorkFlow/Movimentacao/WorkFlowImpl.cs -------------------------------------------------------------------------------- /WorkFlow/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WorkFlow")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Petrobras")] 12 | [assembly: AssemblyProduct("WorkFlow")] 13 | [assembly: AssemblyCopyright("Copyright © Petrobras 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("217a952b-8b57-4269-9e71-2d511dc76c38")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.8.0.0")] 36 | [assembly: AssemblyFileVersion("1.8.0.0")] 37 | -------------------------------------------------------------------------------- /WorkFlow/Singleton/WorkFlowSingleton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Newtonsoft.Json; 7 | using WorkFlow.Entities; 8 | using WorkFlow.DAO; 9 | using WorkFlow.Configuration; 10 | using WorkFlow.Exceptions; 11 | 12 | namespace WorkFlow.Singleton 13 | { 14 | public class WorkFlowSingleton 15 | { 16 | private static WorkFlowSingleton _instance; 17 | private Structure structure; 18 | private IDAO dalc = (IDAO)Activator.CreateInstance(WorkFlowConfiguration.Binder.GetRepository()); 19 | private static object syncRoot = new Object(); 20 | 21 | private WorkFlowSingleton() 22 | { 23 | string json = dalc.GetJson(); 24 | structure = JsonConvert.DeserializeObject(json); 25 | WorkFlowConfiguration.Binder.Setting.Validator.Validate(structure); 26 | } 27 | 28 | public static WorkFlowSingleton Instance() 29 | { 30 | if (_instance == null) 31 | { 32 | lock (syncRoot) 33 | { 34 | if (_instance == null) 35 | _instance = new WorkFlowSingleton(); 36 | } 37 | } 38 | 39 | return _instance; 40 | } 41 | 42 | public static void DestroyInstance() 43 | { 44 | _instance = null; 45 | } 46 | 47 | public Structure GetStructure() 48 | { 49 | return structure; 50 | } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /WorkFlow/Utils/WorkFlowUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | 7 | namespace WorkFlow.Utils 8 | { 9 | public static class WorkFlowUtils 10 | { 11 | internal static IEnumerable BinaryToStrings(byte[] data, int maxStringLength) 12 | { 13 | var buffer = new char[maxStringLength]; 14 | 15 | using (MemoryStream stream = new MemoryStream(data)) 16 | using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) 17 | { 18 | while (true) 19 | { 20 | int count = reader.Read(buffer, 0, maxStringLength); 21 | 22 | if (count == 0) 23 | { 24 | break; 25 | } 26 | 27 | yield return new string(buffer, 0, count); 28 | } 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WorkFlow/Validation/IValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Entities; 6 | 7 | namespace WorkFlow.Validation 8 | { 9 | public interface IValidator 10 | { 11 | void Validate(Structure structure); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WorkFlow/Validation/ValidationResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WorkFlow.Entities; 7 | 8 | namespace WorkFlow.Validation 9 | { 10 | public class ValidationResult 11 | { 12 | public Condition Condition { get; set; } 13 | public Evaluate Parameter { get; set; } 14 | 15 | public ValidationResult(Condition condition, Evaluate parameter) 16 | { 17 | this.Condition = condition; 18 | this.Parameter = parameter; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WorkFlow/Validation/ValidatorDefault.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Exceptions; 6 | 7 | namespace WorkFlow.Validation 8 | { 9 | internal class ValidatorDefault : IValidator 10 | { 11 | public void Validate(Entities.Structure structure) 12 | { 13 | ValidateDuplicatedId(structure); 14 | 15 | ValidateDuplicatedSourceAndArea(structure); 16 | 17 | ValidateDuplicatedConditions(structure); 18 | } 19 | 20 | private void ValidateDuplicatedConditions(Entities.Structure structure) 21 | { 22 | var totalgrouped = structure.Conditions 23 | .GroupBy(x => x.Name) 24 | .Where(grp => grp.Count() > 1) 25 | .Select(x => new { Key = x.Key, List = x.ToList() }); 26 | 27 | foreach (var item in totalgrouped) 28 | { 29 | string message = item.Key.ToString(); 30 | throw new DuplicatedNodeException(string.Format("There are duplicated entries for Condition: {0}", message)); 31 | } 32 | } 33 | 34 | private void ValidateDuplicatedId(Entities.Structure structure) 35 | { 36 | var totalgrouped = structure.WorkFlow 37 | .GroupBy(x => x.Id) 38 | .Where(grp => grp.Count() > 1) 39 | .Select(x => new { Key = x.Key, List = x.ToList() }); 40 | 41 | foreach (var item in totalgrouped) 42 | { 43 | string message = item.Key.ToString(); 44 | throw new DuplicatedNodeException(string.Format("There are duplicated entries for Id: {0}", message)); 45 | } 46 | } 47 | 48 | private void ValidateDuplicatedSourceAndArea(Entities.Structure structure) 49 | { 50 | var totalgrouped = structure.WorkFlow 51 | .GroupBy(x => new { x.Area, x.SourceState }) 52 | .Where(grp => grp.Count() > 1) 53 | .Select(x => new { Key = x.Key, List = x.ToList() }); 54 | 55 | foreach (var item in totalgrouped) 56 | { 57 | string message = string.Join(",", item.List.Select(x => x.Id).ToList()); 58 | throw new DuplicatedNodeException(string.Format("There are duplicated entries for Ids: {0}", message)); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /WorkFlow/Visitors/DefaultVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Visitors 7 | { 8 | public class DefaultVisitor : IVisitor 9 | { 10 | 11 | private IList transitions = new List(); 12 | 13 | public virtual void Visit(string status, Entities.Activity activity, string newstatus) 14 | { 15 | transitions.Add(string.Format("{0}=={1}==>{2}", status, activity.Operation, newstatus)); 16 | } 17 | 18 | public virtual object EndVisit() 19 | { 20 | return transitions; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WorkFlow/Visitors/IVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WorkFlow.Visitors 7 | { 8 | public interface IVisitor 9 | { 10 | void Visit(string status, Entities.Activity activity, string newstatus); 11 | object EndVisit(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WorkFlow/WorkFlow.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {BAC6D2B4-8F6F-4B9A-9E6B-C245B31AE43F} 9 | Library 10 | Properties 11 | WorkFlow 12 | LightWorkFlow 13 | v4.5.1 14 | 512 15 | SAK 16 | SAK 17 | SAK 18 | SAK 19 | 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | false 30 | 31 | 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | false 39 | 40 | 41 | false 42 | 43 | 44 | 45 | 46 | 47 | 48 | bin\TESTE\ 49 | TRACE 50 | true 51 | pdbonly 52 | AnyCPU 53 | bin\Release\WorkFlow.dll.CodeAnalysisLog.xml 54 | true 55 | GlobalSuppressions.cs 56 | prompt 57 | MinimumRecommendedRules.ruleset 58 | ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets 59 | true 60 | ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules 61 | true 62 | false 63 | false 64 | 65 | 66 | bin\DESENVOLVIMENTO\ 67 | false 68 | 69 | 70 | 71 | ..\packages\Newtonsoft.Json.6.0.1\lib\net40\Newtonsoft.Json.dll 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 140 | -------------------------------------------------------------------------------- /WorkFlow/WorkFlow.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /WorkFlow/WorkflowService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Classificador; 3 | 4 | namespace Workflow 5 | { 6 | public class WorkflowService 7 | { 8 | public WorkflowService() 9 | { 10 | 11 | } 12 | 13 | public Boolean ExecutaWorkflowEncerramento(IClassificador classe, string estadoAtual, string fato) 14 | { 15 | //PermissaoTrabalhoFato ptf = new PermissaoTrabalhoFato(classe); 16 | 17 | //return ptf.EncerrarPT(entidade, fato); 18 | return true; 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WorkFlow/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /WorkFlowClient/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /WorkFlowClient/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WorkFlow; 7 | using WorkFlow.Business.Search; 8 | using WorkFlow.ConcreteCondition; 9 | using WorkFlow.Configuration; 10 | using WorkFlow.Context; 11 | using WorkFlow.DAO; 12 | using WorkFlow.Entities; 13 | using WorkFlow.Impl; 14 | using WorkFlow.Validation; 15 | using WorkFlow.Visitors; 16 | 17 | namespace WorkFlowClient 18 | { 19 | class Program 20 | { 21 | static void Main(string[] args) 22 | { 23 | //put this line in a global.asax for web 24 | WorkFlowConfiguration.Binder.SetRepository(typeof(DAOEmbeddedResource)) 25 | .Setup(x => x.TypeName, "WorkFlow.Json.workflow.json , LightWorkFlow"); 26 | 27 | IWorkFlow work = WorkFlowManager.GetManager();//getting instance of workflow. 28 | 29 | /* 30 | { 31 | "Id": 36, 32 | "SourceState": "ATDRAFT", 33 | "StateOrder": "Initial", 34 | "Transitions": [{ Operation:"AskAprovePURCHASEASK", Description:"Ask Aproving" , "DestinyState": "WAITINGALLOW"}, 35 | { Operation:"CancelDraft", Description:"Erase Draft" , "DestinyState": "None"}], 36 | 37 | "Area": "AreaPURCHASEASK" 38 | }, 39 | */ 40 | //1) Getting Initial State 41 | 42 | string initialstate = work.GetInitialStatus("AreaPURCHASEASK");//ATDRAFT 43 | //====================================================================================================== 44 | //2) listing operations that can be done from a specific state. 45 | 46 | WorkFlowContext workoperation = work.GetContext() 47 | .SetArea("AreaPURCHASEASK") 48 | .SetSourceState("ATDRAFT"); 49 | 50 | IList operations = work.GetActivities(workoperation);//AskAprovePURCHASEASK, CancelDraft 51 | 52 | string description = work.GetActivityDescription("AskAprovePURCHASEASK");//Ask Aproving 53 | //======================================================================================================= 54 | //3) Get Next Status 55 | 56 | WorkFlowContext workgetnextstatus = work.GetContext() 57 | .SetArea("AreaPURCHASEASK") 58 | .SetSourceState("ATDRAFT") 59 | .SetOperation("AskAprovePURCHASEASK"); 60 | 61 | string nextstatus = work.GetNextStatus(workgetnextstatus);//WAITINGALLOW 62 | //======================================================================================================== 63 | //4)Runner - walk throughout workflow in depth and breadth 64 | 65 | //setting area and initial state from which runner will start to look at. 66 | WorkFlowContext workc = work.GetContext() 67 | .SetArea("AreaPURCHASEASK") 68 | .SetSourceState("ATDRAFT"); 69 | 70 | var depth = work.Run(workc, SearchMode.Depth);//all transitions printed in a depth search mode. 71 | 72 | work.GetContext() 73 | .SetArea("AreaPURCHASEASK") 74 | .SetSourceState("ATDRAFT"); 75 | 76 | var breadth = (IList)work.Run(workc, SearchMode.Breadth);//all transitions printed in a breadth search mode. 77 | 78 | 79 | //4.1 configuring visitor 80 | 81 | WorkFlowContext workvisitor = work.GetContext() 82 | .SetArea("AreaPURCHASEASK") 83 | .SetSourceState("ATDRAFT"); 84 | 85 | var workvisitordepth = work.Run(workc, SearchMode.Depth, new CustomVisitor());//ok 86 | 87 | //======================================================================================================== 88 | //5) setting conditions 89 | /* 90 | * { 91 | "Name": "EXTINTION", 92 | "Parameters": [ 93 | { 94 | "Key": "Objective", 95 | "Value": [ 96 | "4", 97 | "3", 98 | "7", 99 | "5", 100 | "9", 101 | "8" 102 | ] 103 | } 104 | ] 105 | }, 106 | { 107 | "Id": 10, 108 | "SourceState": "WAITMOVEMENTDESTINY", 109 | "Transitions": [{ Condition:"!EXTINTION", Operation:"PURCHASEORDER_CONFIRM_ARRIVE_DESTINY", Description:"Confirm chegada" , "DestinyState": "WAITRETURN"}, 110 | { Condition: "EXTINTION", Operation:"PROTOCOLR_REQUIREMENT", Description:"Protocolar Requerimento" , "DestinyState": "PROTOCOLREQUIREMENT"}], 111 | "Area": "AreaPURCHASEORDER" 112 | }, 113 | */ 114 | 115 | WorkFlowContext workoperationcond = work.GetContext() 116 | .SetArea("AreaPURCHASEORDER") 117 | .SetSourceState("WAITMOVEMENTDESTINY"); 118 | 119 | workoperationcond["Objective"] = new List { "4" }; 120 | 121 | IList operationsExtintion = work.GetActivities(workoperationcond); 122 | //PROTOCOLR_REQUIREMENT,PURCHASEORDER_CANCEL 123 | 124 | workoperationcond["Objective"] = new List { "1" }; 125 | 126 | IList operationsNoExtintion = work.GetActivities(workoperationcond); 127 | //PURCHASEORDER_CONFIRM_ARRIVE_DESTINY,PURCHASEORDER_CANCEL 128 | 129 | 130 | //PURCHASEORDER_CANCEL shows up here because SourceState is configured with "All" in the area "AreaPURCHASEORDER". 131 | //if you dont want this operation shows up in a set of states, use "But" inside operation. 132 | 133 | //6) Setting a new condition match class 134 | 135 | WorkFlowContext context = new WorkFlowContext { 136 | Area = "AreaPURCHASEORDER", 137 | Operation = "PURCHASEORDER_CONFIRM_ARRIVE_DESTINY", 138 | SourceState = "WAITMOVEMENTDESTINY" 139 | }.SetCondition(typeof(NewMatch)); 140 | 141 | context["Objective"] = new List { "2" }; 142 | 143 | string state = work.GetNextStatus(context); 144 | } 145 | } 146 | 147 | public class NewMatch : MatchCondition 148 | { 149 | public override bool CheckConditions(string condition, WorkFlowContext context, IList results = null) 150 | { 151 | if (condition == null) return true; 152 | 153 | if (condition.StartsWith("!")) 154 | { 155 | Condition cond = GetNode().Conditions.Where(x => x.Name.Equals(condition.Substring(1))).FirstOrDefault(); 156 | return !CheckParameters(context, cond, results); 157 | } 158 | else 159 | { 160 | Condition cond = GetNode().Conditions.Where(x => x.Name.Equals(condition)).FirstOrDefault(); 161 | return CheckParameters(context, cond, results); 162 | } 163 | } 164 | } 165 | 166 | public class CustomVisitor : IVisitor 167 | { 168 | public void Visit(string status, Activity activity, string newstatus) 169 | { 170 | Console.WriteLine(string.Format("{0}==>{1}==>{2}", status, activity.Description, newstatus)); 171 | } 172 | 173 | public object EndVisit() 174 | { 175 | return "ok"; 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /WorkFlowClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WorkFlowClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("WorkFlowClient")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c767b3c2-74de-411c-aad0-abd8bacdcb2f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /WorkFlowClient/WorkFlowClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F546445F-1FCD-4442-ACA1-2F7E932A8286} 8 | Exe 9 | Properties 10 | WorkFlowClient 11 | WorkFlowClient 12 | v4.5.1 13 | 512 14 | SAK 15 | SAK 16 | SAK 17 | SAK 18 | 19 | 20 | 21 | AnyCPU 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | AnyCPU 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | {bac6d2b4-8f6f-4b9a-9e6b-c245b31ae43f} 58 | WorkFlow 59 | 60 | 61 | 62 | 69 | -------------------------------------------------------------------------------- /WorkFlowClient/WorkFlowClient.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /WorkFlowTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WorkFlowTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("WorkFlowTest")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("dc242900-bca4-4e44-821f-478058a861d5")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /WorkFlowTest/Visitor/ListVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WorkFlow.Visitors; 6 | using System.IO; 7 | 8 | namespace WorkFlowTest.Visitor 9 | { 10 | public class ListVisitor : IVisitor 11 | { 12 | private IList transitions = new List(); 13 | 14 | public ListVisitor() 15 | { 16 | 17 | } 18 | 19 | public void Visit(string status, WorkFlow.Entities.Activity activity, string newstatus) 20 | { 21 | string transition = string.Format("{0}--[{1}]-->{2} ", status, activity.Description, newstatus); 22 | transitions.Add(transition); 23 | } 24 | 25 | public object EndVisit() 26 | { 27 | return transitions; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /WorkFlowTest/WorkFlowTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using WorkFlow; 5 | using WorkFlow.Entities; 6 | using System.Linq; 7 | using WorkFlow.Exceptions; 8 | using System.IO; 9 | using WorkFlowTest.Visitor; 10 | using WorkFlow.Business.BusinessProcess; 11 | using WorkFlow.Business.Search; 12 | using WorkFlow.Context; 13 | using WorkFlow.DAO; 14 | using WorkFlow.Configuration; 15 | using WorkFlow.Impl; 16 | using WorkFlow.Visitors; 17 | using WorkFlow.Command; 18 | 19 | namespace WorkFlowTest 20 | { 21 | [TestClass] 22 | public class WorkFlowTest 23 | { 24 | private static IWorkFlow work; 25 | 26 | [ClassInitialize] 27 | public static void Initialize(TestContext context) 28 | { 29 | WorkFlowConfiguration.Binder.SetRepository(typeof(DAOEmbeddedResource)) 30 | .Setup(x => x.TypeName, "WorkFlow.Json.workflow.json , LightWorkFlow"); 31 | 32 | work = WorkFlowManager.GetManager(); 33 | } 34 | 35 | [TestMethod] 36 | public void GeInitialStatus() 37 | { 38 | string initial = work.GetInitialStatus("AreaPURCHASEASK"); 39 | Assert.AreEqual("ATDRAFT", initial); 40 | } 41 | 42 | [TestMethod] 43 | public void GetNextStatus() 44 | { 45 | WorkFlowContext context = work.GetContext().SetArea("AreaPURCHASEASK") 46 | .SetOperation("AskAprovePURCHASEASK") 47 | .SetSourceState("ATDRAFT"); 48 | string status = work.GetNextStatus(context); 49 | Assert.AreEqual("WAITINGALLOW", status); 50 | } 51 | 52 | [TestMethod] 53 | public void GetNextStatusWithAll() 54 | { 55 | WorkFlowContext context = work.GetContext().SetArea("AreaPURCHASEASK") 56 | .SetOperation("SOLICITAR_CANCEL") 57 | .SetSourceState("EMITTED"); 58 | 59 | context["Objective"] = new List { "2" };//deposito 60 | context["Departament"] = new List { "1" }; 61 | string status = work.GetNextStatus(context); 62 | Assert.AreEqual("CANCELASKEDPURCHASEASK", status); 63 | } 64 | 65 | [TestMethod] 66 | public void GetAtivities() 67 | { 68 | WorkFlowContext context = work.GetContext().SetArea("AreaPURCHASEASK") 69 | .SetSourceState("ATDRAFT"); 70 | IList act = work.GetActivities(context); 71 | Assert.AreEqual(2, act.Count); 72 | } 73 | 74 | /// 75 | /// Testando os status automáticos 76 | /// 77 | [TestMethod] 78 | public void GetDestinyWithNoOrigin() 79 | { 80 | WorkFlowContext context = work.GetContext().Reset().SetArea("Automatic") 81 | .SetOperation("LAST_ITEM_CANCELLED_PURCHASEASK"); 82 | 83 | string destiny = work.GetNextStatus(context); 84 | Assert.AreEqual("CANCELLEDPURCHASEASK", destiny); 85 | } 86 | 87 | [TestMethod] 88 | public void GetAtivitiesGrid() 89 | { 90 | work.GetContext().AddElements("ATDRAFT", "GridPURCHASEASK"); 91 | IList act = work.GetActivities(work.GetContext()); 92 | Assert.AreEqual(2, act.Count); 93 | Assert.IsTrue(act.Any(x => x.Operation.Equals("ALTER_ITEM_PURCHASEASK"))); 94 | Assert.IsTrue(act.Any(x => x.Operation.Equals("EXCLUDE_ITEM_PURCHASEASK"))); 95 | 96 | work.GetContext().SetSourceState("EMITTED"); 97 | IList emitido = work.GetActivities(work.GetContext()); 98 | Assert.AreEqual(0, emitido.Count); 99 | 100 | work.GetContext().SetSourceState("ATANALYSIS"); 101 | IList analise = work.GetActivities(work.GetContext()); 102 | Assert.AreEqual(2, analise.Count); 103 | Assert.IsTrue(analise.Any(x => x.Operation.Equals("ALTER_ITEM_PURCHASEASK"))); 104 | Assert.IsTrue(analise.Any(x => x.Operation.Equals("CANCEL_ITEM_PURCHASEASK"))); 105 | } 106 | 107 | [TestMethod] 108 | public void CheckConditionsKeyAndAtLeastOneValueMatch() 109 | { 110 | WorkFlowContext context = work.GetContext(); 111 | context["Objective"] = new List { "3" };//destruction 112 | context["Departament"] = new List { "1" }; 113 | Assert.IsTrue(context.Match.CheckConditions("DESTRUCTION", context)); 114 | } 115 | 116 | [TestMethod] 117 | public void CheckConditionsKeyNotMatch() 118 | { 119 | WorkFlowContext context = work.GetContext(); 120 | 121 | context["Objective"] = new List { "2" };//deposito 122 | context["Departament"] = new List { "1" }; 123 | Assert.IsFalse(context.Match.CheckConditions("DESTRUCTION", context)); 124 | } 125 | 126 | [TestMethod] 127 | public void CheckConditionsKeyMatchButValueDoesnt() 128 | { 129 | WorkFlowContext context = work.GetContext(); 130 | context["Objective"] = new List { "2" };//deposito 131 | context["Departament"] = new List { "1" }; 132 | Assert.IsFalse(context.Match.CheckConditions("EXTINTION", context)); 133 | } 134 | 135 | [TestMethod] 136 | public void SameOriginForDifferentConditions() 137 | { 138 | WorkFlowContext context = work.GetContext(); 139 | context.AddElements("EMITTED", "AreaPURCHASEASK"); 140 | context["Objective"] = new List { "4" };//deposito 141 | context["Departament"] = new List { "1" }; 142 | IList lista = work.GetActivities(context); 143 | Assert.IsTrue(lista.Count == 2 && lista.Any(x => x.Operation.Equals("INICIO_ANALYSIS_EXPORTATION"))); 144 | /*testing another condition*/ 145 | 146 | WorkFlowContext context2 = work.GetContext(); 147 | context2.AddElements("EMITTED", "AreaPURCHASEASK"); 148 | context2["Objective"] = new List { "2" };//deposito 149 | context2["Departament"] = new List { "1" }; 150 | IList atividades = work.GetActivities(context2); 151 | Assert.IsTrue(atividades.Count == 2 && atividades.Any(x => x.Operation.Equals("TakePURCHASEASK"))); 152 | } 153 | 154 | [TestMethod] 155 | public void ConditionAndStatusAllTogetherWithStatusInBut() 156 | { 157 | WorkFlowContext context = work.GetContext().AddElements("WAITMOVEMENT", "PURCHASEORDEROperation"); 158 | context["Objective"] = new List { "2" };//deposito 159 | context["Departament"] = new List { "1" }; 160 | IList lista = work.GetActivities(context); 161 | Assert.AreEqual(0, lista.Count); 162 | } 163 | 164 | [TestMethod] 165 | public void ConditionAndStatusAllTogetherStatusNotInBut() 166 | { 167 | WorkFlowContext context = work.GetContext().AddElements("WAITMOVEMENTDESTINY", "PURCHASEORDEROperation"); 168 | context["Objective"] = new List { "2" };//deposito 169 | context["Departament"] = new List { "1" }; 170 | IList lista = work.GetActivities(context); 171 | Assert.IsTrue(lista.Count == 1 && lista.Any(x => x.Operation.Equals("RELEASE_MOVIMENTACAO"))); 172 | } 173 | 174 | [TestMethod] 175 | public void ConditionMatchAndStatusAllTogetherStatusNotInBut() 176 | { 177 | WorkFlowContext context = work.GetContext().AddElements("WAITMOVEMENTDESTINY", "PURCHASEORDEROperation"); 178 | context["Objective"] = new List { "3" };//destruction 179 | context["Departament"] = new List { "1" }; 180 | IList lista = work.GetActivities(context); 181 | Assert.IsTrue(lista.Count == 2 && lista.Any(x => x.Operation.Equals("RELEASE_EXTINTION"))); 182 | } 183 | 184 | [TestMethod] 185 | public void PrintPURCHASEORDERParaDeposit() 186 | { 187 | WorkFlowContext context = work.GetContext().AddElements("PURCHASEORDEREMITTED", "AreaPURCHASEORDER"); 188 | context["Objective"] = new List { "2" };//deposito 189 | context["Departament"] = new List { "2" }; 190 | 191 | var lista = (List)work.Run(context, SearchMode.Depth, new ListVisitor()); 192 | string transicoes = string.Join(",", lista.ToArray()); 193 | Assert.AreEqual("PURCHASEORDEREMITTED--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,PURCHASEORDEREMITTED--[Autorizar Movement]-->MOVEMENTALLOWED ,MOVEMENTALLOWED--[Associate RT]-->None ,MOVEMENTALLOWED--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,MOVEMENTALLOWED--[Move Material]-->WAITMOVEMENT ,WAITMOVEMENT--[Associate RT]-->None ,WAITMOVEMENT--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,WAITMOVEMENT--[Disponibilizar para Vistoria]-->ATCHECKING ,ATCHECKING--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,ATCHECKING--[Concluir Vistoria]-->WAITMOVEMENTDESTINY ,WAITMOVEMENTDESTINY--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,WAITMOVEMENTDESTINY--[Confirm chegada]-->WAITRETURN ,WAITRETURN--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,WAITRETURN--[Confirm Return]-->RETURNCONFIRMED ,RETURNCONFIRMED--[Confirmation Finishing]-->FINISHED ,RETURNCONFIRMED--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,ATCHECKING--[Informar Divergência]-->DIFFERENT ,DIFFERENT--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,DIFFERENT--[Confirm Acerto]-->ATCHECKING ,ATCHECKING--[Ask Apoio Técnico]-->WAITINGIDENTIFICATION ,WAITINGIDENTIFICATION--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,WAITINGIDENTIFICATION--[Informar apoio técnico]-->ATCHECKING ,DIFFERENT--[Informar Justificativa]-->MOVEMENTALLOWED ", transicoes); 194 | } 195 | 196 | [TestMethod] 197 | public void PrintPURCHASEORDERParaDestruction() 198 | { 199 | WorkFlowContext context = work.GetContext().AddElements("PURCHASEORDEREMITTED", "AreaPURCHASEORDER"); 200 | context["Objective"] = new List { "3" };//destruction 201 | context["Departament"] = new List { "2" }; 202 | 203 | var lista = (List)work.Run(context, SearchMode.Breadth, new ListVisitor()); 204 | string transicoes = string.Join(",", lista.ToArray()); 205 | Assert.AreEqual("PURCHASEORDEREMITTED--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,PURCHASEORDEREMITTED--[Autorizar Movement]-->MOVEMENTALLOWED ,MOVEMENTALLOWED--[Associate RT]-->None ,MOVEMENTALLOWED--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,MOVEMENTALLOWED--[Move Material]-->WAITMOVEMENT ,WAITMOVEMENT--[Associate RT]-->None ,WAITMOVEMENT--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,WAITMOVEMENT--[Disponibilizar para Vistoria]-->ATCHECKING ,ATCHECKING--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,ATCHECKING--[Concluir Vistoria]-->WAITMOVEMENTDESTINY ,ATCHECKING--[Informar Divergência]-->DIFFERENT ,ATCHECKING--[Ask Apoio Técnico]-->WAITINGIDENTIFICATION ,WAITMOVEMENTDESTINY--[Protocolar Requerimento]-->PROTOCOLREQUIREMENT ,WAITMOVEMENTDESTINY--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,DIFFERENT--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,DIFFERENT--[Confirm Acerto]-->ATCHECKING ,DIFFERENT--[Informar Justificativa]-->MOVEMENTALLOWED ,WAITINGIDENTIFICATION--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,WAITINGIDENTIFICATION--[Informar apoio técnico]-->ATCHECKING ,PROTOCOLREQUIREMENT--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,PROTOCOLREQUIREMENT--[Aguardar Destruição]-->WAITINGDESTRUCTION ,WAITINGDESTRUCTION--[Destruição Efetuada]-->FINISHEDPROCESS ,WAITINGDESTRUCTION--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ,FINISHEDPROCESS--[Encerrar Destruição]-->FINISHED ,FINISHEDPROCESS--[Cancel PURCHASEORDER]-->CANCELLEDPURCHASEORDER ", transicoes); 206 | } 207 | 208 | 209 | 210 | [TestMethod] 211 | public void PrintPURCHASEASKParaReexportation() 212 | { 213 | WorkFlowContext context = work.GetContext().AddElements("ATDRAFT", "AreaPURCHASEASK"); 214 | context["Objective"] = new List { "4" };//Reexportation 215 | context["Departament"] = new List { "2" }; 216 | 217 | var lista = (List)work.Run(context, SearchMode.Depth, new ListVisitor()); 218 | string transicoes = string.Join(",", lista.ToArray()); 219 | Assert.AreEqual("ATDRAFT--[Ask Aproving]-->WAITINGALLOW ,WAITINGALLOW--[Emit PURCHASEASK]-->EMITTED ,EMITTED--[Take PURCHASEASK]-->ANALYSISPURCHASEASKEXPORTAÇÃO ,ANALYSISPURCHASEASKEXPORTAÇÃO--[Enviar Questionario]-->WAITINGQUESTIONÁRIO ,WAITINGQUESTIONÁRIO--[Questionario Preenchido]-->ANALYSISPURCHASEASKEXPORTAÇÃO ,ANALYSISPURCHASEASKEXPORTAÇÃO--[Retornar Análise]-->ATANALYSIS ,ATANALYSIS--[Associate PURCHASEORDER]-->PURCHASEORDERCREATED ,PURCHASEORDERCREATED--[Encerrando PURCHASEASK]-->PROCESSFINISHED ,PURCHASEORDERCREATED--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,CANCELASKEDPURCHASEASK--[Recusar Cancelling]-->None ,ATANALYSIS--[Correct PURCHASEASK]-->ATREVISION ,ATREVISION--[Ask Aproving]-->WAITINGALLOW ,WAITINGALLOW--[Não Aprove PURCHASEASK]-->ATREVISION ,ATREVISION--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,WAITINGALLOW--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,ATANALYSIS--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,ANALYSISPURCHASEASKEXPORTAÇÃO--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,WAITINGQUESTIONÁRIO--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,EMITTED--[Ask Cancelling]-->CANCELASKEDPURCHASEASK ,ATDRAFT--[Erase Draft]-->None ", transicoes); 220 | } 221 | 222 | [TestMethod] 223 | public void PrintPURCHASEASKParaDeposit() 224 | { 225 | WorkFlowContext context = work.GetContext().AddElements("ATDRAFT", "AreaPURCHASEASK"); 226 | context["Objective"] = new List { "2" };//Reexportation 227 | context["Departament"] = new List { "2" }; 228 | 229 | var lista = (List)work.Run(context, SearchMode.Breadth, new ListVisitor()); 230 | string transicoes = string.Join(",", lista.ToArray()); 231 | 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); 232 | } 233 | 234 | [TestMethod] 235 | public void PrintPURCHASEASKParaDepositInWidth() 236 | { 237 | WorkFlowContext context = work.GetContext().AddElements("ATDRAFT", "AreaPURCHASEASK"); 238 | context["Objective"] = new List { "2" };//Reexportation 239 | context["Departament"] = new List { "2" }; 240 | 241 | var lista = (List)work.Run(context, SearchMode.Breadth, new ListVisitor()); 242 | string transicoes = string.Join(",", lista.ToArray()); 243 | 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); 244 | } 245 | 246 | [TestMethod] 247 | public void PrintPURCHASEASKParaDepositContext() 248 | { 249 | WorkFlowContext context = work.GetContext().AddElements("ATDRAFT", "AreaPURCHASEASK"); 250 | context["Objective"] = new List { "2" };//deposito 251 | context["Departament"] = new List { "2" }; 252 | 253 | var lista = (List)work.Run(context, SearchMode.Breadth, new ListVisitor()); 254 | string transicoes = string.Join(",", lista.ToArray()); 255 | 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); 256 | 257 | } 258 | 259 | [TestMethod] 260 | public void PrintRunnerStrategy() 261 | { 262 | IWorkFlow workteste = WorkFlowManager.GetManager(typeof(RunnerCustom)); 263 | 264 | WorkFlowContext context = workteste 265 | .GetContext() 266 | .AddElements("ATDRAFT", "AreaPURCHASEASK"); 267 | 268 | var lista = (List)workteste.Run(context, SearchMode.Breadth, new ListVisitor()); 269 | string transicoes = string.Join(",", lista.ToArray()); 270 | 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); 271 | 272 | } 273 | 274 | [TestMethod] 275 | public void ExecuteCommand() 276 | { 277 | IWorkFlow workteste = WorkFlowManager.GetManager(); 278 | 279 | WorkFlowContext context = workteste 280 | .GetContext() 281 | .AddElements("ATDRAFT", "AreaPURCHASEASK") 282 | .SetCommand(typeof(DefaultWorkFlowCommand)) 283 | .Execute(); 284 | 285 | } 286 | 287 | [TestMethod] 288 | public void ConditionWithDifferentOperators() 289 | { 290 | IWorkFlow workteste = WorkFlowManager.GetManager(); 291 | 292 | WorkFlowContext context = workteste.GetContext() 293 | .SetArea("TESTCONDITIONSICK") 294 | .SetSourceState("INITIAL"); 295 | 296 | context["TESTCONDITIONEQUAL"] = new List { "COLD" }; 297 | context["TESTCONDITIONLT"] = new List { "4" }; 298 | context["TESTCONDITIONIN"] = new List { "5", "8" }; 299 | 300 | 301 | var activities = workteste.GetActivities(context); 302 | // must be one because im not passing custom parameter... 303 | Assert.AreEqual(1, activities.Count); 304 | } 305 | 306 | [TestMethod] 307 | public void ConditionWithDifferentOperatorsWithCustomEvaluator() 308 | { 309 | IWorkFlow workteste = WorkFlowManager.GetManager(); 310 | 311 | WorkFlowContext context = workteste.GetContext() 312 | .AddEvaluator(new CustomEvaluator()) 313 | .SetArea("TESTCONDITIONSICK") 314 | .SetSourceState("INITIAL"); 315 | 316 | 317 | context["TESTCONDITIONEQUAL"] = new List { "COLD" }; 318 | context["TESTCONDITIONLT"] = new List { "4" }; 319 | context["CUSTOM"] = new List { "http://" }; 320 | context["TESTCONDITIONIN"] = new List { "5", "8" }; 321 | 322 | 323 | var activities = workteste.GetActivities(context); 324 | 325 | Assert.AreEqual(2, activities.Count); 326 | } 327 | 328 | [TestMethod] 329 | public void ConditionWithDifferentOperatorsLastParameterFalse() 330 | { 331 | IWorkFlow workteste = WorkFlowManager.GetManager(); 332 | 333 | WorkFlowContext context = workteste.GetContext() 334 | .SetArea("TESTCONDITIONSICK") 335 | .SetSourceState("INITIAL"); 336 | 337 | context["TESTCONDITIONEQUAL"] = new List { "COLD" }; 338 | context["TESTCONDITIONLT"] = new List { "4" }; 339 | context["TESTCONDITIONIN"] = new List { "5", "8", "9", "10" }; 340 | 341 | 342 | var activities = workteste.GetActivities(context); 343 | 344 | Assert.AreEqual(1, activities.Count); 345 | } 346 | [TestMethod] 347 | public void OneParameterNotValidWithMessage() 348 | { 349 | IWorkFlow workteste = WorkFlowManager.GetManager(); 350 | 351 | WorkFlowContext context = workteste.GetContext() 352 | .SetArea("TESTCONDITIONSICKNOVALID") 353 | .SetOperation("MAKEEFFORT") 354 | .SetSourceState("INITIAL"); 355 | 356 | context["TESTCONDITIONEQUAL"] = new List { "HOT" }; 357 | context["TESTCONDITIONLT"] = new List { "6" }; 358 | context["TESTCONDITIONIN"] = new List { "5", "8", "9" }; 359 | 360 | var results = workteste.ValidateNextStatus(context); 361 | 362 | Assert.AreEqual(2, results.Count); 363 | Assert.IsTrue(results[1].Parameter.Message == "TESTCONDITIONLT NOT BIGGER THAN 5"); 364 | } 365 | } 366 | 367 | public class CustomEvaluator : IEvaluatorCommand 368 | { 369 | //there's no successor 370 | public IEvaluatorCommand Successor 371 | { 372 | get; 373 | 374 | set; 375 | } 376 | 377 | public bool Execute(Evaluate item, WorkFlowContext context) 378 | { 379 | bool result = false; 380 | 381 | if (item.Operator == "ENDPOINT") 382 | { 383 | return item.Value.FirstOrDefault() == "http://"; 384 | //search in remote server... 385 | } 386 | else 387 | { 388 | result = Successor.Execute(item, context); 389 | } 390 | 391 | return result; 392 | } 393 | } 394 | 395 | public class RunnerCustom : RunnerManager 396 | { 397 | public override object Run(WorkFlowContext context, SearchMode mode, WorkFlow.Visitors.IVisitor visitor = null) 398 | { 399 | if (visitor == null) 400 | visitor = new DefaultVisitor(); 401 | 402 | Queue fila = new Queue(); 403 | List mark = new List(); 404 | 405 | fila.Enqueue(context.SourceState); 406 | mark.Add(context.SourceState); 407 | 408 | while (fila.Count != 0) 409 | { 410 | string statusfila = fila.Dequeue(); 411 | context.SourceState = statusfila; 412 | foreach (var item in this.GetActivities(context).OrderBy(x => x.Operation)) 413 | { 414 | context.Operation = item.Operation; 415 | string newstatus = this.GetNextStatus(context); 416 | visitor.Visit(statusfila, new Activity { Operation = item.Operation, Description = item.Description }, newstatus); 417 | 418 | if (!mark.Contains(newstatus)) 419 | { 420 | fila.Enqueue(newstatus); 421 | mark.Add(newstatus); 422 | } 423 | } 424 | } 425 | 426 | return visitor.EndVisit(); 427 | } 428 | } 429 | } 430 | -------------------------------------------------------------------------------- /WorkFlowTest/WorkFlowTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {15111F02-02BD-4639-893C-C939ADFC367D} 7 | Library 8 | Properties 9 | WorkFlowTest 10 | WorkFlowTest 11 | v4.5.1 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | SAK 21 | SAK 22 | SAK 23 | SAK 24 | 25 | 26 | true 27 | full 28 | false 29 | bin\Debug\ 30 | DEBUG;TRACE 31 | prompt 32 | 4 33 | false 34 | 35 | 36 | pdbonly 37 | true 38 | bin\Release\ 39 | TRACE 40 | prompt 41 | 4 42 | false 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | {bac6d2b4-8f6f-4b9a-9e6b-c245b31ae43f} 67 | WorkFlow 68 | 69 | 70 | 71 | 72 | 73 | 74 | False 75 | 76 | 77 | False 78 | 79 | 80 | False 81 | 82 | 83 | False 84 | 85 | 86 | 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /WorkFlowTest/WorkFlowTest.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /WorkFlowTestException/ExceptionsWorkFlowTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using WorkFlow; 5 | using WorkFlow.Entities; 6 | using System.Linq; 7 | using WorkFlow.Exceptions; 8 | using System.IO; 9 | using WorkFlow.Business.BusinessProcess; 10 | using WorkFlow.Business.Search; 11 | using WorkFlow.Context; 12 | using WorkFlow.DAO; 13 | using WorkFlow.Configuration; 14 | using WorkFlow.Impl; 15 | using WorkFlow.Validation; 16 | 17 | namespace WorkFlowTest 18 | { 19 | [TestClass] 20 | public class ExceptionsWorkFlowTest 21 | { 22 | private static IWorkFlow work; 23 | 24 | [TestMethod] 25 | [ExpectedException(typeof(DuplicatedNodeException))] 26 | public void RaiseExceptionWhenSourceStateAndAreaAreDuplicated() 27 | { 28 | WorkFlowConfiguration.Binder 29 | .SetRepository(typeof(DAOEmbeddedResource)) 30 | .SetValidator(typeof(ValidatorCustom)) 31 | .Setup(x => x.TypeName, "WorkFlowTestException.Json.sourceAreaException.json , WorkFlowTestException"); 32 | 33 | work = WorkFlowManager.GetManager(); 34 | } 35 | 36 | [TestMethod] 37 | [ExpectedException(typeof(DuplicatedNodeException))] 38 | public void RaiseExceptionWhenIdsAreDuplicated() 39 | { 40 | WorkFlowConfiguration.Binder 41 | .SetRepository(typeof(DAOEmbeddedResource)) 42 | .Setup(x => x.TypeName, "WorkFlowTestException.Json.idException.json , WorkFlowTestException"); 43 | 44 | work = WorkFlowManager.GetManager(); 45 | } 46 | 47 | [TestMethod] 48 | [ExpectedException(typeof(DuplicatedNodeException))] 49 | public void RaiseExceptionWhenConditionsAreDuplicated() 50 | { 51 | WorkFlowConfiguration.Binder 52 | .SetRepository(typeof(DAOEmbeddedResource)) 53 | .Setup(x => x.TypeName, "WorkFlowTestException.Json.conditionException.json , WorkFlowTestException"); 54 | 55 | work = WorkFlowManager.GetManager(); 56 | } 57 | } 58 | 59 | public class ValidatorCustom : IValidator 60 | { 61 | public void Validate(Structure structure) 62 | { 63 | ValidateDuplicatedSourceAndArea(structure); 64 | } 65 | private void ValidateDuplicatedSourceAndArea(Structure structure) 66 | { 67 | var totalgrouped = structure.WorkFlow 68 | .GroupBy(x => new { x.Area, x.SourceState }) 69 | .Where(grp => grp.Count() > 1) 70 | .Select(x => new { Key = x.Key, List = x.ToList() }); 71 | 72 | foreach (var item in totalgrouped) 73 | { 74 | string message = string.Join(",", item.List.Select(x => x.Id).ToList()); 75 | throw new DuplicatedNodeException(string.Format("There are duplicated entries for Ids: {0}", message)); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /WorkFlowTestException/Json/conditionException.json: -------------------------------------------------------------------------------- 1 | { 2 | "Conditions": [ 3 | { 4 | "Name": "EXTINTION", 5 | "Parameters": [ 6 | { 7 | "Key": "Objective", 8 | "Value": [ 9 | "4", 10 | "3", 11 | "7", 12 | "5", 13 | "9", 14 | "8" 15 | ] 16 | } 17 | ] 18 | }, 19 | { 20 | "Name": "EXTINTION", 21 | "Parameters": [ 22 | { 23 | "Key": "Objective", 24 | "Value": [ 25 | "3" 26 | ] 27 | } 28 | ] 29 | }, 30 | { 31 | "Name": "EXPORTATION", 32 | "Parameters": [ 33 | { 34 | "Key": "Objective", 35 | "Value": [ 36 | "4", 37 | "8" 38 | ] 39 | } 40 | ] 41 | }, 42 | { 43 | "Name": "ES", 44 | "Parameters": [ 45 | { 46 | "Key": "Departament", 47 | "Value": [ 48 | "40" 49 | ] 50 | } 51 | ] 52 | }, 53 | { 54 | "Name": "EHPARTE", 55 | "Parameters": [ 56 | { 57 | "Key": "Parte", 58 | "Value": [ 59 | "True" 60 | ] 61 | } 62 | ] 63 | }, 64 | { 65 | "Name": "NAOMOVED", 66 | "Parameters": [ 67 | { 68 | "Key": "MOVED", 69 | "Value": [ 70 | "false" 71 | ] 72 | } 73 | ] 74 | } 75 | ], 76 | "WorkFlow": [ 77 | { 78 | "Id": 1, 79 | "SourceState": "APPROVED", 80 | "Transitions": [{ Operation:"CANCEL_ASKED", Description:"None" , "DestinyState": "CANCELASKEDPURCHASEASK"}, 81 | { Operation:"ATUALIZA_PURCHASEASK_CANCEL", Description:"None" , "DestinyState": "PURCHASEORDERCREATED"}, 82 | { Operation:"PURCHASEORDER_CHECK_MATERIAL", Description:"None" , "DestinyState": "ATCHECKING"}, 83 | { Operation:"LAST_ITEM_CANCELLED_PURCHASEASK", Description:"None" , "DestinyState": "CANCELLEDPURCHASEASK"}, 84 | { Operation:"ITEM_CANCELLED_PURCHASEORDER", Description:"None" , "DestinyState": "ATANALYSIS"}, 85 | { Operation:"CancelPURCHASEASK", Description:"None" , "DestinyState": "CANCELLEDPURCHASEASK"}, 86 | { Operation:"LAST_ITEM_CANCELLED_PURCHASEORDER", Description:"None" , "DestinyState": "CANCELLEDPURCHASEORDER"}, 87 | { Operation:"CANCEL_ASKED_PURCHASEORDER", Description:"None" , "DestinyState": "CANCELASKEDPURCHASEORDER"}], 88 | 89 | "Area": "PURCHASEPROCESS" 90 | }, 91 | { 92 | "Id": 2, 93 | "SourceState": "APPROVED", 94 | "Transitions": [{ Operation:"PURCHASEORDER_CANCEL", Description:"Cancel PURCHASEORDER" , "DestinyState": "CANCELLEDPURCHASEORDER"}], 95 | "Area": "NEWPURCHASE" 96 | }, 97 | { 98 | "Id": 3, 99 | "SourceState": "APPROVED", 100 | "Transitions": [{ Operation:"PURCHASEORDER_CANCEL", Description:"Cancel PURCHASEORDER" , "DestinyState": "CANCELLEDPURCHASEORDER"}], 101 | "Area": "NEWPURCHASEPROCESS" 102 | } 103 | ] 104 | } 105 | -------------------------------------------------------------------------------- /WorkFlowTestException/Json/idException.json: -------------------------------------------------------------------------------- 1 | { 2 | "Conditions": [ 3 | { 4 | "Name": "EXTINTION", 5 | "Parameters": [ 6 | { 7 | "Key": "Objective", 8 | "Value": [ 9 | "4", 10 | "3", 11 | "7", 12 | "5", 13 | "9", 14 | "8" 15 | ] 16 | } 17 | ] 18 | }, 19 | { 20 | "Name": "DESTRUCTION", 21 | "Parameters": [ 22 | { 23 | "Key": "Objective", 24 | "Value": [ 25 | "3" 26 | ] 27 | } 28 | ] 29 | }, 30 | { 31 | "Name": "EXPORTATION", 32 | "Parameters": [ 33 | { 34 | "Key": "Objective", 35 | "Value": [ 36 | "4", 37 | "8" 38 | ] 39 | } 40 | ] 41 | }, 42 | { 43 | "Name": "ES", 44 | "Parameters": [ 45 | { 46 | "Key": "Departament", 47 | "Value": [ 48 | "40" 49 | ] 50 | } 51 | ] 52 | }, 53 | { 54 | "Name": "EHPARTE", 55 | "Parameters": [ 56 | { 57 | "Key": "Parte", 58 | "Value": [ 59 | "True" 60 | ] 61 | } 62 | ] 63 | }, 64 | { 65 | "Name": "NAOMOVED", 66 | "Parameters": [ 67 | { 68 | "Key": "MOVED", 69 | "Value": [ 70 | "false" 71 | ] 72 | } 73 | ] 74 | } 75 | ], 76 | "WorkFlow": [ 77 | { 78 | "Id": 1, 79 | "SourceState": "APPROVED", 80 | "Transitions": [{ Operation:"CANCEL_ASKED", Description:"None" , "DestinyState": "CANCELASKEDPURCHASEASK"}, 81 | { Operation:"ATUALIZA_PURCHASEASK_CANCEL", Description:"None" , "DestinyState": "PURCHASEORDERCREATED"}, 82 | { Operation:"PURCHASEORDER_CHECK_MATERIAL", Description:"None" , "DestinyState": "ATCHECKING"}, 83 | { Operation:"LAST_ITEM_CANCELLED_PURCHASEASK", Description:"None" , "DestinyState": "CANCELLEDPURCHASEASK"}, 84 | { Operation:"ITEM_CANCELLED_PURCHASEORDER", Description:"None" , "DestinyState": "ATANALYSIS"}, 85 | { Operation:"CancelPURCHASEASK", Description:"None" , "DestinyState": "CANCELLEDPURCHASEASK"}, 86 | { Operation:"LAST_ITEM_CANCELLED_PURCHASEORDER", Description:"None" , "DestinyState": "CANCELLEDPURCHASEORDER"}, 87 | { Operation:"CANCEL_ASKED_PURCHASEORDER", Description:"None" , "DestinyState": "CANCELASKEDPURCHASEORDER"}], 88 | 89 | "Area": "PURCHASEPROCESS" 90 | }, 91 | { 92 | "Id": 1, 93 | "SourceState": "APPROVED", 94 | "Transitions": [{ Operation:"PURCHASEORDER_CANCEL", Description:"Cancel PURCHASEORDER" , "DestinyState": "CANCELLEDPURCHASEORDER"}], 95 | "Area": "NEWPURCHASEPROCESS" 96 | }, 97 | { 98 | "Id": 2, 99 | "SourceState": "APPROVED", 100 | "Transitions": [{ Operation:"PURCHASEORDER_CANCEL", Description:"Cancel PURCHASEORDER" , "DestinyState": "CANCELLEDPURCHASEORDER"}], 101 | "Area": "NEWPURCHASEPROCESS" 102 | } 103 | ] 104 | } 105 | -------------------------------------------------------------------------------- /WorkFlowTestException/Json/sourceAreaException.json: -------------------------------------------------------------------------------- 1 | { 2 | "Conditions": [ 3 | { 4 | "Name": "EXTINTION", 5 | "Parameters": [ 6 | { 7 | "Key": "Objective", 8 | "Value": [ 9 | "4", 10 | "3", 11 | "7", 12 | "5", 13 | "9", 14 | "8" 15 | ] 16 | } 17 | ] 18 | }, 19 | { 20 | "Name": "DESTRUCTION", 21 | "Parameters": [ 22 | { 23 | "Key": "Objective", 24 | "Value": [ 25 | "3" 26 | ] 27 | } 28 | ] 29 | }, 30 | { 31 | "Name": "EXPORTATION", 32 | "Parameters": [ 33 | { 34 | "Key": "Objective", 35 | "Value": [ 36 | "4", 37 | "8" 38 | ] 39 | } 40 | ] 41 | }, 42 | { 43 | "Name": "ES", 44 | "Parameters": [ 45 | { 46 | "Key": "Departament", 47 | "Value": [ 48 | "40" 49 | ] 50 | } 51 | ] 52 | }, 53 | { 54 | "Name": "EHPARTE", 55 | "Parameters": [ 56 | { 57 | "Key": "Parte", 58 | "Value": [ 59 | "True" 60 | ] 61 | } 62 | ] 63 | }, 64 | { 65 | "Name": "NAOMOVED", 66 | "Parameters": [ 67 | { 68 | "Key": "MOVED", 69 | "Value": [ 70 | "false" 71 | ] 72 | } 73 | ] 74 | } 75 | ], 76 | "WorkFlow": [ 77 | { 78 | "Id": 1, 79 | "SourceState": "APPROVED", 80 | "Transitions": [{ Operation:"CANCEL_ASKED", Description:"None" , "DestinyState": "CANCELASKEDPURCHASEASK"}, 81 | { Operation:"ATUALIZA_PURCHASEASK_CANCEL", Description:"None" , "DestinyState": "PURCHASEORDERCREATED"}, 82 | { Operation:"PURCHASEORDER_CHECK_MATERIAL", Description:"None" , "DestinyState": "ATCHECKING"}, 83 | { Operation:"LAST_ITEM_CANCELLED_PURCHASEASK", Description:"None" , "DestinyState": "CANCELLEDPURCHASEASK"}, 84 | { Operation:"ITEM_CANCELLED_PURCHASEORDER", Description:"None" , "DestinyState": "ATANALYSIS"}, 85 | { Operation:"CancelPURCHASEASK", Description:"None" , "DestinyState": "CANCELLEDPURCHASEASK"}, 86 | { Operation:"LAST_ITEM_CANCELLED_PURCHASEORDER", Description:"None" , "DestinyState": "CANCELLEDPURCHASEORDER"}, 87 | { Operation:"CANCEL_ASKED_PURCHASEORDER", Description:"None" , "DestinyState": "CANCELASKEDPURCHASEORDER"}], 88 | 89 | "Area": "PURCHASEPROCESS" 90 | }, 91 | { 92 | "Id": 2, 93 | "SourceState": "APPROVED", 94 | "Transitions": [{ Operation:"PURCHASEORDER_CANCEL", Description:"Cancel PURCHASEORDER" , "DestinyState": "CANCELLEDPURCHASEORDER"}], 95 | "Area": "NEWPURCHASEPROCESS" 96 | }, 97 | { 98 | "Id": 3, 99 | "SourceState": "APPROVED", 100 | "Transitions": [{ Operation:"PURCHASEORDER_CANCEL", Description:"Cancel PURCHASEORDER" , "DestinyState": "CANCELLEDPURCHASEORDER"}], 101 | "Area": "NEWPURCHASEPROCESS" 102 | } 103 | ] 104 | } 105 | -------------------------------------------------------------------------------- /WorkFlowTestException/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WorkFlowTestException")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("WorkFlowTestException")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d8a0c15b-0966-4508-9662-f9c047a97409")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /WorkFlowTestException/WorkFlowTestException.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {0A285418-EEA9-48DE-8A0D-73A161DA9DE5} 7 | Library 8 | Properties 9 | WorkFlowTestException 10 | WorkFlowTestException 11 | v4.5.1 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | {bac6d2b4-8f6f-4b9a-9e6b-c245b31ae43f} 63 | WorkFlow 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | False 77 | 78 | 79 | False 80 | 81 | 82 | False 83 | 84 | 85 | False 86 | 87 | 88 | 89 | 90 | 91 | 92 | 99 | -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/Newtonsoft.Json.6.0.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/packages/Newtonsoft.Json.6.0.1/Newtonsoft.Json.6.0.1.nupkg -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/Newtonsoft.Json.6.0.1.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Newtonsoft.Json 5 | 6.0.1 6 | Json.NET 7 | James Newton-King 8 | James Newton-King 9 | https://raw.github.com/JamesNK/Newtonsoft.Json/master/LICENSE.md 10 | http://james.newtonking.com/json 11 | false 12 | Json.NET is a popular high-performance JSON framework for .NET 13 | 14 | 15 | en-US 16 | json 17 | 18 | -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/lib/net20/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/packages/Newtonsoft.Json.6.0.1/lib/net20/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/lib/net35/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/packages/Newtonsoft.Json.6.0.1/lib/net35/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/lib/net40/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/packages/Newtonsoft.Json.6.0.1/lib/net40/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/lib/net45/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/packages/Newtonsoft.Json.6.0.1/lib/net45/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/lib/netcore45/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/packages/Newtonsoft.Json.6.0.1/lib/netcore45/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/lib/portable-net40+sl5+wp80+win8+monotouch+monoandroid/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/packages/Newtonsoft.Json.6.0.1/lib/portable-net40+sl5+wp80+win8+monotouch+monoandroid/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/lib/portable-net45+wp80+win8/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xblader/LightWorkFlow/24d3bb7a55138d082dd2c89cdaf6998399283e75/packages/Newtonsoft.Json.6.0.1/lib/portable-net45+wp80+win8/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.6.0.1/tools/install.ps1: -------------------------------------------------------------------------------- 1 | param($installPath, $toolsPath, $package, $project) 2 | 3 | # open json.net splash page on package install 4 | # don't open if json.net is installed as a dependency 5 | 6 | try 7 | { 8 | $url = "http://james.newtonking.com/json" 9 | $dte2 = Get-Interface $dte ([EnvDTE80.DTE2]) 10 | 11 | if ($dte2.ActiveWindow.Caption -eq "Package Manager Console") 12 | { 13 | # user is installing from VS NuGet console 14 | # get reference to the window, the console host and the input history 15 | # show webpage if "install-package newtonsoft.json" was last input 16 | 17 | $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow]) 18 | 19 | $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor ` 20 | [System.Reflection.BindingFlags]::NonPublic) 21 | 22 | $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1 23 | if ($prop -eq $null) { return } 24 | 25 | $hostInfo = $prop.GetValue($consoleWindow) 26 | if ($hostInfo -eq $null) { return } 27 | 28 | $history = $hostInfo.WpfConsole.InputHistory.History 29 | 30 | $lastCommand = $history | select -last 1 31 | 32 | if ($lastCommand) 33 | { 34 | $lastCommand = $lastCommand.Trim().ToLower() 35 | if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json")) 36 | { 37 | $dte2.ItemOperations.Navigate($url) | Out-Null 38 | } 39 | } 40 | } 41 | else 42 | { 43 | # user is installing from VS NuGet dialog 44 | # get reference to the window, then smart output console provider 45 | # show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation 46 | 47 | $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor ` 48 | [System.Reflection.BindingFlags]::NonPublic) 49 | $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor ` 50 | [System.Reflection.BindingFlags]::NonPublic) 51 | if ($instanceField -eq $null -or $consoleField -eq $null) { return } 52 | 53 | $instance = $instanceField.GetValue($null) 54 | if ($instance -eq $null) { return } 55 | 56 | $consoleProvider = $consoleField.GetValue($instance) 57 | if ($consoleProvider -eq $null) { return } 58 | 59 | $console = $consoleProvider.CreateOutputConsole($false) 60 | 61 | $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor ` 62 | [System.Reflection.BindingFlags]::NonPublic) 63 | if ($messagesField -eq $null) { return } 64 | 65 | $messages = $messagesField.GetValue($console) 66 | if ($messages -eq $null) { return } 67 | 68 | $operations = $messages -split "==============================" 69 | 70 | $lastOperation = $operations | select -last 1 71 | 72 | if ($lastOperation) 73 | { 74 | $lastOperation = $lastOperation.ToLower() 75 | 76 | $lines = $lastOperation -split "`r`n" 77 | 78 | $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1 79 | 80 | if ($installMatch) 81 | { 82 | $dte2.ItemOperations.Navigate($url) | Out-Null 83 | } 84 | } 85 | } 86 | } 87 | catch 88 | { 89 | # stop potential errors from bubbling up 90 | # worst case the splash page won't open 91 | } 92 | 93 | # yolo -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------