private IEnumerable<string> GetInRole(ProcessInstance processInstance, string parameter) { using (var session = Workflow.WorkflowInit.Provider.Store.OpenSession()) { return EmployeeHelper.EmployeeCache.Where(c => c.Roles.Any(r => r.Value == parameter)).Select(c => c.Id.ToString("N")).ToList(); } }
private IEnumerable<string> GetAuthorsBoss(ProcessInstance processInstance, string parameter) { var res = new List<string>(); var dbcoll = Workflow.WorkflowInit.Provider.Store.GetCollection<Document>("Document"); var document = dbcoll.FindOneById(processInstance.ProcessId); if (document == null) return res; var sds = StructDivisionHelper.StructDivisionCache; var emps = EmployeeHelper.EmployeeCache; var author = emps.FirstOrDefault(c => c.Id == document.AuthorId); if (author == null) return res; var currentSD = sds.FirstOrDefault(c => c.Id == author.StructDivisionId); while (currentSD != null) { var headEmpIds = emps.Where(c => c.IsHead && c.StructDivisionId == currentSD.Id).Select(c => c.Id.ToString("N")).ToArray(); res.AddRange(headEmpIds); if (currentSD.ParentId != null) currentSD = sds.FirstOrDefault(c => c.Id == currentSD.ParentId); else currentSD = null; } return res.Distinct(); }
public static bool CheckBigBossMustSight(ProcessInstance processInstance, string parameter) { using (var context = new DataModelDataContext()) { return context.Documents.Count(d => d.Id == processInstance.ProcessId && d.Sum > 100) > 0; } }
public static void WriteTransitionHistory(ProcessInstance processInstance, string parameter) { 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 dbcoll = Workflow.WorkflowInit.Provider.Store.GetCollection("Document"); var doc = dbcoll.FindOneByIdAs<Document>(processInstance.ProcessId); if (doc != null) { doc.TransitionHistories.Add(new DocumentTransitionHistory() { Id = Guid.NewGuid(), AllowedToEmployeeNames = GetEmployeesString(processInstance.IdentityIds), DestinationState = nextState, InitialState = currentstate, Command = command }); dbcoll.Save<Document>(doc); } }
public static bool CheckDocumentsAuthorIsBoss(ProcessInstance processInstance, string parameter) { using (var context = new DataModelDataContext()) { return context.Documents.Count(d => d.Id == processInstance.ProcessId && d.Employee1.IsHead) > 0; } }
public static bool CheckDocumentHasController(ProcessInstance processInstance, string parameter) { using (var context = new DataModelDataContext()) { return context.Documents.Count(d => d.Id == processInstance.ProcessId && d.EmloyeeControlerId.HasValue) > 0; } }
public static void WriteTransitionHistory(ProcessInstance processInstance, string parameter) { 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); using (var context = new DataModelDataContext()) { GetEmployeesString(processInstance.IdentityIds, context); var historyItem = new DocumentTransitionHistory { Id = Guid.NewGuid(), AllowedToEmployeeNames = GetEmployeesString(processInstance.IdentityIds, context), DestinationState = nextState, DocumentId = processInstance.ProcessId, InitialState = currentstate, Command = command }; context.DocumentTransitionHistories.InsertOnSubmit(historyItem); context.SubmitChanges(); } }
public static void WriteTransitionHistory(ProcessInstance processInstance, string parameter) { 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); using (var session = Workflow.WorkflowInit.Provider.Store.OpenSession()) { var doc = session.Load<Document>(processInstance.ProcessId); doc.TransitionHistories.Add(new DocumentTransitionHistory() { Id = Guid.NewGuid(), AllowedToEmployeeNames = GetEmployeesString(processInstance.IdentityIds), DestinationState = nextState, InitialState = currentstate, Command = command }); session.SaveChanges(); } }
private bool CheckRole(ProcessInstance processInstance, string identityId, string parameter) { using (var session = Workflow.WorkflowInit.Provider.Store.OpenSession()) { var emp = EmployeeHelper.EmployeeCache.Where(c=>c.Id == new Guid(identityId)).FirstOrDefault(); return emp.Roles.Any(c => c.Value == parameter); } }
private bool CheckRole(ProcessInstance processInstance, string identityId, string parameter) { using (var context = new DataModelDataContext()) { return context.EmployeeRoles.Any( r => r.EmloyeeId == new Guid(identityId) && r.Role.Name == parameter); } }
public bool ExecuteCondition(string name, ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter) { if (_conditions.ContainsKey(name)) { return _conditions[name].Invoke(processInstance, actionParameter); } throw new NotImplementedException(string.Format("Action condition with name {0} not implemented", name)); }
private IEnumerable<string> GetInRole(ProcessInstance processInstance, string parameter) { using (var context = new DataModelDataContext()) { return context.EmployeeRoles.Where(r => r.Role.Name == parameter).ToList() .Select(r => r.EmloyeeId.ToString("N")).ToList(); } }
public static bool CheckBigBossMustSight(ProcessInstance processInstance, string parameter) { var conditionResult = false; var dbcoll = Workflow.WorkflowInit.Provider.Store.GetCollection("Document"); var doc = dbcoll.FindOneByIdAs<Document>(processInstance.ProcessId); if (doc != null) conditionResult = doc.Sum > 100; return conditionResult; }
public static bool CheckDocumentHasController(ProcessInstance processInstance, string parameter) { var conditionResult = false; var dbcoll = Workflow.WorkflowInit.Provider.Store.GetCollection("Document"); var doc = dbcoll.FindOneByIdAs<Document>(processInstance.ProcessId); if (doc != null) conditionResult = doc.EmloyeeControlerId.HasValue; return conditionResult; }
private bool IsAuthorsBoss(ProcessInstance processInstance, string identityId, string parameter) { using (var context = new DataModelDataContext()) { var document = context.Documents.FirstOrDefault(d => d.Id == processInstance.ProcessId); if (document == null) return false; return context.vHeads.Count(h => h.Id == document.AuthorId && h.HeadId == new Guid(identityId)) > 0; } }
private void ClearTimers(ProcessInstance processInstance, List<string> usedTransitions) { List<string> list = processInstance.ProcessScheme.GetTimerTransitionForActivity(processInstance.CurrentActivity, ForkTransitionSearchType.Both).Where<TransitionDefinition>((TransitionDefinition t) => { if (t.Trigger.Timer == null || usedTransitions.Contains(t.Name)) { return false; } return t.Trigger.Timer.NotOverrideIfExists; }).Select<TransitionDefinition, string>((TransitionDefinition t) => t.Trigger.Timer.Name).ToList<string>(); this._runtime.PersistenceProvider.ClearTimers(processInstance.ProcessId, list); }
public static bool CheckDocumentHasController(ProcessInstance processInstance, string parameter) { var conditionResult = false; using (var session = Workflow.WorkflowInit.Provider.Store.OpenSession()) { var doc = session.Load<Document>(processInstance.ProcessId); if (doc != null) conditionResult = doc.EmloyeeControlerId.HasValue; } return conditionResult; }
public static bool CheckBigBossMustSight(ProcessInstance processInstance, string parameter) { var conditionResult = false; using (var session = Workflow.WorkflowInit.Provider.Store.OpenSession()) { var doc = session.Load<Document>(processInstance.ProcessId); if (doc != null) conditionResult = doc.Sum > 100; else conditionResult = false; } return conditionResult; }
public static void UpdateTransitionHistory(ProcessInstance processInstance, string parameter) { 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 isTimer = !string.IsNullOrEmpty(processInstance.ExecutedTimer); using (var session = Workflow.WorkflowInit.Provider.Store.OpenSession()) { var document = session.Load<Document>(processInstance.ProcessId); if (document == null) return; var historyItem = document.TransitionHistories.FirstOrDefault( h => !h.TransitionTime.HasValue && h.InitialState == currentstate && h.DestinationState == nextState); if (historyItem == null) { historyItem = new DocumentTransitionHistory { Id = Guid.NewGuid(), AllowedToEmployeeNames = string.Empty, DestinationState = nextState, InitialState = currentstate }; document.TransitionHistories.Add(historyItem); } historyItem.Command = !isTimer ? command : string.Format("Timer: {0}", processInstance.ExecutedTimer); historyItem.TransitionTime = DateTime.Now; if (string.IsNullOrWhiteSpace(processInstance.IdentityId)) { historyItem.EmployeeId = null; historyItem.EmployeeName = string.Empty; } else { historyItem.EmployeeId = new Guid(processInstance.IdentityId); historyItem.EmployeeName = EmployeeHelper.EmployeeCache.First(c => c.Id == historyItem.EmployeeId).Name; } session.SaveChanges(); } }
public static bool CheckDocumentsAuthorIsBoss(ProcessInstance processInstance, string parameter) { var conditionResult = false; var dbcoll = Workflow.WorkflowInit.Provider.Store.GetCollection("Document"); var doc = dbcoll.FindOneByIdAs<Document>(processInstance.ProcessId); if (doc != null) { var dbcollEmployee = Workflow.WorkflowInit.Provider.Store.GetCollection("Employee"); var emp = dbcollEmployee.FindOneByIdAs<Employee>(doc.AuthorId); if (emp != null) conditionResult = emp.IsHead; } return conditionResult; }
/// <summary> /// Register all timers for all outgouing timer transitions for current actvity of the specified process. /// All timers registered before which are present in transitions will be rewrited except timers marked as NotOverrideIfExists <see cref="TimerDefinition"/> /// </summary> /// <param name="processInstance">Process instance whose timers need to be registered</param> public void RegisterTimers(ProcessInstance processInstance) { var timersToRegister = processInstance.ProcessScheme.GetTimerTransitionForActivity(processInstance.CurrentActivity) .Where(t => t.Trigger.Timer != null).Select(t=>t.Trigger.Timer).ToList(); if (!timersToRegister.Any()) return; if (!_stopped) RefreshInterval(processInstance, timersToRegister); else { RegisterTimers(processInstance, timersToRegister); } }
private IEnumerable<string> GetAuthorsBoss(ProcessInstance processInstance, string parameter) { using (var context = new DataModelDataContext()) { var document = context.Documents.FirstOrDefault(d => d.Id == processInstance.ProcessId); if (document == null) return new List<string> {}; return context.vHeads.Where(h => h.Id == document.AuthorId) .Select(h => h.HeadId) .ToList() .Select(c => c.ToString("N")); } }
private void RefreshInterval(ProcessInstance processInstance, List<TimerDefinition> timersToRegister) { _lock.EnterUpgradeableReadLock(); try { _timer.Change(Timeout.Infinite, Timeout.Infinite); RegisterTimers(processInstance, timersToRegister); RefreshInterval(); } finally { _lock.ExitUpgradeableReadLock(); } }
public static bool CheckDocumentsAuthorIsBoss(ProcessInstance processInstance, string parameter) { var conditionResult = false; using (var session = Workflow.WorkflowInit.Provider.Store.OpenSession()) { var doc = session.Load<Document>(processInstance.ProcessId); if (doc != null) { var emp = session.Load<Employee>(doc.AuthorId); if (emp != null) conditionResult = emp.IsHead; } } return conditionResult; }
public static void UpdateTransitionHistory(ProcessInstance processInstance, string parameter) { 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 isTimer = !string.IsNullOrEmpty(processInstance.ExecutedTimer); using (var context = new DataModelDataContext()) { var historyItem = context.DocumentTransitionHistories.FirstOrDefault( h => h.DocumentId == processInstance.ProcessId && !h.TransitionTime.HasValue && h.InitialState == currentstate && h.DestinationState == nextState); if (historyItem == null) { historyItem = new DocumentTransitionHistory { Id = Guid.NewGuid(), AllowedToEmployeeNames = string.Empty, DestinationState = nextState, DocumentId = processInstance.ProcessId, InitialState = currentstate }; context.DocumentTransitionHistories.InsertOnSubmit(historyItem); } historyItem.Command = !isTimer ? command : string.Format("Timer: {0}",processInstance.ExecutedTimer); historyItem.TransitionTime = DateTime.Now; if (string.IsNullOrWhiteSpace(processInstance.IdentityId)) historyItem.EmployeeId = null; else historyItem.EmployeeId = new Guid(processInstance.IdentityId); context.SubmitChanges(); } }
public void BindProcessToNewScheme(ProcessInstance processInstance, bool resetIsDeterminingParametersChanged) { using (TransactionScope readCommittedSupressedScope = PredefinedTransactionScopes.ReadCommittedSupressedScope) { using (WorkflowPersistenceModelDataContext workflowPersistenceModelDataContext = base.CreateContext()) { WorkflowProcessInstance workflowProcessInstance = workflowPersistenceModelDataContext.WorkflowProcessInstances.SingleOrDefault((WorkflowProcessInstance wpi) => wpi.Id == processInstance.ProcessId); if (workflowProcessInstance == null) { throw new ProcessNotFoundException(); } workflowProcessInstance.SchemeId = new Guid?(processInstance.SchemeId); if (resetIsDeterminingParametersChanged) { workflowProcessInstance.IsDeterminingParametersChanged = false; } workflowPersistenceModelDataContext.SubmitChanges(); } readCommittedSupressedScope.Complete(); } }
private IEnumerable<string> GetDocumentController(ProcessInstance processInstance, string parameter) { using (var context = new DataModelDataContext()) { var document = context.Documents.FirstOrDefault(d => d.Id == processInstance.ProcessId); if (document == null || !document.EmloyeeControlerId.HasValue) return new List<string> {}; return new List<string> {document.EmloyeeControlerId.Value.ToString("N")}; } }
public IEnumerable<string> GetIdentities(ProcessInstance processInstance, string ruleName, string parameter) { return !_funcs.ContainsKey(ruleName) ? new List<string> {} : _funcs[ruleName].GetFunction.Invoke(processInstance, parameter); }
public bool Check(ProcessInstance processInstance, string identityId, string ruleName, string parameter) { return _funcs.ContainsKey(ruleName) && _funcs[ruleName].CheckFunction.Invoke(processInstance, identityId, parameter); }
private bool IsDocumentAuthor(ProcessInstance processInstance, string identityId, string parameter) { using (var context = new DataModelDataContext()) { var document = context.Documents.FirstOrDefault(d => d.Id == processInstance.ProcessId); if (document == null) return false; return document.AuthorId == new Guid(identityId); } }