public bool Terminate(string ID) { lock (locker) { if (!Workers.ContainsKey(ID)) { return(false); } try { if (Workers[ID] != null) { Workers[ID].Enabled = false; Workers[ID].Stop(); bool isLocked = Workers[ID].IsBusy; } } catch (Exception ex) { ex.ToOutput(); } Workers[ID].Dispose(); Workers[ID] = null; Workers.Remove(ID); return(true); } }
public ThreadedTimer Timer(string ID) { lock (locker) { return(Workers.ContainsKey(ID) ? Workers[ID] : null); } }
private string RouteDecision(string worker, string route, string trigger, string state) { Debug.Assert(!string.IsNullOrWhiteSpace(worker)); Debug.Assert(!string.IsNullOrWhiteSpace(route)); route = RouteSubstitutions(route); if (Workers.ContainsKey(WorkerKey(worker, route))) { try { var nextState = Workers[WorkerKey(worker, route)].DecideTransition(Id, route, trigger, state); _dblog.DebugFormat("Workflow {0} routing decision on {1}/{2} for state {3}, trigger {4} returns {5}", Id, worker, route, state, trigger, nextState); return(nextState); } catch (Exception ex) { var es = string.Format("Exception while invoking decision {0}: {1},\n{2}", worker, route, ex); _log.Error(es); var on = Catalog.Factory.Resolve <IApplicationAlert>(); on.RaiseAlert(ApplicationAlertKind.System, es); } } else { var es = string.Format( "Cannot invoke decision on worker {0}, this worker doesn't exist in the workflow", worker); _log.Error(es); var on = Catalog.Factory.Resolve <IApplicationAlert>(); on.RaiseAlert(ApplicationAlertKind.System, es); } return(state); }
private bool RouteCondition(string worker, string route, string state, string trigger) { Debug.Assert(!string.IsNullOrWhiteSpace(worker)); Debug.Assert(!string.IsNullOrWhiteSpace(route)); route = RouteSubstitutions(route); if (Workers.ContainsKey(WorkerKey(worker, route))) { try { var check = Workers[WorkerKey(worker, route)].Guard(Id, route, state, trigger); _dblog.DebugFormat("Workflow {0} checking condition {0}/{1} on state {2}, trigger {3}, returns {4}", Id, worker, route, state, trigger, check); return(check); } catch (Exception ex) { var es = string.Format("Exception while invoking guard {0}: {1},\n{2}", worker, route, ex); _log.Error(es); var on = Catalog.Factory.Resolve <IApplicationAlert>(); on.RaiseAlert(ApplicationAlertKind.System, es); } } else { var es = string.Format("Cannot invoke condition on worker {0}, this worker doesn't exist in the workflow", worker); _log.Error(es); var on = Catalog.Factory.Resolve <IApplicationAlert>(); on.RaiseAlert(ApplicationAlertKind.System, es); } return(false); }
private void RouteAction(string worker, string route) { Debug.Assert(!string.IsNullOrWhiteSpace(worker)); Debug.Assert(!string.IsNullOrWhiteSpace(route)); route = RouteSubstitutions(route); _dblog.DebugFormat("workflow instance {0} taking action {1}/{2}", Id, worker, route); if (Workers.ContainsKey(WorkerKey(worker, route))) { try { Workers[WorkerKey(worker, route)].Invoke(Id, route); } catch (Exception ex) { var es = string.Format("Exception while invoking route {0}: {1},\n{2}", worker, route, ex); _log.Error(es); var on = Catalog.Factory.Resolve <IApplicationAlert>(); on.RaiseAlert(ApplicationAlertKind.System, es); } } else { var es = string.Format("Cannot invoke action on worker {0}, this worker doesn't exist in the workflow", worker); _log.Error(es); var on = Catalog.Factory.Resolve <IApplicationAlert>(); on.RaiseAlert(ApplicationAlertKind.System, es); } }
public bool Run(Expression <Action> EAMethod, int interval, string ID = null, bool waitForAccess = true, bool autostart = true) { if (EAMethod == null) { return(false); } if (MaxThreadsCount < Workers.Count) { if (!waitForAccess) { return(false); } while (MaxThreadsCount <= Workers.Count) { Thread.Sleep(1); } } if (ID.IsNullOrEmpty()) { ID = Expressions.nameofFull(EAMethod); } lock (locker) { ThreadedTimer TTimer = Workers.ContainsKey(ID) ? Workers[ID] : null; if (TTimer != null && TTimer.Enabled) { return(false); } TTimer = new ThreadedTimer(EAMethod, interval, autostart); Workers.Add(ID, TTimer, true); Workers[ID].Start(); } return(true); }
private void ValidateWork(string worker, string route) { string msg = null; if (!Workers.ContainsKey(WorkerKey(worker, route))) { msg = string.Format("Template uses worker {0} without loading a worker plugin for it", worker); } if (!Workers[WorkerKey(worker, route)].SupportsRoute(route)) { msg = string.Format("Template attempts route {0} on worker {1}, but it doesn't support it.", route, worker); } if (!string.IsNullOrEmpty(msg)) { _log.ErrorFormat(msg); throw new WorkflowTemplateException(msg); } }
public bool Contains(string ID) { return(Workers.ContainsKey(ID)); }