private void GenereateDate(IDatabase db) { var batch = db.CreateBatch(); var roles = new RedisValue[] { "Big Boss", "Accountant", "User" }; batch.SetAddAsync(GetKeyForRolesSet(), roles); var sd = new List <StructDivision>() { new StructDivision() { Id = new Guid("B14F5D81-5B0D-4ACC-92B8-27CBBE39086B"), Name = "Group 1", ParentId = new Guid("F6E34BDF-B769-42DD-A2BE-FEE67FAF9045"), Heads = new List <Guid>() { new Guid("DEB579F9-991C-4DB9-A17D-BB1ECCF2842C") } }, new StructDivision() { Id = new Guid("7E9FD972-C775-4C6B-9D91-47E9397BD2E6"), Name = "Group 1.1", ParentId = new Guid("B14F5D81-5B0D-4ACC-92B8-27CBBE39086B"), Heads = new List <Guid>() { new Guid("91F2B471-4A96-4AB7-A41A-EA4293703D16") } }, new StructDivision() { Id = new Guid("DC195A4F-46F9-41B2-80D2-77FF9C6269B7"), Name = "Group 1.2", ParentId = new Guid("B14F5D81-5B0D-4ACC-92B8-27CBBE39086B"), Heads = new List <Guid>() }, new StructDivision() { Id = new Guid("C5DCC148-9C0C-45C4-8A68-901D99A26184"), Name = "Group 2.2", ParentId = new Guid("72D461B2-234B-40D6-B410-B261964BA291"), Heads = new List <Guid>() }, new StructDivision() { Id = new Guid("72D461B2-234B-40D6-B410-B261964BA291"), Name = "Group 2", ParentId = new Guid("F6E34BDF-B769-42DD-A2BE-FEE67FAF9045"), Heads = new List <Guid>() }, new StructDivision() { Id = new Guid("BC21A482-28E7-4951-8177-E57813A70FC5"), Name = "Group 2.1", ParentId = new Guid("72D461B2-234B-40D6-B410-B261964BA291"), Heads = new List <Guid>() }, new StructDivision() { Id = new Guid("F6E34BDF-B769-42DD-A2BE-FEE67FAF9045"), Name = "Head Group", Heads = new List <Guid>() { new Guid("81537E21-91C5-4811-A546-2DDDFF6BF409") } } }; batch.SetAddAsync(GetKeyForStructDivisionsSet(), sd.Select(x => (RedisValue)x.Id.ToString()).ToArray()); foreach (var s in sd) { batch.StringSetAsync(GetKeyForStructDivision(s.Id), JsonConvert.SerializeObject(s)); } var e1 = new Employee() { Id = new Guid("E41B48E3-C03D-484F-8764-1711248C4F8A"), Name = "Maria", StructDivisionId = new Guid("C5DCC148-9C0C-45C4-8A68-901D99A26184"), IsHead = false }; e1.Roles.Add(new Guid("412174C2-0490-4101-A7B3-830DE90BCAA0"), "Accountant"); e1.Roles.Add(new Guid("71FFFB5B-B707-4B3C-951C-C37FDFCC8DFB"), "User"); var e2 = new Employee() { Id = new Guid("BBE686F8-8736-48A7-A886-2DA25567F978"), Name = "Mark", StructDivisionId = new Guid("7E9FD972-C775-4C6B-9D91-47E9397BD2E6"), IsHead = false, }; e2.Roles.Add(new Guid("71FFFB5B-B707-4B3C-951C-C37FDFCC8DFB"), "User"); var e3 = new Employee() { Id = new Guid("81537E21-91C5-4811-A546-2DDDFF6BF409"), Name = "Silviya", StructDivisionId = new Guid("F6E34BDF-B769-42DD-A2BE-FEE67FAF9045"), IsHead = true, }; e3.Roles.Add(new Guid("8D378EBE-0666-46B3-B7AB-1A52480FD12A"), "Big Boss"); e3.Roles.Add(new Guid("71FFFB5B-B707-4B3C-951C-C37FDFCC8DFB"), "User"); var e4 = new Employee() { Id = new Guid("B0E6FD4C-2DB9-4BB6-A62E-68B6B8999905"), Name = "Margo", StructDivisionId = new Guid("DC195A4F-46F9-41B2-80D2-77FF9C6269B7"), IsHead = false, }; e4.Roles.Add(new Guid("71FFFB5B-B707-4B3C-951C-C37FDFCC8DFB"), "User"); var e5 = new Employee() { Id = new Guid("DEB579F9-991C-4DB9-A17D-BB1ECCF2842C"), Name = "Max", StructDivisionId = new Guid("B14F5D81-5B0D-4ACC-92B8-27CBBE39086B"), IsHead = true, }; e5.Roles.Add(new Guid("71FFFB5B-B707-4B3C-951C-C37FDFCC8DFB"), "User"); var e6 = new Employee() { Id = new Guid("91F2B471-4A96-4AB7-A41A-EA4293703D16"), Name = "John", StructDivisionId = new Guid("7E9FD972-C775-4C6B-9D91-47E9397BD2E6"), IsHead = true, }; e6.Roles.Add(new Guid("71FFFB5B-B707-4B3C-951C-C37FDFCC8DFB"), "User"); var employees = new List <Employee>() { e1, e2, e3, e4, e5, e6 }; foreach (var e in employees) { e.StructDivisionName = sd.Where(x => x.Id == e.StructDivisionId).Select(x => x.Name).FirstOrDefault(); } batch.SetAddAsync(GetKeyForEmployeesSet(), employees.Select(x => (RedisValue)x.Id.ToString()).ToArray()); foreach (var e in employees) { batch.StringSetAsync(GetKeyForEmployee(e.Id), JsonConvert.SerializeObject(e)); } Dictionary <string, RedisValue[]> employeesInRole = new Dictionary <string, RedisValue[]>() { ["Accountant"] = employees.Where(e => e.Roles.Values.Contains("Accountant")).Select(x => (RedisValue)x.Id.ToString()).ToArray(), ["User"] = employees.Where(e => e.Roles.Values.Contains("User")).Select(x => (RedisValue)x.Id.ToString()).ToArray(), ["Big Boss"] = employees.Where(e => e.Roles.Values.Contains("Big Boss")).Select(x => (RedisValue)x.Id.ToString()).ToArray(), }; foreach (var kvp in employeesInRole) { batch.SetAddAsync(GetKeyForEmployeesInRole(kvp.Key), kvp.Value); } #region Insert scheme _provider.SaveScheme("SimpleWF", @"<Process Name=""SimpleWF""> <Designer X=""-110"" Y=""-60"" /> <Actors> <Actor Name=""Author"" Rule=""IsDocumentAuthor"" Value="""" /> <Actor Name=""Manager"" Rule=""IsDocumentManager"" Value="""" /> <Actor Name=""BigBoss"" Rule=""CheckRole"" Value=""Big Boss"" /> <Actor Name=""Accountant"" Rule=""CheckRole"" Value=""Accountant"" /> </Actors> <Parameters> <Parameter Name=""Comment"" Type=""String"" Purpose=""Temporary"" /> </Parameters> <Commands> <Command Name=""StartSigning""> <InputParameters> <ParameterRef Name=""Comment"" IsRequired=""false"" DefaultValue="""" NameRef=""Comment"" /> </InputParameters> </Command> <Command Name=""Approve""> <InputParameters> <ParameterRef Name=""Comment"" IsRequired=""false"" DefaultValue="""" NameRef=""Comment"" /> </InputParameters> </Command> <Command Name=""Reject""> <InputParameters> <ParameterRef Name=""Comment"" IsRequired=""false"" DefaultValue="""" NameRef=""Comment"" /> </InputParameters> </Command> <Command Name=""Paid""> <InputParameters> <ParameterRef Name=""Comment"" IsRequired=""false"" DefaultValue="""" NameRef=""Comment"" /> </InputParameters> </Command> </Commands> <Timers> <Timer Name=""SendToBigBoss"" Type=""Interval"" Value=""10minutes"" NotOverrideIfExists=""false"" /> </Timers> <Activities> <Activity Name=""VacationRequestCreated"" State=""VacationRequestCreated"" IsInitial=""True"" IsFinal=""False"" IsForSetState=""True"" IsAutoSchemeUpdate=""True""> <Implementation> <ActionRef Order=""1"" NameRef=""UpdateTransitionHistory"" /> </Implementation> <PreExecutionImplementation> <ActionRef Order=""1"" NameRef=""WriteTransitionHistory"" /> </PreExecutionImplementation> <Designer X=""10"" Y=""170"" /> </Activity> <Activity Name=""ManagerSigning"" State=""ManagerSigning"" IsInitial=""False"" IsFinal=""False"" IsForSetState=""True"" IsAutoSchemeUpdate=""True""> <Implementation> <ActionRef Order=""1"" NameRef=""UpdateTransitionHistory"" /> </Implementation> <PreExecutionImplementation> <ActionRef Order=""1"" NameRef=""WriteTransitionHistory"" /> </PreExecutionImplementation> <Designer X=""320"" Y=""170"" /> </Activity> <Activity Name=""BigBossSigning"" State=""BigBossSigning"" IsInitial=""False"" IsFinal=""False"" IsForSetState=""True"" IsAutoSchemeUpdate=""True""> <Implementation> <ActionRef Order=""1"" NameRef=""UpdateTransitionHistory"" /> </Implementation> <PreExecutionImplementation> <ActionRef Order=""1"" NameRef=""WriteTransitionHistory"" /> </PreExecutionImplementation> <Designer X=""620"" Y=""170"" /> </Activity> <Activity Name=""AccountingReview "" State=""AccountingReview "" IsInitial=""False"" IsFinal=""False"" IsForSetState=""True"" IsAutoSchemeUpdate=""True""> <Implementation> <ActionRef Order=""1"" NameRef=""UpdateTransitionHistory"" /> </Implementation> <PreExecutionImplementation> <ActionRef Order=""1"" NameRef=""WriteTransitionHistory"" /> </PreExecutionImplementation> <Designer X=""620"" Y=""340"" /> </Activity> <Activity Name=""RequestApproved"" State=""RequestApproved"" IsInitial=""False"" IsFinal=""True"" IsForSetState=""True"" IsAutoSchemeUpdate=""True""> <Implementation> <ActionRef Order=""1"" NameRef=""UpdateTransitionHistory"" /> </Implementation> <PreExecutionImplementation> <ActionRef Order=""1"" NameRef=""WriteTransitionHistory"" /> </PreExecutionImplementation> <Designer X=""930"" Y=""340"" /> </Activity> </Activities> <Transitions> <Transition Name=""ManagerSigning_Draft_1"" To=""VacationRequestCreated"" From=""ManagerSigning"" Classifier=""Reverse"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Restrictions> <Restriction Type=""Allow"" NameRef=""Manager"" /> </Restrictions> <Triggers> <Trigger Type=""Command"" NameRef=""Reject"" /> </Triggers> <Conditions> <Condition Type=""Always"" /> </Conditions> <Designer X=""258"" Y=""177"" /> </Transition> <Transition Name=""BigBossSigning_Activity_1_1"" To=""AccountingReview "" From=""BigBossSigning"" Classifier=""Direct"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Restrictions> <Restriction Type=""Allow"" NameRef=""BigBoss"" /> </Restrictions> <Triggers> <Trigger Type=""Command"" NameRef=""Approve"" /> </Triggers> <Conditions> <Condition Type=""Always"" /> </Conditions> <Designer X=""716"" Y=""283"" /> </Transition> <Transition Name=""ManagerSigning_Approved_1"" To=""AccountingReview "" From=""ManagerSigning"" Classifier=""Direct"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Restrictions> <Restriction Type=""Allow"" NameRef=""Manager"" /> </Restrictions> <Triggers> <Trigger Type=""Command"" NameRef=""Approve"" /> </Triggers> <Conditions> <Condition Type=""Otherwise"" /> </Conditions> <Designer X=""492"" Y=""346"" /> </Transition> <Transition Name=""ManagerSigning_BigBossSigning_1"" To=""BigBossSigning"" From=""ManagerSigning"" Classifier=""Direct"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Restrictions> <Restriction Type=""Allow"" NameRef=""Manager"" /> </Restrictions> <Triggers> <Trigger Type=""Command"" NameRef=""Approve"" /> </Triggers> <Conditions> <Condition Type=""Action"" NameRef=""CheckBigBossMustSign"" ConditionInversion=""false"" /> </Conditions> <Designer X=""565"" Y=""226"" /> </Transition> <Transition Name=""Draft_ManagerSigning_1"" To=""ManagerSigning"" From=""VacationRequestCreated"" Classifier=""Direct"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Restrictions> <Restriction Type=""Allow"" NameRef=""Author"" /> </Restrictions> <Triggers> <Trigger Type=""Command"" NameRef=""StartSigning"" /> </Triggers> <Conditions> <Condition Type=""Always"" /> </Conditions> <Designer X=""257"" Y=""220"" /> </Transition> <Transition Name=""BigBossSigning_ManagerSigning_1"" To=""ManagerSigning"" From=""BigBossSigning"" Classifier=""Reverse"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Restrictions> <Restriction Type=""Allow"" NameRef=""BigBoss"" /> </Restrictions> <Triggers> <Trigger Type=""Command"" NameRef=""Reject"" /> </Triggers> <Conditions> <Condition Type=""Always"" /> </Conditions> <Designer X=""565"" Y=""179"" /> </Transition> <Transition Name=""ManagerSigning_BigBossSigning_2"" To=""BigBossSigning"" From=""ManagerSigning"" Classifier=""NotSpecified"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Triggers> <Trigger Type=""Timer"" NameRef=""SendToBigBoss"" /> </Triggers> <Conditions> <Condition Type=""Always"" /> </Conditions> <Designer X=""565"" Y=""131"" /> </Transition> <Transition Name=""Accountant_Activity_1_1"" To=""RequestApproved"" From=""AccountingReview "" Classifier=""Direct"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Restrictions> <Restriction Type=""Allow"" NameRef=""Accountant"" /> </Restrictions> <Triggers> <Trigger Type=""Command"" NameRef=""Paid"" /> </Triggers> <Conditions> <Condition Type=""Always"" /> </Conditions> <Designer X=""865"" Y=""370"" /> </Transition> <Transition Name=""Accountant_ManagerSigning_1"" To=""ManagerSigning"" From=""AccountingReview "" Classifier=""Reverse"" AllowConcatenationType=""And"" RestrictConcatenationType=""And"" ConditionsConcatenationType=""And"" IsFork=""false"" MergeViaSetState=""false"" DisableParentStateControl=""false""> <Restrictions> <Restriction Type=""Allow"" NameRef=""Accountant"" /> </Restrictions> <Triggers> <Trigger Type=""Command"" NameRef=""Reject"" /> </Triggers> <Conditions> <Condition Type=""Always"" /> </Conditions> <Designer X=""414"" Y=""391"" /> </Transition> </Transitions> <CodeActions> <CodeAction Name=""CheckBigBossMustSign"" Type=""Condition"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[var doc = WorkflowInit.DataServiceProvider.Get<IDocumentRepository>().Get(processInstance.ProcessId); if(doc == null) return false; return doc.Sum > 100;]]></ActionCode> <Usings><![CDATA[System;System.Collections;System.Collections.Generic;System.Linq;OptimaJet.Workflow;OptimaJet.Workflow.Core.Model;WF.Sample.Business;WF.Sample.Business.Workflow;WF.Sample.Business.DataAccess;]]></Usings> </CodeAction> <CodeAction Name=""WriteTransitionHistory"" Type=""Action"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[if (processInstance.IdentityIds == null) return; var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState); var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState); var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand); var repository = WorkflowInit.DataServiceProvider.Get<IDocumentRepository>(); repository.WriteTransitionHistory(processInstance.ProcessId, currentstate, nextState, command, processInstance.IdentityIds);]]></ActionCode> <Usings><![CDATA[System;System.Collections;System.Collections.Generic;System.Linq;OptimaJet.Workflow;OptimaJet.Workflow.Core.Model;WF.Sample.Business;WF.Sample.Business.Workflow;WF.Sample.Business.DataAccess;]]></Usings> </CodeAction> <CodeAction Name=""UpdateTransitionHistory"" Type=""Action"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[if (string.IsNullOrEmpty(processInstance.CurrentCommand)) return; var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState); var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState); var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand); if(!string.IsNullOrEmpty(processInstance.ExecutedTimer)) { command = string.Format(""Timer: {0}"",processInstance.ExecutedTimer); } Guid? employeeId = null; if (!string.IsNullOrWhiteSpace(processInstance.IdentityId)) employeeId = new Guid(processInstance.IdentityId); var repository = WorkflowInit.DataServiceProvider.Get<IDocumentRepository>(); repository.UpdateTransitionHistory(processInstance.ProcessId, currentstate, nextState, command, employeeId);]]></ActionCode> <Usings><![CDATA[System;System.Collections;System.Collections.Generic;System.Linq;OptimaJet.Workflow;OptimaJet.Workflow.Core.Model;WF.Sample.Business;WF.Sample.Business.Workflow;WF.Sample.Business.DataAccess;]]></Usings> </CodeAction> <CodeAction Name=""IsDocumentManager"" Type=""RuleCheck"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[var document = WorkflowInit.DataServiceProvider.Get<IDocumentRepository>().Get(processInstance.ProcessId); if (document == null) return false; return document.ManagerId.HasValue && document.ManagerId.Value == new Guid(identityId);]]></ActionCode> <Usings><![CDATA[System;System.Collections.Generic;System.Linq;OptimaJet.Workflow.Core.Runtime;OptimaJet.Workflow.Core.Model;WF.Sample.Business.DataAccess;WF.Sample.Business.Workflow;]]></Usings> </CodeAction> <CodeAction Name=""IsDocumentManager"" Type=""RuleGet"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[var document = WorkflowInit.DataServiceProvider.Get<IDocumentRepository>().Get(processInstance.ProcessId, false); if (document == null || !document.ManagerId.HasValue) return new List<string> { }; return new List<string> { document.ManagerId.Value.ToString() };]]></ActionCode> <Usings><![CDATA[System;System.Collections.Generic;System.Linq;OptimaJet.Workflow.Core.Runtime;OptimaJet.Workflow.Core.Model;WF.Sample.Business.DataAccess;WF.Sample.Business.Workflow;]]></Usings> </CodeAction> <CodeAction Name=""IsDocumentAuthor"" Type=""RuleCheck"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[var document = WorkflowInit.DataServiceProvider.Get<IDocumentRepository>().Get(processInstance.ProcessId); if (document == null) return false; return document.AuthorId == new Guid(identityId); ]]></ActionCode> <Usings><![CDATA[System;System.Collections.Generic;System.Linq;OptimaJet.Workflow.Core.Runtime;OptimaJet.Workflow.Core.Model;WF.Sample.Business.DataAccess;WF.Sample.Business.Workflow;]]></Usings> </CodeAction> <CodeAction Name=""IsDocumentAuthor"" Type=""RuleGet"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[var document = WorkflowInit.DataServiceProvider.Get<IDocumentRepository>().Get(processInstance.ProcessId); if (document == null) return new List<string> { }; return new List<string> { document.AuthorId.ToString() };]]></ActionCode> <Usings><![CDATA[System;System.Collections.Generic;System.Linq;OptimaJet.Workflow.Core.Runtime;OptimaJet.Workflow.Core.Model;WF.Sample.Business.DataAccess;WF.Sample.Business.Workflow;]]></Usings> </CodeAction> <CodeAction Name=""CheckRole"" Type=""RuleCheck"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[return WorkflowInit.DataServiceProvider.Get<IEmployeeRepository>().CheckRole(new Guid(identityId), parameter);]]></ActionCode> <Usings><![CDATA[System;System.Collections.Generic;System.Linq;OptimaJet.Workflow.Core.Runtime;OptimaJet.Workflow.Core.Model;WF.Sample.Business.DataAccess;WF.Sample.Business.Workflow;]]></Usings> </CodeAction> <CodeAction Name=""CheckRole"" Type=""RuleGet"" IsGlobal=""False"" IsAsync=""False""> <ActionCode><![CDATA[return WorkflowInit.DataServiceProvider.Get<IEmployeeRepository>().GetInRole(parameter);]]></ActionCode> <Usings><![CDATA[System;System.Collections.Generic;System.Linq;OptimaJet.Workflow.Core.Runtime;OptimaJet.Workflow.Core.Model;WF.Sample.Business.DataAccess;WF.Sample.Business.Workflow;]]></Usings> </CodeAction> </CodeActions> <Localization> <Localize Type=""State"" IsDefault=""True"" Culture=""en-US"" ObjectName=""ManagerSigning"" Value=""Manager signing"" /> <Localize Type=""State"" IsDefault=""True"" Culture=""en-US"" ObjectName=""BigBossSigning"" Value=""BigBoss signing"" /> <Localize Type=""Command"" IsDefault=""True"" Culture=""en-US"" ObjectName=""StartSigning"" Value=""Start signing"" /> <Localize Type=""State"" IsDefault=""True"" Culture=""en-US"" ObjectName=""AccountingReview "" Value=""Accounting review"" /> <Localize Type=""State"" IsDefault=""True"" Culture=""en-US"" ObjectName=""VacationRequestCreated"" Value=""Vacation request created"" /> <Localize Type=""State"" IsDefault=""True"" Culture=""en-US"" ObjectName=""RequestApproved"" Value=""Request approved"" /> </Localization> </Process>"); #endregion batch.Execute(); }