diff --git a/.gitignore b/.gitignore index 45b344b..5329ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ bin obj *.suo *.vspscc +/Sources/.vs +/Sources/TinyWorkflow/project.lock.json diff --git a/Sources/TinyWorkflow.Tests/AsynchStepTest.cs b/Sources/TinyWorkflow.Tests/AsynchStepTest.cs index ef66a4b..c071660 100644 --- a/Sources/TinyWorkflow.Tests/AsynchStepTest.cs +++ b/Sources/TinyWorkflow.Tests/AsynchStepTest.cs @@ -1,74 +1,75 @@ using System; +using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using TinyWorkflow.Tests.States; -using System.Threading; namespace TinyWorkflow.Tests { - [TestClass] - public class AsynchStepTest - { - Workflow temporaryWorkflow; - [TestMethod] - public void RunOneAsynchStep() - { - temporaryWorkflow = new Workflow() - .DoAsynch(EasyAction) - .Block() - .Do(EasyAsynchronousTestValidation); - temporaryWorkflow.Start(new SimpleState()); - Thread.Sleep(3000); - } + [TestClass] + public class AsynchStepTest + { + private IWorkflow temporaryWorkflow; + + [TestMethod] + public void RunOneAsynchStep() + { + temporaryWorkflow = new Workflow() + .DoAsynch(EasyAction) + .Block() + .Do(EasyAsynchronousTestValidation); + temporaryWorkflow.Start(new SimpleState()); + Thread.Sleep(3000); + } - [TestMethod] - public void RunMultipleAsynchStep() - { - temporaryWorkflow = new Workflow() - .DoAsynch(EasyActionAsynch1,EasyActionAsynch2,EasyActionAsynch3) - .Block(3) - .Do(AsynchronousTestValidation); - temporaryWorkflow.Start(new SimpleState()); - Thread.Sleep(3000); - } + [TestMethod] + public void RunMultipleAsynchStep() + { + temporaryWorkflow = new Workflow() + .DoAsynch(EasyActionAsynch1, EasyActionAsynch2, EasyActionAsynch3) + .Block(3) + .Do(AsynchronousTestValidation); + temporaryWorkflow.Start(new SimpleState()); + Thread.Sleep(3000); + } - public void EasyAsynchronousTestValidation(SimpleState state) - { - Assert.AreEqual(1, state.StateFullVariable); - } + public void EasyAsynchronousTestValidation(SimpleState state) + { + Assert.AreEqual(1, state.StateFullVariable); + } - public void AsynchronousTestValidation(SimpleState state) - { - Assert.AreEqual(10, state.StateFullVariableAsynch1); - Assert.AreEqual(20, state.StateFullVariableAsynch2); - Assert.AreEqual(30, state.StateFullVariableAsynch3); - } + public void AsynchronousTestValidation(SimpleState state) + { + Assert.AreEqual(10, state.StateFullVariableAsynch1); + Assert.AreEqual(20, state.StateFullVariableAsynch2); + Assert.AreEqual(30, state.StateFullVariableAsynch3); + } - public void EasyAction(SimpleState state) - { - Thread.Sleep(1000); - state.StateFullVariable = 1; - temporaryWorkflow.Unblock(); - } + public void EasyAction(SimpleState state) + { + Thread.Sleep(1000); + state.StateFullVariable = 1; + temporaryWorkflow.Unblock(); + } - public void EasyActionAsynch1(SimpleState state) - { - Thread.Sleep(1200); - state.StateFullVariableAsynch1 = 10; - temporaryWorkflow.Unblock(); - } + public void EasyActionAsynch1(SimpleState state) + { + Thread.Sleep(1200); + state.StateFullVariableAsynch1 = 10; + temporaryWorkflow.Unblock(); + } - public void EasyActionAsynch2(SimpleState state) - { - Thread.Sleep(700); - state.StateFullVariableAsynch2 = 20; - temporaryWorkflow.Unblock(); - } + public void EasyActionAsynch2(SimpleState state) + { + Thread.Sleep(700); + state.StateFullVariableAsynch2 = 20; + temporaryWorkflow.Unblock(); + } - public void EasyActionAsynch3(SimpleState state) - { - Thread.Sleep(1000); - state.StateFullVariableAsynch3 = 30; - temporaryWorkflow.Unblock(); - } - } -} + public void EasyActionAsynch3(SimpleState state) + { + Thread.Sleep(1000); + state.StateFullVariableAsynch3 = 30; + temporaryWorkflow.Unblock(); + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/BlockIfStepTest.cs b/Sources/TinyWorkflow.Tests/BlockIfStepTest.cs index 3433b07..e3f5bcb 100644 --- a/Sources/TinyWorkflow.Tests/BlockIfStepTest.cs +++ b/Sources/TinyWorkflow.Tests/BlockIfStepTest.cs @@ -4,58 +4,58 @@ namespace TinyWorkflow.Tests { - [TestClass] - public class BlockIfStepTest - { - [TestMethod] - public void RunIfTrueAndBlock() - { - Workflow workflow = new Workflow() - .If(TestToTrue, ActionIfTrue, ActionIfFalse) - .Block() - .Do(ActionAfter); - workflow.Start(new SimpleState()); - Assert.AreEqual(2, workflow.Workload.StateFullVariable); - workflow.Unblock(); - Assert.AreEqual(3, workflow.Workload.StateFullVariable); - } + [TestClass] + public class BlockIfStepTest + { + [TestMethod] + public void RunIfTrueAndBlock() + { + var workflow = new Workflow() + .If(TestToTrue, ActionIfTrue, ActionIfFalse) + .Block() + .Do(ActionAfter); + workflow.Start(new SimpleState()); + Assert.AreEqual(2, workflow.Workload.StateFullVariable); + workflow.Unblock(); + Assert.AreEqual(3, workflow.Workload.StateFullVariable); + } - [TestMethod] - public void RunIfFalseAndBlock() - { - Workflow workflow = new Workflow() - .If(TestToFalse, ActionIfTrue, ActionIfFalse) - .Block() - .Do(ActionAfter); - workflow.Start(new SimpleState()); - Assert.AreEqual(3, workflow.Workload.StateFullVariable); - workflow.Unblock(); - Assert.AreEqual(4, workflow.Workload.StateFullVariable); - } + [TestMethod] + public void RunIfFalseAndBlock() + { + var workflow = new Workflow() + .If(TestToFalse, ActionIfTrue, ActionIfFalse) + .Block() + .Do(ActionAfter); + workflow.Start(new SimpleState()); + Assert.AreEqual(3, workflow.Workload.StateFullVariable); + workflow.Unblock(); + Assert.AreEqual(4, workflow.Workload.StateFullVariable); + } - public bool TestToTrue(SimpleState state) - { - return state.StateFullVariable == 0; - } + public bool TestToTrue(SimpleState state) + { + return state.StateFullVariable == 0; + } - public bool TestToFalse(SimpleState state) - { - return state.StateFullVariable != 0; - } + public bool TestToFalse(SimpleState state) + { + return state.StateFullVariable != 0; + } - public void ActionIfTrue(SimpleState state) - { - state.StateFullVariable = 2; - } + public void ActionIfTrue(SimpleState state) + { + state.StateFullVariable = 2; + } - public void ActionIfFalse(SimpleState state) - { - state.StateFullVariable = 3; - } + public void ActionIfFalse(SimpleState state) + { + state.StateFullVariable = 3; + } - public void ActionAfter(SimpleState state) - { - state.StateFullVariable++; - } - } -} + public void ActionAfter(SimpleState state) + { + state.StateFullVariable++; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/BlockSimpleStepTest.cs b/Sources/TinyWorkflow.Tests/BlockSimpleStepTest.cs index b38ed18..95a5237 100644 --- a/Sources/TinyWorkflow.Tests/BlockSimpleStepTest.cs +++ b/Sources/TinyWorkflow.Tests/BlockSimpleStepTest.cs @@ -1,38 +1,38 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; using TinyWorkflow.Tests.States; namespace TinyWorkflow.Tests { - [TestClass] - public class BlockSimpleStepTest - { - [TestMethod] - public void SimpleStepBlock() - { - Workflow workflow = new Workflow() - .Do(ActionBeforeBlock) - .Block() - .Do(ActionAfterBlock); + [TestClass] + public class BlockSimpleStepTest + { + [TestMethod] + public void SimpleStepBlock() + { + var workflow = new Workflow() + .Do(ActionBeforeBlock) + .Block() + .Do(ActionAfterBlock); - workflow.Start(new SimpleState()); - Assert.AreEqual(5, workflow.Workload.StateFullVariable); - workflow.Unblock(); - Assert.AreEqual(10, workflow.Workload.StateFullVariable); - } + workflow.Start(new SimpleState()); + Assert.AreEqual(5, workflow.Workload.StateFullVariable); + workflow.Unblock(); + Assert.AreEqual(10, workflow.Workload.StateFullVariable); + } - public void ActionBeforeBlock(SimpleState state) - { - state.StateFullVariable = 5; - } + public void ActionBeforeBlock(SimpleState state) + { + state.StateFullVariable = 5; + } - public void ActionAfterBlock(SimpleState state) - { - state.StateFullVariable = 10; - } - } -} + public void ActionAfterBlock(SimpleState state) + { + state.StateFullVariable = 10; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/BlockWhileStepTest.cs b/Sources/TinyWorkflow.Tests/BlockWhileStepTest.cs index 8f9a075..178e575 100644 --- a/Sources/TinyWorkflow.Tests/BlockWhileStepTest.cs +++ b/Sources/TinyWorkflow.Tests/BlockWhileStepTest.cs @@ -1,44 +1,44 @@ using System; +using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using TinyWorkflow.Tests.States; -using System.Collections.Generic; namespace TinyWorkflow.Tests { - [TestClass] - public class BlockWhileStepTest - { - [TestMethod] - public void RunWhileWithBlock() - { - Workflow workflow = new Workflow() - .While(WhileTest, - new Workflow() - .Do(WhileContent) - .Block() - ); + [TestClass] + public class BlockWhileStepTest + { + [TestMethod] + public void RunWhileWithBlock() + { + var workflow = new Workflow() + .While(WhileTest, + new Workflow() + .Do(WhileContent) + .Block() + ); - workflow.Start(new ConditionState() { MaxRun = 5}); - Assert.AreEqual(0, workflow.Workload.StateFullVariable); - workflow.Unblock(); - Assert.AreEqual(1, workflow.Workload.StateFullVariable); - workflow.Unblock(); - Assert.AreEqual(3, workflow.Workload.StateFullVariable); - workflow.Unblock(); - Assert.AreEqual(6, workflow.Workload.StateFullVariable); - workflow.Unblock(); - Assert.AreEqual(10, workflow.Workload.StateFullVariable); - } + workflow.Start(new ConditionState() { MaxRun = 5 }); + Assert.AreEqual(0, workflow.Workload.StateFullVariable); + workflow.Unblock(); + Assert.AreEqual(1, workflow.Workload.StateFullVariable); + workflow.Unblock(); + Assert.AreEqual(3, workflow.Workload.StateFullVariable); + workflow.Unblock(); + Assert.AreEqual(6, workflow.Workload.StateFullVariable); + workflow.Unblock(); + Assert.AreEqual(10, workflow.Workload.StateFullVariable); + } - public void WhileContent(ConditionState state) - { - state.StateFullVariable += state.ActualRun; - state.ActualRun++; - } + public void WhileContent(ConditionState state) + { + state.StateFullVariable += state.ActualRun; + state.ActualRun++; + } - public bool WhileTest(ConditionState state) - { - return state.ActualRun < state.MaxRun; - } - } -} + public bool WhileTest(ConditionState state) + { + return state.ActualRun < state.MaxRun; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/BugFixes/ForStepBugFixTest.cs b/Sources/TinyWorkflow.Tests/BugFixes/ForStepBugFixTest.cs index face221..82621f2 100644 --- a/Sources/TinyWorkflow.Tests/BugFixes/ForStepBugFixTest.cs +++ b/Sources/TinyWorkflow.Tests/BugFixes/ForStepBugFixTest.cs @@ -1,61 +1,61 @@ using System; +using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using TinyWorkflow.Tests.States; -using System.Collections.Generic; namespace TinyWorkflow.Tests.BugFixes { - /// - /// Do not run indefinitely when no items returned (Bug #25775) - /// - [TestClass] - public class ForStepBugFixTest - { - [TestMethod] - public void RunStaticForeach() - { - Workflow workflow = new Workflow() - .Foreach(StaticEnumerateItem, - new Workflow>() - .Do(ActionInForeach) - ); - - workflow.Start(new ListState()); - Assert.AreEqual(0, workflow.Workload.StateFullVariable); - } - - [TestMethod] - public void RunDynamicForeach() - { - Workflow workflow = new Workflow() - .Do(DefineList) - .Foreach(DynamicEnumerateItem, - new Workflow>() - .Do(ActionInForeach) - ); - - workflow.Start(new ListState()); - Assert.AreEqual(0, workflow.Workload.StateFullVariable); - } - - public void DefineList(ListState state) - { - state.List = new List() {}; - } - - public IEnumerable DynamicEnumerateItem(ListState state) - { - return state.List; - } - - public IEnumerable StaticEnumerateItem(ListState state) - { - return new List() {}; - } - - public void ActionInForeach(Tuple state) - { - state.Item2.StateFullVariable += state.Item1; - } - } -} + /// + /// Do not run indefinitely when no items returned (Bug #25775) + /// + [TestClass] + public class ForStepBugFixTest + { + [TestMethod] + public void RunStaticForeach() + { + var workflow = new Workflow() + .Foreach(StaticEnumerateItem, + new Workflow>() + .Do(ActionInForeach) + ); + + workflow.Start(new ListState()); + Assert.AreEqual(0, workflow.Workload.StateFullVariable); + } + + [TestMethod] + public void RunDynamicForeach() + { + var workflow = new Workflow() + .Do(DefineList) + .Foreach(DynamicEnumerateItem, + new Workflow>() + .Do(ActionInForeach) + ); + + workflow.Start(new ListState()); + Assert.AreEqual(0, workflow.Workload.StateFullVariable); + } + + public void DefineList(ListState state) + { + state.List = new List() { }; + } + + public IEnumerable DynamicEnumerateItem(ListState state) + { + return state.List; + } + + public IEnumerable StaticEnumerateItem(ListState state) + { + return new List() { }; + } + + public void ActionInForeach(Tuple state) + { + state.Item2.StateFullVariable += state.Item1; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/ComplexTest.cs b/Sources/TinyWorkflow.Tests/ComplexTest.cs index 7939af9..0126aed 100644 --- a/Sources/TinyWorkflow.Tests/ComplexTest.cs +++ b/Sources/TinyWorkflow.Tests/ComplexTest.cs @@ -1,82 +1,82 @@ using System; +using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using TinyWorkflow.Tests.States; -using System.Collections.Generic; namespace TinyWorkflow.Tests { - [TestClass] - public class ComplexTest - { - [TestMethod] - public void FindAllPrimeNumbersAfter() - { - Workflow workflow = new Workflow() - //Define the - .Do(DefineInitialList) - .Foreach(DynamicEnumerateItem, - new Workflow>() - .Do(InitWhile) - .While(TestNumber, InternalWhileContent) - .Do(RegisterResult)); + [TestClass] + public class ComplexTest + { + [TestMethod] + public void FindAllPrimeNumbersAfter() + { + var workflow = new Workflow() + //Define the + .Do(DefineInitialList) + .Foreach(DynamicEnumerateItem, + new Workflow>() + .Do(InitWhile) + .While(TestNumber, InternalWhileContent) + .Do(RegisterResult)); - workflow.Start(new ComplexState()); - Assert.AreEqual(7, workflow.Workload.ListFinal[0]); - Assert.AreEqual(7, workflow.Workload.ListFinal[1]); - Assert.AreEqual(11, workflow.Workload.ListFinal[2]); - } + workflow.Start(new ComplexState()); + Assert.AreEqual(7, workflow.Workload.ListFinal[0]); + Assert.AreEqual(7, workflow.Workload.ListFinal[1]); + Assert.AreEqual(11, workflow.Workload.ListFinal[2]); + } - public void DefineInitialList(ComplexState state) - { - state.ListInitial = new List() { 5, 6, 9 }; - } + public void DefineInitialList(ComplexState state) + { + state.ListInitial = new List() { 5, 6, 9 }; + } - public IEnumerable DynamicEnumerateItem(ComplexState state) - { - return state.ListInitial; - } + public IEnumerable DynamicEnumerateItem(ComplexState state) + { + return state.ListInitial; + } - public IEnumerable DynamicEnumerateItemResult(ComplexState state) - { - return state.ListFinal; - } + public IEnumerable DynamicEnumerateItemResult(ComplexState state) + { + return state.ListFinal; + } - public void PrintNumber(Tuple state) - { - Console.WriteLine(state.Item1 + " is a prime number"); - } + public void PrintNumber(Tuple state) + { + Console.WriteLine(state.Item1 + " is a prime number"); + } - public void InitWhile(Tuple state) - { - state.Item2.CacheValue = state.Item1 + 1; - } + public void InitWhile(Tuple state) + { + state.Item2.CacheValue = state.Item1 + 1; + } - public bool TestNumber(Tuple state) - { - return !IsPrimeNumber(state.Item2.CacheValue); - } + public bool TestNumber(Tuple state) + { + return !IsPrimeNumber(state.Item2.CacheValue); + } - public void InternalWhileContent(Tuple state) - { - state.Item2.CacheValue++; - } + public void InternalWhileContent(Tuple state) + { + state.Item2.CacheValue++; + } - public void RegisterResult(Tuple state) - { - state.Item2.ListFinal.Add(state.Item2.CacheValue); - } + public void RegisterResult(Tuple state) + { + state.Item2.ListFinal.Add(state.Item2.CacheValue); + } - private bool IsPrimeNumber(int number) - { - for (int i = 2; i <= number/2; i++) - { - if ((number % i == 0)) - { - return false; - } - } + private bool IsPrimeNumber(int number) + { + for (int i = 2; i <= number / 2; i++) + { + if ((number % i == 0)) + { + return false; + } + } - return true; - } - } -} + return true; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/ForStepTest.cs b/Sources/TinyWorkflow.Tests/ForStepTest.cs index 565f023..b48a313 100644 --- a/Sources/TinyWorkflow.Tests/ForStepTest.cs +++ b/Sources/TinyWorkflow.Tests/ForStepTest.cs @@ -1,61 +1,61 @@ using System; +using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using TinyWorkflow.Tests.States; -using System.Collections.Generic; namespace TinyWorkflow.Tests { - [TestClass] - public class ForStepTest - { - [TestMethod] - public void RunStaticForeach() - { - Workflow workflow = new Workflow() - .Foreach(StaticEnumerateItem, - new Workflow>() - .Do(ActionInForeach) - ); - - //Workflow workflow = new Workflow() - // .Foreach(StaticEnumerateItem,ActionInForeach); - - workflow.Start(new ListState()); - Assert.AreEqual(10, workflow.Workload.StateFullVariable); - } - - [TestMethod] - public void RunDynamicForeach() - { - Workflow workflow = new Workflow() - .Do(DefineList) - .Foreach(DynamicEnumerateItem, - new Workflow>() - .Do(ActionInForeach) - ); - - workflow.Start(new ListState()); - Assert.AreEqual(20, workflow.Workload.StateFullVariable); - } - - public void DefineList(ListState state) - { - state.List = new List() { 5, 6, 9 }; - } - - public IEnumerable DynamicEnumerateItem(ListState state) - { - return state.List; - } - - public IEnumerable StaticEnumerateItem(ListState state) - { - return new List() { 3, 5, 2 }; - } - - public void ActionInForeach(Tuple state) - { - state.Item2.StateFullVariable += state.Item1; - } - } -} + [TestClass] + public class ForStepTest + { + [TestMethod] + public void RunStaticForeach() + { + var workflow = new Workflow() + .Foreach(StaticEnumerateItem, + new Workflow>() + .Do(ActionInForeach) + ); + + //Workflow workflow = new Workflow() + // .Foreach(StaticEnumerateItem,ActionInForeach); + + workflow.Start(new ListState()); + Assert.AreEqual(10, workflow.Workload.StateFullVariable); + } + + [TestMethod] + public void RunDynamicForeach() + { + var workflow = new Workflow() + .Do(DefineList) + .Foreach(DynamicEnumerateItem, + new Workflow>() + .Do(ActionInForeach) + ); + + workflow.Start(new ListState()); + Assert.AreEqual(20, workflow.Workload.StateFullVariable); + } + + public void DefineList(ListState state) + { + state.List = new List() { 5, 6, 9 }; + } + + public IEnumerable DynamicEnumerateItem(ListState state) + { + return state.List; + } + + public IEnumerable StaticEnumerateItem(ListState state) + { + return new List() { 3, 5, 2 }; + } + + public void ActionInForeach(Tuple state) + { + state.Item2.StateFullVariable += state.Item1; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/IfStepTest.cs b/Sources/TinyWorkflow.Tests/IfStepTest.cs index 0835d9e..cde273b 100644 --- a/Sources/TinyWorkflow.Tests/IfStepTest.cs +++ b/Sources/TinyWorkflow.Tests/IfStepTest.cs @@ -4,45 +4,45 @@ namespace TinyWorkflow.Tests { - [TestClass] - public class IfStepTest - { - [TestMethod] - public void RunIfTrue() - { - Workflow workflow = new Workflow() - .If(TestToTrue, ActionIfTrue, ActionIfFalse); - workflow.Start(new SimpleState()); - Assert.AreEqual(2, workflow.Workload.StateFullVariable); - } + [TestClass] + public class IfStepTest + { + [TestMethod] + public void RunIfTrue() + { + var workflow = new Workflow() + .If(TestToTrue, ActionIfTrue, ActionIfFalse); + workflow.Start(new SimpleState()); + Assert.AreEqual(2, workflow.Workload.StateFullVariable); + } - [TestMethod] - public void RunIfFalse() - { - Workflow workflow = new Workflow() - .If(TestToFalse, ActionIfTrue, ActionIfFalse); - workflow.Start(new SimpleState()); - Assert.AreEqual(3, workflow.Workload.StateFullVariable); - } + [TestMethod] + public void RunIfFalse() + { + var workflow = new Workflow() + .If(TestToFalse, ActionIfTrue, ActionIfFalse); + workflow.Start(new SimpleState()); + Assert.AreEqual(3, workflow.Workload.StateFullVariable); + } - public bool TestToTrue(SimpleState state) - { - return state.StateFullVariable == 0; - } + public bool TestToTrue(SimpleState state) + { + return state.StateFullVariable == 0; + } - public bool TestToFalse(SimpleState state) - { - return state.StateFullVariable != 0; - } + public bool TestToFalse(SimpleState state) + { + return state.StateFullVariable != 0; + } - public void ActionIfTrue(SimpleState state) - { - state.StateFullVariable = 2; - } + public void ActionIfTrue(SimpleState state) + { + state.StateFullVariable = 2; + } - public void ActionIfFalse(SimpleState state) - { - state.StateFullVariable = 3; - } - } -} + public void ActionIfFalse(SimpleState state) + { + state.StateFullVariable = 3; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/SimpleStepTest.cs b/Sources/TinyWorkflow.Tests/SimpleStepTest.cs index 36b190e..f17631a 100644 --- a/Sources/TinyWorkflow.Tests/SimpleStepTest.cs +++ b/Sources/TinyWorkflow.Tests/SimpleStepTest.cs @@ -4,60 +4,59 @@ namespace TinyWorkflow.Tests { - [TestClass] - public class SimpleStepTest - { - [TestMethod] - public void RunOneStep() - { - Workflow workflow = new Workflow() - .Do(EasyAction); - workflow.Start(new SimpleState()); - Assert.AreEqual(1, workflow.Workload.StateFullVariable); - } - - [TestMethod] - public void RunMultipleStepSequence() - { - Workflow workflow = new Workflow() - .Do(EasyAction) - .Do(EasyAction2) - .Do(EasyAction3); - workflow.Start(new SimpleState()); - Assert.AreEqual(3, workflow.Workload.StateFullVariable); - } - - [TestMethod] - public void RunHugeMultipleStep() - { - Workflow workflow = new Workflow(); - for (int i = 0; i < 500; i++) + [TestClass] + public class SimpleStepTest + { + [TestMethod] + public void RunOneStep() + { + var workflow = new Workflow() + .Do(EasyAction); + workflow.Start(new SimpleState()); + Assert.AreEqual(1, workflow.Workload.StateFullVariable); + } + + [TestMethod] + public void RunMultipleStepSequence() + { + var workflow = new Workflow() + .Do(EasyAction) + .Do(EasyAction2) + .Do(EasyAction3); + workflow.Start(new SimpleState()); + Assert.AreEqual(3, workflow.Workload.StateFullVariable); + } + + [TestMethod] + public void RunHugeMultipleStep() + { + Workflow workflow = new Workflow(); + for (int i = 0; i < 500; i++) { - workflow.Do(EasyActionAdd); + workflow.Do(EasyActionAdd); } - workflow.Start(new SimpleState()); - Assert.AreEqual(500, workflow.Workload.StateFullVariable); - } - - - public void EasyAction(SimpleState state) - { - state.StateFullVariable = 1; - } - - public void EasyAction2(SimpleState state) - { - state.StateFullVariable = 2; - } - - public void EasyAction3(SimpleState state) - { - state.StateFullVariable = 3; - } - - public void EasyActionAdd(SimpleState state) - { - state.StateFullVariable++; - } - } -} + workflow.Start(new SimpleState()); + Assert.AreEqual(500, workflow.Workload.StateFullVariable); + } + + public void EasyAction(SimpleState state) + { + state.StateFullVariable = 1; + } + + public void EasyAction2(SimpleState state) + { + state.StateFullVariable = 2; + } + + public void EasyAction3(SimpleState state) + { + state.StateFullVariable = 3; + } + + public void EasyActionAdd(SimpleState state) + { + state.StateFullVariable++; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.Tests/WhileStepTest.cs b/Sources/TinyWorkflow.Tests/WhileStepTest.cs index 91d3074..8954017 100644 --- a/Sources/TinyWorkflow.Tests/WhileStepTest.cs +++ b/Sources/TinyWorkflow.Tests/WhileStepTest.cs @@ -1,32 +1,32 @@ using System; +using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using TinyWorkflow.Tests.States; -using System.Collections.Generic; namespace TinyWorkflow.Tests { - [TestClass] - public class WhileStepTest - { - [TestMethod] - public void RunWhile() - { - Workflow workflow = new Workflow() - .While(WhileTest, WhileContent); + [TestClass] + public class WhileStepTest + { + [TestMethod] + public void RunWhile() + { + var workflow = new Workflow() + .While(WhileTest, WhileContent); - workflow.Start(new ConditionState() { MaxRun = 5}); - Assert.AreEqual(10, workflow.Workload.StateFullVariable); - } + workflow.Start(new ConditionState() { MaxRun = 5 }); + Assert.AreEqual(10, workflow.Workload.StateFullVariable); + } - public void WhileContent(ConditionState state) - { - state.StateFullVariable += state.ActualRun; - state.ActualRun++; - } + public void WhileContent(ConditionState state) + { + state.StateFullVariable += state.ActualRun; + state.ActualRun++; + } - public bool WhileTest(ConditionState state) - { - return state.ActualRun < state.MaxRun; - } - } -} + public bool WhileTest(ConditionState state) + { + return state.ActualRun < state.MaxRun; + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow.sln b/Sources/TinyWorkflow.sln index 87a43ec..8759ae8 100644 --- a/Sources/TinyWorkflow.sln +++ b/Sources/TinyWorkflow.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyWorkflow", "TinyWorkflow\TinyWorkflow.csproj", "{EB78B492-6A7E-439C-9000-32BDE7B8CB53}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyWorkflow.Tests", "TinyWorkflow.Tests\TinyWorkflow.Tests.csproj", "{FA775B80-F4D4-4AE0-8E71-1559D6089E13}" @@ -8,21 +10,6 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyWorkflow.UITests", "TinyWorkflow.UITests\TinyWorkflow.UITests.csproj", "{25B9A518-CBD6-4FAD-A124-26C76641AD3C}" EndProject Global - GlobalSection(TeamFoundationVersionControl) = preSolution - SccNumberOfProjects = 4 - SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} - SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs03 - SccLocalPath0 = . - SccProjectUniqueName1 = TinyWorkflow.Tests\\TinyWorkflow.Tests.csproj - SccProjectName1 = TinyWorkflow.Tests - SccLocalPath1 = TinyWorkflow.Tests - SccProjectUniqueName2 = TinyWorkflow\\TinyWorkflow.csproj - SccProjectName2 = TinyWorkflow - SccLocalPath2 = TinyWorkflow - SccProjectUniqueName3 = TinyWorkflow.UITests\\TinyWorkflow.UITests.csproj - SccProjectName3 = TinyWorkflow.UITests - SccLocalPath3 = TinyWorkflow.UITests - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU diff --git a/Sources/TinyWorkflow/Actions/BlockWorkflowAction.cs b/Sources/TinyWorkflow/Actions/BlockWorkflowAction.cs index 4a7b52e..b7340a6 100644 --- a/Sources/TinyWorkflow/Actions/BlockWorkflowAction.cs +++ b/Sources/TinyWorkflow/Actions/BlockWorkflowAction.cs @@ -1,85 +1,83 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TinyWorkflow.Actions { - internal class BlockWorkflowAction : WorkflowAction - { - #region Public properties + internal class BlockWorkflowAction : WorkflowAction + { + #region Public properties - public override WorkflowActionState State - { - get - { - if (!BlockCount.HasValue) - { - return WorkflowActionState.Ready; - } - else if (BlockCount.Value > UnblockedCount) - { - return WorkflowActionState.Blocked; - } - else - { - return WorkflowActionState.Ended; - } - } - } + public override WorkflowActionState State + { + get + { + if (!BlockCount.HasValue) + { + return WorkflowActionState.Ready; + } + else if (BlockCount.Value > UnblockedCount) + { + return WorkflowActionState.Blocked; + } + else + { + return WorkflowActionState.Ended; + } + } + } - /// - /// Function that will return dynamicaly the number of block count. - /// - public Func BlockCountFunc { get; private set; } - /// - /// Once resolved, keep the value of block count. - /// - public int? BlockCount { get; private set; } - /// - /// How many times the unblock method has been called. - /// - public int UnblockedCount { get; private set; } + /// + /// Function that will return dynamicaly the number of block count. + /// + public Func BlockCountFunc { get; private set; } - #endregion + /// + /// Once resolved, keep the value of block count. + /// + public int? BlockCount { get; private set; } - #region Ctor + /// + /// How many times the unblock method has been called. + /// + public int UnblockedCount { get; private set; } - public BlockWorkflowAction(Func blockCount) - { - BlockCountFunc = blockCount; - } + #endregion Public properties - #endregion + #region Ctor - #region Public methods + public BlockWorkflowAction(Func blockCount) + { + BlockCountFunc = blockCount; + } - public override void Reset() - { - UnblockedCount = 0; - } + #endregion Ctor - #endregion + #region Public methods - public override void Resolve(T obj) - { - BlockCount = BlockCountFunc(obj); - } + public override void Reset() + { + UnblockedCount = 0; + } - public override void Unblock(int unblockLevel) - { - lock (this) - { - if (unblockLevel == Int32.MaxValue) - { - UnblockedCount = Int32.MaxValue; - } - else - { - UnblockedCount += unblockLevel; - } - } - } - } -} + #endregion Public methods + + public override void Resolve(T obj) + { + BlockCount = BlockCountFunc(obj); + } + + public override void Unblock(int unblockLevel) + { + lock (this) + { + if (unblockLevel == Int32.MaxValue) + { + UnblockedCount = Int32.MaxValue; + } + else + { + UnblockedCount += unblockLevel; + } + } + } + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/Actions/ForWorkflowAction.cs b/Sources/TinyWorkflow/Actions/ForWorkflowAction.cs index 1719d30..eb38b14 100644 --- a/Sources/TinyWorkflow/Actions/ForWorkflowAction.cs +++ b/Sources/TinyWorkflow/Actions/ForWorkflowAction.cs @@ -1,125 +1,125 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TinyWorkflow.Actions { - internal class ForWorkflowAction : WorkflowAction - { - #region Public properties - - public override WorkflowActionState State - { - get - { - if (Workflow.State == WorkflowState.End) - { - return WorkflowActionState.Ended; - } - if (Workflow.State == WorkflowState.Blocked) - { - return WorkflowActionState.Blocked; - } - return WorkflowActionState.Ready; - } - } - - public Func> Enumarator { get; private set; } - - public Workflow> Workflow { get; private set; } - - #endregion - - #region Private Variables - - private List ResolvedEnumerator; - - private int indexOfRun; - - private T LastState; - - #endregion - - #region Ctor - - public ForWorkflowAction(Func> enumerator, Workflow> workflow) - { - Workflow = workflow; - Enumarator = enumerator; - indexOfRun = 0; - } - - #endregion - - #region Public methods - - public override void Reset() - { - indexOfRun = 0; - if (Workflow != null) - { - Workflow.Reset(); - } - } - - /// - /// Resolve the dynamic part of the step. - /// - /// - public override void Resolve(T obj) - { - LastState = obj; - ResolvedEnumerator = Enumarator(obj).ToList(); - } - - /// - /// Run the step - /// - /// - public override void Run(T obj) - { - LastState = obj; - - if (indexOfRun >= ResolvedEnumerator.Count) - { - //Workflow part is done before starting. - //No items to iterate. - Workflow.End(); - } - else - { - do - { - Workflow.Start(new Tuple(ResolvedEnumerator[indexOfRun], obj)); - switch (Workflow.State) - { - case WorkflowState.End: - indexOfRun++; - if (indexOfRun < ResolvedEnumerator.Count) - { - Workflow.Reset(); - } - break; - case WorkflowState.Blocked: - return; - } - } - while (indexOfRun < ResolvedEnumerator.Count); - } - } - - public override void Unblock(int unblockLevel) - { - Workflow.UnblockInternal(unblockLevel); - //Run(LastState); - //if (indexOfRun >= ResolvedEnumerator.Count) - //{ - // Workflow.Reset(); - //} - } - #endregion - - } -} + internal class ForWorkflowAction : WorkflowAction + { + #region Public properties + + public override WorkflowActionState State + { + get + { + if (Workflow.State == WorkflowState.End) + { + return WorkflowActionState.Ended; + } + if (Workflow.State == WorkflowState.Blocked) + { + return WorkflowActionState.Blocked; + } + return WorkflowActionState.Ready; + } + } + + public Func> Enumarator { get; private set; } + + public IWorkflow> Workflow { get; private set; } + + #endregion Public properties + + #region Private Variables + + private List ResolvedEnumerator; + + private int indexOfRun; + + private T LastState; + + #endregion Private Variables + + #region Ctor + + public ForWorkflowAction(Func> enumerator, IWorkflow> workflow) + { + Workflow = workflow; + Enumarator = enumerator; + indexOfRun = 0; + } + + #endregion Ctor + + #region Public methods + + public override void Reset() + { + indexOfRun = 0; + if (Workflow != null) + { + Workflow.Reset(); + } + } + + /// + /// Resolve the dynamic part of the step. + /// + /// + public override void Resolve(T obj) + { + LastState = obj; + ResolvedEnumerator = Enumarator(obj).ToList(); + } + + /// + /// Run the step + /// + /// + public override void Run(T obj) + { + LastState = obj; + + if (indexOfRun >= ResolvedEnumerator.Count) + { + //Workflow part is done before starting. + //No items to iterate. + Workflow.End(); + } + else + { + do + { + Workflow.Start(new Tuple(ResolvedEnumerator[indexOfRun], obj)); + switch (Workflow.State) + { + case WorkflowState.End: + indexOfRun++; + if (indexOfRun < ResolvedEnumerator.Count) + { + Workflow.Reset(); + } + break; + + case WorkflowState.Blocked: + return; + } + } + while (indexOfRun < ResolvedEnumerator.Count); + } + } + + public override void Unblock(int unblockLevel) + { + var wf = Workflow as Workflow; + wf?.UnblockInternal(unblockLevel); + //Run(LastState); + //if (indexOfRun >= ResolvedEnumerator.Count) + //{ + // Workflow.Reset(); + //} + } + + #endregion Public methods + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/Actions/GoWorkflowAction.cs b/Sources/TinyWorkflow/Actions/GoWorkflowAction.cs index b4e3342..3184f36 100644 --- a/Sources/TinyWorkflow/Actions/GoWorkflowAction.cs +++ b/Sources/TinyWorkflow/Actions/GoWorkflowAction.cs @@ -1,59 +1,56 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TinyWorkflow.Actions { - internal class GoWorkflowAction : WorkflowAction - { - #region Public properties - /// - /// Action embeded in the step - /// - public Action Action { get; private set; } + internal class GoWorkflowAction : WorkflowAction + { + #region Public properties - public override WorkflowActionState State - { - get { return state; } - } + /// + /// Action embeded in the step + /// + public Action Action { get; private set; } - #endregion + public override WorkflowActionState State + { + get { return state; } + } - #region Private Variables + #endregion Public properties - private WorkflowActionState state; + #region Private Variables - #endregion + private WorkflowActionState state; - #region Ctor + #endregion Private Variables - public GoWorkflowAction(Action action) - { - Action = action; - state = WorkflowActionState.Ready; - } + #region Ctor - #endregion + public GoWorkflowAction(Action action) + { + Action = action; + state = WorkflowActionState.Ready; + } - #region Public methods + #endregion Ctor - public override void Reset() - { - state = WorkflowActionState.Ready; - } + #region Public methods - /// - /// Run the step - /// - /// - public override void Run(T obj) - { - Action(obj); - state = WorkflowActionState.Ended; - } + public override void Reset() + { + state = WorkflowActionState.Ready; + } - #endregion - } -} + /// + /// Run the step + /// + /// + public override void Run(T obj) + { + Action(obj); + state = WorkflowActionState.Ended; + } + + #endregion Public methods + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/Actions/IfWorkflowAction.cs b/Sources/TinyWorkflow/Actions/IfWorkflowAction.cs index a282c72..230e295 100644 --- a/Sources/TinyWorkflow/Actions/IfWorkflowAction.cs +++ b/Sources/TinyWorkflow/Actions/IfWorkflowAction.cs @@ -1,140 +1,141 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TinyWorkflow.Actions { - internal class IfWorkflowAction : WorkflowAction - { - #region Public properties - - public override WorkflowActionState State - { - get - { - var tempWF = EvaluatedConditionOnResolve == true ? WorkflowIfTrue : null; - tempWF = EvaluatedConditionOnResolve == false ? WorkflowIfFalse : tempWF; - - if (tempWF != null) - { - if (tempWF.State == WorkflowState.Blocked) - { - return WorkflowActionState.Blocked; - } - - if (tempWF.State == WorkflowState.End) - { - return WorkflowActionState.Ended; - } - } - - return WorkflowActionState.Ready; - } - } - - /// - /// Action embeded in the step if True - /// - public Workflow WorkflowIfTrue { get; private set; } - - /// - /// Action embeded in the step if False - /// - public Workflow WorkflowIfFalse { get; private set; } - - /// - /// Condition for steps - /// - public Func Condition { get; private set; } - - /// - /// Dynamic query that is used in cas of 'for'. Must be evaluated just before being run. - /// - public Func>> DynamicQuery { get; private set; } - - #endregion - - #region Private Variables - - private bool? EvaluatedConditionOnResolve { get; set; } - - #endregion - - #region Ctor - - public IfWorkflowAction(Func condition, Action actionIfTrue, Action actionIfFalse) - : this(condition, new Workflow().Do(actionIfTrue), new Workflow().Do(actionIfFalse)) - { - } - - public IfWorkflowAction(Func condition, Workflow actionIfTrue, Workflow actionIfFalse) - { - Condition = condition; - WorkflowIfTrue = actionIfTrue; - WorkflowIfFalse = actionIfFalse; - } - #endregion - - #region Public methods - - public override void Reset() - { - if (WorkflowIfTrue != null) - { - WorkflowIfTrue.Reset(); - } - if (WorkflowIfFalse != null) - { - WorkflowIfFalse.Reset(); - } - } - - public override void Resolve(T obj) - { - EvaluatedConditionOnResolve = Condition(obj); - } - - public override void Run(T obj) - { - if (EvaluatedConditionOnResolve == true) - { - if (WorkflowIfTrue != null) - { - WorkflowIfTrue.Start(obj); - } - } - else if (EvaluatedConditionOnResolve == false) - { - if (WorkflowIfFalse != null) - { - WorkflowIfFalse.Start(obj); - } - } - else - { - throw new Exception("If part is not resolved"); - } - } - - public override void Unblock(int unblockLevel) - { - if (EvaluatedConditionOnResolve == true) - { - if (WorkflowIfTrue != null) - { - WorkflowIfTrue.UnblockInternal(unblockLevel); - } - } - else if (EvaluatedConditionOnResolve == false) - { - if (WorkflowIfFalse != null) - { - WorkflowIfFalse.UnblockInternal(unblockLevel); - } - } - } - #endregion - } -} + internal class IfWorkflowAction : WorkflowAction + { + #region Public properties + + public override WorkflowActionState State + { + get + { + var tempWF = EvaluatedConditionOnResolve == true ? WorkflowIfTrue : null; + tempWF = EvaluatedConditionOnResolve == false ? WorkflowIfFalse : tempWF; + + if (tempWF != null) + { + if (tempWF.State == WorkflowState.Blocked) + { + return WorkflowActionState.Blocked; + } + + if (tempWF.State == WorkflowState.End) + { + return WorkflowActionState.Ended; + } + } + + return WorkflowActionState.Ready; + } + } + + /// + /// Action embeded in the step if True + /// + public IWorkflow WorkflowIfTrue { get; private set; } + + /// + /// Action embeded in the step if False + /// + public IWorkflow WorkflowIfFalse { get; private set; } + + /// + /// Condition for steps + /// + public Func Condition { get; private set; } + + /// + /// Dynamic query that is used in cas of 'for'. Must be evaluated just before being run. + /// + public Func>> DynamicQuery { get; private set; } + + #endregion Public properties + + #region Private Variables + + private bool? EvaluatedConditionOnResolve { get; set; } + + #endregion Private Variables + + #region Ctor + + public IfWorkflowAction(Func condition, Action actionIfTrue, Action actionIfFalse) + : this(condition, new Workflow().Do(actionIfTrue), new Workflow().Do(actionIfFalse)) + { + } + + public IfWorkflowAction(Func condition, IWorkflow actionIfTrue, IWorkflow actionIfFalse) + { + Condition = condition; + WorkflowIfTrue = actionIfTrue; + WorkflowIfFalse = actionIfFalse; + } + + #endregion Ctor + + #region Public methods + + public override void Reset() + { + if (WorkflowIfTrue != null) + { + WorkflowIfTrue.Reset(); + } + if (WorkflowIfFalse != null) + { + WorkflowIfFalse.Reset(); + } + } + + public override void Resolve(T obj) + { + EvaluatedConditionOnResolve = Condition(obj); + } + + public override void Run(T obj) + { + if (EvaluatedConditionOnResolve == true) + { + if (WorkflowIfTrue != null) + { + WorkflowIfTrue.Start(obj); + } + } + else if (EvaluatedConditionOnResolve == false) + { + if (WorkflowIfFalse != null) + { + WorkflowIfFalse.Start(obj); + } + } + else + { + throw new Exception("If part is not resolved"); + } + } + + public override void Unblock(int unblockLevel) + { + if (EvaluatedConditionOnResolve == true) + { + var wfTrue = WorkflowIfTrue as Workflow; + if (wfTrue != null) + { + wfTrue.UnblockInternal(unblockLevel); + } + } + else if (EvaluatedConditionOnResolve == false) + { + var wfFalse = WorkflowIfFalse as Workflow; + if (wfFalse != null) + { + wfFalse.UnblockInternal(unblockLevel); + } + } + } + + #endregion Public methods + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/Actions/MultipleGoWorkflowAction.cs b/Sources/TinyWorkflow/Actions/MultipleGoWorkflowAction.cs index 8473762..4a73c69 100644 --- a/Sources/TinyWorkflow/Actions/MultipleGoWorkflowAction.cs +++ b/Sources/TinyWorkflow/Actions/MultipleGoWorkflowAction.cs @@ -1,58 +1,56 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; namespace TinyWorkflow.Actions { - internal class MultipleGoWorkflowAction : WorkflowAction - { - #region Public properties - /// - /// Action embeded in the step - /// - public Action[] Actions { get; private set; } + internal class MultipleGoWorkflowAction : WorkflowAction + { + #region Public properties - public override WorkflowActionState State - { - get { return state; } - } + /// + /// Action embeded in the step + /// + public Action[] Actions { get; private set; } - #endregion + public override WorkflowActionState State + { + get { return state; } + } - #region Private Variables + #endregion Public properties - private WorkflowActionState state; + #region Private Variables - #endregion + private WorkflowActionState state; - #region Ctor + #endregion Private Variables - public MultipleGoWorkflowAction(Action[] actions) - { - Actions = actions; - state = WorkflowActionState.Ready; - } + #region Ctor - #endregion + public MultipleGoWorkflowAction(Action[] actions) + { + Actions = actions; + state = WorkflowActionState.Ready; + } - #region Public methods + #endregion Ctor - public override void Reset() - { - state = WorkflowActionState.Ready; - } + #region Public methods - public override void Run(T obj) - { - foreach (var item in Actions) - { - Task.Factory.StartNew(() => item(obj)); - } - state = WorkflowActionState.Ended; - } + public override void Reset() + { + state = WorkflowActionState.Ready; + } - #endregion - } -} + public override void Run(T obj) + { + foreach (var item in Actions) + { + Task.Factory.StartNew(() => item(obj)); + } + state = WorkflowActionState.Ended; + } + + #endregion Public methods + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/Actions/WhileWorkflowAction.cs b/Sources/TinyWorkflow/Actions/WhileWorkflowAction.cs index 7d9201e..a1f565f 100644 --- a/Sources/TinyWorkflow/Actions/WhileWorkflowAction.cs +++ b/Sources/TinyWorkflow/Actions/WhileWorkflowAction.cs @@ -1,126 +1,125 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TinyWorkflow.Actions { - internal class WhileWorkflowAction : WorkflowAction - { - #region Public properties - - /// - /// Action embeded in the step - /// - public Workflow Workflow { get; private set; } - - /// - /// Condition for running the step - /// - public Func ConditionToRun { get; private set; } - - /// - /// Condition result, once evaluated. - /// - public bool? CachedConditionToRun { get; private set; } - - public override WorkflowActionState State - { - get - { - if (!CachedConditionToRun.HasValue) - { - return WorkflowActionState.Ready; - } - else if (CachedConditionToRun == true) - { - if (Workflow.State == WorkflowState.End) - { - return WorkflowActionState.Ended; - } - if (Workflow.State == WorkflowState.Blocked) - { - return WorkflowActionState.Blocked; - } - return WorkflowActionState.Ready; - } - else - { - return WorkflowActionState.Ended; - } - } - } - - #endregion - - #region Private Variables - - private T _State; - - #endregion - - #region Ctor - - public WhileWorkflowAction(Func conditionToRun, Action action) - :this(conditionToRun, new Workflow().Do(action)) - { - } - - public WhileWorkflowAction(Func conditionToRun, Workflow workflow) - { - Workflow = workflow; - ConditionToRun = conditionToRun; - } - - #endregion - - #region Public methods - - private bool EvaluateCondition(T obj) - { - CachedConditionToRun = ConditionToRun(obj); - return CachedConditionToRun.Value; - } - - public override void Reset() - { - if (Workflow != null) - { - Workflow.Reset(); - } - CachedConditionToRun = null; - } - - public override void Run(T obj) - { - _State = obj; - if (Workflow != null) - { - if (EvaluateCondition(obj)) - { - Workflow.Start(obj); - - if (Workflow.State == WorkflowState.End && EvaluateCondition(obj)) - { - Workflow.Reset(); - } - } - } - } - - public override void Unblock(int unblockLevel) - { - if (Workflow != null) - { - Workflow.UnblockInternal(unblockLevel); - - //if (Workflow.State == WorkflowState.End && EvaluateCondition(_State)) - //{ - // Workflow.Reset(); - //} - } - } - #endregion - } -} + internal class WhileWorkflowAction : WorkflowAction + { + #region Public properties + + /// + /// Action embeded in the step + /// + public IWorkflow Workflow { get; private set; } + + /// + /// Condition for running the step + /// + public Func ConditionToRun { get; private set; } + + /// + /// Condition result, once evaluated. + /// + public bool? CachedConditionToRun { get; private set; } + + public override WorkflowActionState State + { + get + { + if (!CachedConditionToRun.HasValue) + { + return WorkflowActionState.Ready; + } + else if (CachedConditionToRun == true) + { + if (Workflow.State == WorkflowState.End) + { + return WorkflowActionState.Ended; + } + if (Workflow.State == WorkflowState.Blocked) + { + return WorkflowActionState.Blocked; + } + return WorkflowActionState.Ready; + } + else + { + return WorkflowActionState.Ended; + } + } + } + + #endregion Public properties + + #region Private Variables + + private T _State; + + #endregion Private Variables + + #region Ctor + + public WhileWorkflowAction(Func conditionToRun, Action action) + : this(conditionToRun, new Workflow().Do(action)) + { + } + + public WhileWorkflowAction(Func conditionToRun, IWorkflow workflow) + { + Workflow = workflow; + ConditionToRun = conditionToRun; + } + + #endregion Ctor + + #region Public methods + + private bool EvaluateCondition(T obj) + { + CachedConditionToRun = ConditionToRun(obj); + return CachedConditionToRun.Value; + } + + public override void Reset() + { + if (Workflow != null) + { + Workflow.Reset(); + } + CachedConditionToRun = null; + } + + public override void Run(T obj) + { + _State = obj; + if (Workflow != null) + { + if (EvaluateCondition(obj)) + { + Workflow.Start(obj); + + if (Workflow.State == WorkflowState.End && EvaluateCondition(obj)) + { + Workflow.Reset(); + } + } + } + } + + public override void Unblock(int unblockLevel) + { + var wf = Workflow as Workflow; + + if (wf != null) + { + wf.UnblockInternal(unblockLevel); + + //if (Workflow.State == WorkflowState.End && EvaluateCondition(_State)) + //{ + // Workflow.Reset(); + //} + } + } + + #endregion Public methods + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/Actions/WorkflowAction.cs b/Sources/TinyWorkflow/Actions/WorkflowAction.cs index 9771df7..75abfa1 100644 --- a/Sources/TinyWorkflow/Actions/WorkflowAction.cs +++ b/Sources/TinyWorkflow/Actions/WorkflowAction.cs @@ -1,64 +1,54 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace TinyWorkflow.Actions +namespace TinyWorkflow.Actions { - /// - /// Workflow action that is representing a workflow step. - /// - /// Type of the state linked to the workflow. - internal abstract class WorkflowAction - { - #region Public properties - - /// - /// State of the workflow. - /// - public abstract WorkflowActionState State { get; } - #endregion - - #region Public methods - - /// - /// Resolve the dynamic part of the step. - /// - /// - public virtual void Resolve(T obj) - { - - } - - /// - /// Reset the action to it's initial state. - /// - /// - public virtual void Reset() - { - - } - - /// - /// Run the step - /// - /// - public virtual void Run(T obj) - { - - } - - /// - /// Unblock the step. - /// - /// - public virtual void Unblock(int unblockLevel) - { - - } - - #endregion - } -} + /// + /// Workflow action that is representing a workflow step. + /// + /// Type of the state linked to the workflow. + internal abstract class WorkflowAction + { + #region Public properties + + /// + /// State of the workflow. + /// + public abstract WorkflowActionState State { get; } + + #endregion Public properties + + #region Public methods + + /// + /// Resolve the dynamic part of the step. + /// + /// + public virtual void Resolve(T obj) + { + } + + /// + /// Reset the action to it's initial state. + /// + /// + public virtual void Reset() + { + } + + /// + /// Run the step + /// + /// + public virtual void Run(T obj) + { + } + + /// + /// Unblock the step. + /// + /// + public virtual void Unblock(int unblockLevel) + { + } + + #endregion Public methods + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/Actions/WorkflowActionState.cs b/Sources/TinyWorkflow/Actions/WorkflowActionState.cs index 0b4a58a..b097c9a 100644 --- a/Sources/TinyWorkflow/Actions/WorkflowActionState.cs +++ b/Sources/TinyWorkflow/Actions/WorkflowActionState.cs @@ -1,27 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TinyWorkflow.Actions +namespace TinyWorkflow.Actions { - /// - /// State of an action. - /// - internal enum WorkflowActionState - { - /// - /// Ready to be run. - /// - Ready, - /// - /// Blocked. Waiting for an unblock command. - /// - Blocked, - /// - /// Has been run and is finised. - /// - Ended, - } -} + /// + /// State of an action. + /// + internal enum WorkflowActionState + { + /// + /// Ready to be run. + /// + Ready, + + /// + /// Blocked. Waiting for an unblock command. + /// + Blocked, + + /// + /// Has been run and is finised. + /// + Ended, + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/IWorkflow.cs b/Sources/TinyWorkflow/IWorkflow.cs new file mode 100644 index 0000000..2f23d6a --- /dev/null +++ b/Sources/TinyWorkflow/IWorkflow.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +namespace TinyWorkflow +{ + public interface IWorkflow + { + T Workload { get; set; } + + WorkflowState State { get; } + + void Start(T workload); + + void End(); + + void Reset(); + + void Unblock(); + + void Unblock(int level); + + void UnblockAll(); + + IWorkflow Block(); + + IWorkflow Block(int blockCount); + + IWorkflow Block(Func blockCount); + + IWorkflow Do(Action action); + + IWorkflow DoAsynch(params Action[] actions); + + IWorkflow Foreach(Func> itemExtractor, Action> action); + + IWorkflow Foreach(Func> itemExtractor, IWorkflow> workflow); + + IWorkflow While(Func condition, Action action); + + IWorkflow While(Func condition, IWorkflow workflow); + + IWorkflow If(Func condition, Action actionIfTrue, Action actionIfFalse); + + IWorkflow If(Func condition, IWorkflow actionsIfTrue, IWorkflow actionsIfFalse); + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/IWorkflowFactory.cs b/Sources/TinyWorkflow/IWorkflowFactory.cs new file mode 100644 index 0000000..6e32ff4 --- /dev/null +++ b/Sources/TinyWorkflow/IWorkflowFactory.cs @@ -0,0 +1,7 @@ +namespace TinyWorkflow +{ + public interface IWorkflowFactory + { + IWorkflow Create(); + } +} \ No newline at end of file diff --git a/Sources/TinyWorkflow/TinyWorkflow.csproj b/Sources/TinyWorkflow/TinyWorkflow.csproj index 3300ba6..ac9cdba 100644 --- a/Sources/TinyWorkflow/TinyWorkflow.csproj +++ b/Sources/TinyWorkflow/TinyWorkflow.csproj @@ -1,20 +1,21 @@  - + + 14.0 Debug AnyCPU {EB78B492-6A7E-439C-9000-32BDE7B8CB53} Library Properties TinyWorkflow - TinyWorkflow - v4.5 + TinyWorkflow.Core + en-US 512 - SAK - SAK - SAK - SAK + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + v5.0 true @@ -32,16 +33,10 @@ TRACE prompt 4 - bin\Release\TinyWorkflow.XML - - - - - - - + + @@ -52,11 +47,14 @@ + + + - +