|
| 1 | +using OptimaJet.Workflow.Core.Runtime; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading; |
| 7 | +using System.Threading.Tasks; |
| 8 | + |
| 9 | +namespace WorkflowApp |
| 10 | +{ |
| 11 | + class Program |
| 12 | + { |
| 13 | + static string schemeCode = "SimpleWF"; |
| 14 | + static Guid? processId = null; |
| 15 | + static void Main(string[] args) |
| 16 | + { |
| 17 | + Console.WriteLine("Operation:"); |
| 18 | + Console.WriteLine("0 - CreateInstance"); |
| 19 | + Console.WriteLine("1 - GetAvailableCommands"); |
| 20 | + Console.WriteLine("2 - ExecuteCommand"); |
| 21 | + Console.WriteLine("3 - GetAvailableState"); |
| 22 | + Console.WriteLine("4 - SetState"); |
| 23 | + Console.WriteLine("5 - DeleteProcess"); |
| 24 | + Console.WriteLine("9 - Exit"); |
| 25 | + |
| 26 | + Console.WriteLine("The process isn't created."); |
| 27 | + CreateInstance(); |
| 28 | + |
| 29 | + do |
| 30 | + { |
| 31 | + if (processId.HasValue) |
| 32 | + { |
| 33 | + Console.WriteLine("ProcessId = '{0}'. CurrentState: {1}, CurrentActivity: {2}", |
| 34 | + processId, |
| 35 | + WorkflowInit.Runtime.GetCurrentStateName(processId.Value), |
| 36 | + WorkflowInit.Runtime.GetCurrentActivityName(processId.Value)); |
| 37 | + } |
| 38 | + |
| 39 | + Console.Write("Enter code of operation:"); |
| 40 | + char operation = Console.ReadLine().FirstOrDefault(); |
| 41 | + |
| 42 | + switch (operation) |
| 43 | + { |
| 44 | + case '0': |
| 45 | + CreateInstance(); |
| 46 | + break; |
| 47 | + case '1': |
| 48 | + GetAvailableCommands(); |
| 49 | + break; |
| 50 | + case '2': |
| 51 | + ExecuteCommand(); |
| 52 | + break; |
| 53 | + case '3': |
| 54 | + GetAvailableState(); |
| 55 | + break; |
| 56 | + case '4': |
| 57 | + SetState(); |
| 58 | + break; |
| 59 | + case '5': |
| 60 | + DeleteProcess(); |
| 61 | + break; |
| 62 | + case '9': |
| 63 | + return; |
| 64 | + default: |
| 65 | + Console.WriteLine("Unknown code. Please, repeat."); |
| 66 | + break; |
| 67 | + } |
| 68 | + |
| 69 | + Console.WriteLine(); |
| 70 | + } while (true); |
| 71 | + } |
| 72 | + |
| 73 | + private static void CreateInstance() |
| 74 | + { |
| 75 | + processId = Guid.NewGuid(); |
| 76 | + try |
| 77 | + { |
| 78 | + WorkflowApp.WorkflowInit.Runtime.CreateInstance(schemeCode, processId.Value); |
| 79 | + Console.WriteLine("CreateInstance - OK.", processId); |
| 80 | + } |
| 81 | + catch (Exception ex) |
| 82 | + { |
| 83 | + Console.WriteLine("CreateInstance - Exception: {0}", ex.Message); |
| 84 | + processId = null; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + private static void GetAvailableCommands() |
| 89 | + { |
| 90 | + if (processId == null) |
| 91 | + { |
| 92 | + Console.WriteLine("The process isn't created. Please, create process instance."); |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + var commands = WorkflowInit.Runtime.GetAvailableCommands(processId.Value, string.Empty); |
| 97 | + |
| 98 | + Console.WriteLine("Available commands:"); |
| 99 | + if (commands.Count() == 0) |
| 100 | + { |
| 101 | + Console.WriteLine("Not found!"); |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + foreach (var command in commands) |
| 106 | + { |
| 107 | + Console.WriteLine("- {0} (LocalizedName:{1}, Classifier:{2})", command.CommandName, command.LocalizedName, command.Classifier); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + private static void ExecuteCommand() |
| 113 | + { |
| 114 | + if (processId == null) |
| 115 | + { |
| 116 | + Console.WriteLine("The process isn't created. Please, create process instance."); |
| 117 | + return; |
| 118 | + } |
| 119 | + |
| 120 | + WorkflowCommand command = null; |
| 121 | + |
| 122 | + do |
| 123 | + { |
| 124 | + GetAvailableCommands(); |
| 125 | + Console.Write("Enter command:"); |
| 126 | + var commandName = Console.ReadLine().ToLower().Trim(); |
| 127 | + if (commandName == string.Empty) |
| 128 | + return; |
| 129 | + |
| 130 | + command = WorkflowInit.Runtime.GetAvailableCommands(processId.Value, string.Empty) |
| 131 | + .Where(c => c.CommandName.Trim().ToLower() == commandName).FirstOrDefault(); |
| 132 | + if (command == null) |
| 133 | + Console.WriteLine("The command isn't found."); |
| 134 | + } while (command == null); |
| 135 | + |
| 136 | + WorkflowInit.Runtime.ExecuteCommand(processId.Value, string.Empty, string.Empty, command); |
| 137 | + Console.WriteLine("ExecuteCommand - OK.", processId); |
| 138 | + } |
| 139 | + |
| 140 | + private static void GetAvailableState() |
| 141 | + { |
| 142 | + if (processId == null) |
| 143 | + { |
| 144 | + Console.WriteLine("The process isn't created. Please, create process instance."); |
| 145 | + return; |
| 146 | + } |
| 147 | + |
| 148 | + var states = WorkflowInit.Runtime.GetAvailableStateToSet(processId.Value, Thread.CurrentThread.CurrentCulture); |
| 149 | + Console.WriteLine("Available state to set:"); |
| 150 | + |
| 151 | + if (states.Count() == 0) |
| 152 | + { |
| 153 | + Console.WriteLine("Not found!"); |
| 154 | + } |
| 155 | + else |
| 156 | + { |
| 157 | + foreach (var state in states) |
| 158 | + { |
| 159 | + Console.WriteLine("- {0}", state.Name); |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + |
| 164 | + private static void SetState() |
| 165 | + { |
| 166 | + if (processId == null) |
| 167 | + { |
| 168 | + Console.WriteLine("The process isn't created. Please, create process instance."); |
| 169 | + return; |
| 170 | + } |
| 171 | + |
| 172 | + string stateName = string.Empty; |
| 173 | + WorkflowState state; |
| 174 | + do |
| 175 | + { |
| 176 | + GetAvailableState(); |
| 177 | + Console.Write("Enter state:"); |
| 178 | + stateName = Console.ReadLine().ToLower().Trim(); |
| 179 | + if (stateName == string.Empty) |
| 180 | + return; |
| 181 | + |
| 182 | + state = WorkflowInit.Runtime.GetAvailableStateToSet(processId.Value, Thread.CurrentThread.CurrentCulture) |
| 183 | + .Where(c => c.Name.Trim().ToLower() == stateName).FirstOrDefault(); |
| 184 | + if (state == null) |
| 185 | + Console.WriteLine("The state isn't found."); |
| 186 | + else |
| 187 | + break; |
| 188 | + } while (true); |
| 189 | + |
| 190 | + if (state != null) |
| 191 | + { |
| 192 | + WorkflowInit.Runtime.SetState(processId.Value, string.Empty, string.Empty, state.Name, new Dictionary<string, object>()); |
| 193 | + Console.WriteLine("SetState - OK.", processId); |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | + private static void DeleteProcess() |
| 198 | + { |
| 199 | + if (processId == null) |
| 200 | + { |
| 201 | + Console.WriteLine("The process isn't created. Please, create process instance."); |
| 202 | + return; |
| 203 | + } |
| 204 | + |
| 205 | + WorkflowInit.Runtime.PersistenceProvider.DeleteProcess(processId.Value); |
| 206 | + Console.WriteLine("DeleteProcess - OK.", processId); |
| 207 | + processId = null; |
| 208 | + } |
| 209 | + } |
| 210 | +} |
0 commit comments