public void RegisterWorkflowTask(IWorkflowTask workflowTask) { var taskType = workflowTask.GetType(); var taskName = taskType.Name; SupportedTaskTypes.Add(taskName, taskType); }
public void InitializeFromJson(object definition) { Definition = (IDictionary <string, dynamic>)definition; VarName = Definition["var"]; InExpression = Definition["in"]; LoopTask = WorkSharp.CreateFromJSON(Definition["task"]); }
protected bool CanTransition(IWorkflowTask t) { if (!typeof(IDecisionWorkflowTask).IsAssignableFrom(t.GetType())) { return(false); } return(((IDecisionWorkflowTask)t).CanTransition()); }
public void UpdateTask(IWorkflowTask task) { var index = Tasks.FindIndex(t => t.Id == task.Id); if (index > -1) { Tasks[index] = task; } }
protected bool CanTransition(IWorkflowTask t, int instantiator) { if (!(t is IDecisionWorkflowTask)) { return(false); } return(((IDecisionWorkflowTask)t).CanTransition(instantiator)); }
public IUiWorkflowTask Create(IWorkflowTask task, IUiPoint point) { var t = task.GetType(); var entityUi = (IWorkflowTaskEntityUi)WorkflowEntityUiResolver.Instance.Resolve(task); var cssClass = entityUi.UiAttributes.ContainsKey("class") ? entityUi.UiAttributes["class"] : string.Empty; var w = new UiWorkflowTask { Top = point.Top, Left = point.Left, Description = task.Description, AvailableTransitions = task.AvailableTransitions, Id = task.Id, Name = task.Name, Transitions = task.Transitions, TypeName = t.FullName, AssemblyQualifiedTypeName = t.AssemblyQualifiedName, Class = cssClass, IsStartTask = task.IsStartTask, TransitionDescriptions = new Dictionary <string, string>(), CustomProperties = new Dictionary <string, object>() }; foreach (var transition in task.AvailableTransitions) { w.TransitionDescriptions.Add(transition, entityUi.TransitionDescriptions[transition]); } foreach (var p in t.GetProperties()) { if (p.Name == "Name" || p.Name == "Description" || p.Name == "IsStartTask") { continue; } if ( p.PropertyType != typeof(string) && p.PropertyType != typeof(int) && p.PropertyType != typeof(Boolean) && p.PropertyType != typeof(IList <string>) && p.PropertyType != typeof(IList <int>) ) { continue; } w.CustomProperties.Add(p.Name, p.GetValue(task, null)); } return(w); }
public IUiWorkflowTask Create(IWorkflowTask task, IUiPoint point) { var t = task.GetType(); var entityUi = (IWorkflowTaskEntityUi)WorkflowEntityUiResolver.Instance.Resolve(task); var cssClass = entityUi.UiAttributes.ContainsKey("class") ? entityUi.UiAttributes["class"] : string.Empty; var w = new UiWorkflowTask { Top = point.Top, Left = point.Left, Description = task.Description, AvailableTransitions = task.AvailableTransitions, Id = task.Id, Name = task.Name, Transitions = task.Transitions, TypeName = t.FullName, AssemblyQualifiedTypeName = t.AssemblyQualifiedName, Class = cssClass, IsStartTask = task.IsStartTask, TransitionDescriptions = new Dictionary<string, string>(), CustomProperties = new Dictionary<string, object>() }; foreach (var transition in task.AvailableTransitions) { w.TransitionDescriptions.Add(transition, entityUi.TransitionDescriptions[transition]); } foreach(var p in t.GetProperties()) { if (p.Name == "Name" || p.Name == "Description" || p.Name == "IsStartTask") continue; if ( p.PropertyType != typeof(string) && p.PropertyType != typeof(int) && p.PropertyType != typeof(Boolean) && p.PropertyType != typeof(IList<string>) && p.PropertyType != typeof(IList<int>) ) continue; w.CustomProperties.Add(p.Name, p.GetValue(task, null)); } return w; }
private async Task ProcessTask(Swagger.Api.Task task, IWorkflowTask workflowTask) { _logger.LogInformation(GetWorkerName() + $"Processing task:{task.TaskDefName} id:{task.TaskId}"); //TODO: we need to think about this try-catch try { await AckTask(task); var result = await workflowTask.Execute(task); result.WorkerId = _workerId; await UpdateTask(result); } catch (Exception e) { _logger.LogError(e, GetWorkerName() + "Failed to execute task"); await UpdateTask(task.FailedWithTerminalError(e.ToString())); } }
public IWorkflowTaskUiAdapter CreateWorkflowTaskUiAdapter(IWorkflowTask adaptedTask) { var t = adaptedTask.GetType(); Log.Debug(string.Format("Getting adapater for {0}", t.AssemblyQualifiedName)); var w = new WorkflowTaskUiAdapter { AvailableTransitions = adaptedTask.AvailableTransitions.Count, TypeName = t.FullName, AssemblyQualifiedTypeName = t.AssemblyQualifiedName, IsStartTask = adaptedTask.IsStartTask }; Log.Debug("Finding WorkflowTaskEntityUi"); var entityUi = (IWorkflowTaskEntityUi)WorkflowEntityUiResolver.Instance.Resolve(adaptedTask); if (entityUi == null) { var message = string.Format("No IWorkflowTaskEntityUi defined for {0}", t.AssemblyQualifiedName); Log.Fatal(message); throw new Exception(message); } Log.Debug(string.Format("Got entity Ui {0} for {1}", entityUi.GetType().AssemblyQualifiedName, t.AssemblyQualifiedName)); w.Name = entityUi.EntityName; w.Class = entityUi.UiAttributes.ContainsKey("class") ? entityUi.UiAttributes["class"] : string.Empty; w.TransitionDescriptions = new Dictionary<string, string>(); foreach (var transition in adaptedTask.AvailableTransitions) { w.TransitionDescriptions.Add(transition, entityUi.TransitionDescriptions[transition]); } return w; }
public IWorkflowTaskUiAdapter CreateWorkflowTaskUiAdapter(IWorkflowTask adaptedTask) { var t = adaptedTask.GetType(); Log.Debug(string.Format("Getting adapater for {0}", t.AssemblyQualifiedName)); var w = new WorkflowTaskUiAdapter { AvailableTransitions = adaptedTask.AvailableTransitions.Count, TypeName = t.FullName, AssemblyQualifiedTypeName = t.AssemblyQualifiedName, IsStartTask = adaptedTask.IsStartTask }; Log.Debug("Finding WorkflowTaskEntityUi"); var entityUi = (IWorkflowTaskEntityUi)WorkflowEntityUiResolver.Instance.Resolve(adaptedTask); if (entityUi == null) { var message = string.Format("No IWorkflowTaskEntityUi defined for {0}", t.AssemblyQualifiedName); Log.Fatal(message); throw new Exception(message); } Log.Debug(string.Format("Got entity Ui {0} for {1}", entityUi.GetType().AssemblyQualifiedName, t.AssemblyQualifiedName)); w.Name = entityUi.EntityName; w.Class = entityUi.UiAttributes.ContainsKey("class") ? entityUi.UiAttributes["class"] : string.Empty; w.TransitionDescriptions = new Dictionary <string, string>(); foreach (var transition in adaptedTask.AvailableTransitions) { w.TransitionDescriptions.Add(transition, entityUi.TransitionDescriptions[transition]); } return(w); }
public void Transition(IWorkflowInstance workflowInstance, IWorkflowTask workflowTask, string transitionName, string comment) { if (workflowTask.Transitions.Values.Count == 0) { Log.Warn(string.Format("Ending workflow '{0}' as it has no transitions.", workflowInstance.Id)); EndWorkflow(workflowInstance); TheWorkflowInstanceRepository.Update(workflowInstance); return; } if (!workflowTask.Transitions.ContainsKey(transitionName)) { LogAndThrow(new WorkflowTaskInvalidTransitionException(string.Format("Inavlid transition '{0}' for task '{1}'", transitionName, workflowTask.Name))); } var transitionGuid = workflowTask.Transitions[transitionName]; var transitionTask = workflowInstance.Tasks.SingleOrDefault(task => task.Id == transitionGuid); if (transitionTask == null) { LogAndThrow(new WorkflowTaskInvalidTransitionException(string.Format("Can't transition to task '{0}' in workflow '{1}' as it is not found", transitionGuid.ToString(), workflowInstance.Id))); } Log.Info(string.Format("Transitioning workflow '{0}' - '{1}' from '{2}' to '{3}' using transition '{4}'", workflowInstance.Name, workflowInstance.Id, workflowInstance.CurrentTask.Name, transitionTask.Name, transitionName)); workflowInstance.TransitionHistory.Add(string.Format("{0} - Transition '{1}' - '{2}' -> '{3}' {4}", DateTime.Now, transitionName, workflowInstance.CurrentTask.Name, transitionTask.Name, comment)); workflowInstance.CurrentTask = transitionTask; if (workflowInstance.CurrentTask is IDelayWorkflowTask) { ((IDelayWorkflowTask)workflowInstance.CurrentTask).StartTime = DateTime.Now; } TheWorkflowInstanceRepository.Update(workflowInstance); }
public void Transition(IWorkflowInstance workflowInstance, IWorkflowTask workflowTask, string transitionName) { Transition(workflowInstance, workflowTask, transitionName, ""); }
public void Transition(IWorkflowInstance workflowInstance, IWorkflowTask workflowTask, string transitionName) { Log.Info(string.Format("The workflow runtime is transitioning {0} - {1} '{2}' - '{3}'", workflowTask.Name, transitionName, workflowInstance.Id, workflowInstance.Name)); Transition(workflowInstance, workflowTask, transitionName, ""); }
public void AddTask(IWorkflowTask task) { Tasks.Add(task); }
public void Transition(IWorkflowInstance workflowInstance, IWorkflowTask workflowTask, string transitionName, string comment) { if (workflowTask.Transitions.Values.Count == 0) { Log.Warn(string.Format("Ending workflow '{0}' as it has no transitions.", workflowInstance.Id)); EndWorkflow(workflowInstance); TheWorkflowInstanceRepository.Update(workflowInstance); return; } if(!workflowTask.Transitions.ContainsKey(transitionName)) { LogAndThrow(new WorkflowTaskInvalidTransitionException(string.Format("Inavlid transition '{0}' for task '{1}'", transitionName, workflowTask.Name))); } var transitionGuid = workflowTask.Transitions[transitionName]; var transitionTask = workflowInstance.Tasks.SingleOrDefault(task => task.Id == transitionGuid); if(transitionTask == null) { LogAndThrow(new WorkflowTaskInvalidTransitionException(string.Format("Can't transition to task '{0}' in workflow '{1}' as it is not found", transitionGuid.ToString(), workflowInstance.Id))); } Log.Info(string.Format("Transitioning workflow '{0}' - '{1}' from '{2}' to '{3}' using transition '{4}'", workflowInstance.Name, workflowInstance.Id, workflowInstance.CurrentTask.Name, transitionTask.Name, transitionName)); workflowInstance.TransitionHistory.Add(string.Format("{0} - Transition '{1}' - '{2}' -> '{3}' {4}", DateTime.Now, transitionName, workflowInstance.CurrentTask.Name, transitionTask.Name, comment)); workflowInstance.CurrentTask = transitionTask; if (workflowInstance.CurrentTask is IDelayWorkflowTask) { ((IDelayWorkflowTask)workflowInstance.CurrentTask).StartTime = DateTime.Now; } TheWorkflowInstanceRepository.Update(workflowInstance); }
protected bool CanTransition(IWorkflowTask t, int instantiator) { if (!(t is IDecisionWorkflowTask)) return false; return ((IDecisionWorkflowTask) t).CanTransition(instantiator); }
public void UpdateTask(IWorkflowTask task) { var index = Tasks.FindIndex(t => t.Id == task.Id); if (index > -1) Tasks[index] = task; }