internal void SetupTimer(WorkflowTimerType timerType, TimeSpan interval) { if (!this.disposed) { if (!this._timers.ContainsKey(timerType)) { if (timerType != WorkflowTimerType.ElapsedTimer) { if (timerType == WorkflowTimerType.RunningTimer) { this._timers.Add(timerType, new PSTimer(timerType, false, false, interval, new WorkflowTimerElapsedHandler(this.Timer_WorkflowTimerElapsed))); } return; } else { this._timers.Add(timerType, new PSTimer(timerType, false, true, interval, new WorkflowTimerElapsedHandler(this.Timer_WorkflowTimerElapsed))); return; } } else { return; } } else { return; } }
internal void StopTimer(WorkflowTimerType timerType) { if (disposed) { return; } if (_timers.ContainsKey(timerType)) { _timers[timerType].Stop(); } }
internal PSTimer(WorkflowTimerType type, bool isRecurring, bool isOneTimeTimer, TimeSpan interval, WorkflowTimerElapsedHandler handler) { this.syncLock = new object(); this.TimerType = type; this.IsRecurring = isRecurring; this.IsOneTimeTimer = isOneTimeTimer; this.Interval = interval; this.RemainingTime = interval; this.StartedAtForFirstTime = null; this.StartedTime = null; this.IsRunning = false; this.Handler = handler; }
internal bool CheckIfTimerHasReachedAlready(WorkflowTimerType timerType) { if (disposed) { return(false); } if (_timers.ContainsKey(timerType) && _timers[WorkflowTimerType.ElapsedTimer].TimerReachedAlready) { return(true); } return(false); }
internal void StopTimer(WorkflowTimerType timerType) { if (!this.disposed) { if (this._timers.ContainsKey(timerType)) { this._timers[timerType].Stop(); } return; } else { return; } }
internal PSTimer(WorkflowTimerType type, bool isRecurring, bool isOneTimeTimer, TimeSpan interval, WorkflowTimerElapsedHandler handler) { Debug.Assert(!(isRecurring == true && isOneTimeTimer == true), "Timer cannot be recurring and one-time-timer at the same time."); this.TimerType = type; this.IsRecurring = isRecurring; this.IsOneTimeTimer = isOneTimeTimer; this.Interval = interval; this.RemainingTime = interval; this.StartedAtForFirstTime = null; this.StartedTime = null; this.IsRunning = false; this.Handler = handler; }
internal PSTimer(Dictionary <string, object> data, WorkflowTimerElapsedHandler handler) { this.syncLock = new object(); this.TimerType = (WorkflowTimerType)data["TimerType"]; this.IsRecurring = (bool)data["IsRecurring"]; this.IsOneTimeTimer = (bool)data["IsOneTimeTimer"]; this.Interval = (TimeSpan)data["Interval"]; if (this.IsRecurring || this.IsOneTimeTimer) { if (this.IsRecurring || !this.IsOneTimeTimer) { this.RemainingTime = this.Interval; } else { DateTime item = (DateTime)data["StartedAtForFirstTime"]; DateTime utcNow = DateTime.UtcNow; TimeSpan interval = this.Interval - utcNow.Subtract(item); if (interval > TimeSpan.FromSeconds(0)) { if (interval >= TimeSpan.FromSeconds(2)) { this.RemainingTime = interval; } else { this.RemainingTime = TimeSpan.FromSeconds(2); } } else { this.TimerReachedAlready = true; this.RemainingTime = TimeSpan.FromSeconds(2); } } } else { this.RemainingTime = (TimeSpan)data["RemainingTime"]; } this.StartedAtForFirstTime = null; this.StartedTime = null; this.IsRunning = false; this.Handler = handler; }
internal PSTimer(Dictionary<string, object> data, WorkflowTimerElapsedHandler handler) { this.syncLock = new object(); this.TimerType = (WorkflowTimerType)data["TimerType"]; this.IsRecurring = (bool)data["IsRecurring"]; this.IsOneTimeTimer = (bool)data["IsOneTimeTimer"]; this.Interval = (TimeSpan)data["Interval"]; if (this.IsRecurring || this.IsOneTimeTimer) { if (this.IsRecurring || !this.IsOneTimeTimer) { this.RemainingTime = this.Interval; } else { DateTime item = (DateTime)data["StartedAtForFirstTime"]; DateTime utcNow = DateTime.UtcNow; TimeSpan interval = this.Interval - utcNow.Subtract(item); if (interval > TimeSpan.FromSeconds(0)) { if (interval >= TimeSpan.FromSeconds(2)) { this.RemainingTime = interval; } else { this.RemainingTime = TimeSpan.FromSeconds(2); } } else { this.TimerReachedAlready = true; this.RemainingTime = TimeSpan.FromSeconds(2); } } } else { this.RemainingTime = (TimeSpan)data["RemainingTime"]; } this.StartedAtForFirstTime = null; this.StartedTime = null; this.IsRunning = false; this.Handler = handler; }
internal bool CheckIfTimerHasReachedAlready(WorkflowTimerType timerType) { if (!this.disposed) { if (!this._timers.ContainsKey(timerType) || !this._timers[WorkflowTimerType.ElapsedTimer].TimerReachedAlready) { return(false); } else { return(true); } } else { return(false); } }
internal bool CheckIfTimerHasReachedAlready(WorkflowTimerType timerType) { if (!this.disposed) { if (!this._timers.ContainsKey(timerType) || !this._timers[WorkflowTimerType.ElapsedTimer].TimerReachedAlready) { return false; } else { return true; } } else { return false; } }
private void Timer_WorkflowTimerElapsed(PSTimer sender, ElapsedEventArgs e) { if (!this.disposed) { PSWorkflowTimer.StructuredTracer.Correlate(); this.Tracer.WriteMessage(string.Concat("PSWorkflowTimer Elapsed: ", sender.TimerType)); if (!this.disposed) { WorkflowTimerType timerType = sender.TimerType; switch (timerType) { case WorkflowTimerType.RunningTimer: { sender.Stop(); this.TerminateWorkflow(Resources.RunningTimeReached); return; } case WorkflowTimerType.ElapsedTimer: { sender.Stop(); this.TerminateAndRemoveWorkflow(Resources.ElapsedTimeReached); return; } default: { return; } } } else { return; } } else { return; } }
internal void SetupTimer(WorkflowTimerType timerType, TimeSpan interval) { if (disposed) { return; } if (_timers.ContainsKey(timerType)) { return; } if (timerType == WorkflowTimerType.ElapsedTimer) { _timers.Add(timerType, new PSTimer(timerType, false, true, interval, Timer_WorkflowTimerElapsed)); } else if (timerType == WorkflowTimerType.RunningTimer) { _timers.Add(timerType, new PSTimer(timerType, false, false, interval, Timer_WorkflowTimerElapsed)); } }
internal PSTimer(Dictionary <string, object> data, WorkflowTimerElapsedHandler handler) { this.TimerType = (WorkflowTimerType)data["TimerType"]; this.IsRecurring = (bool)data["IsRecurring"]; this.IsOneTimeTimer = (bool)data["IsOneTimeTimer"]; this.Interval = (TimeSpan)data["Interval"]; if (IsRecurring == false && IsOneTimeTimer == false) { this.RemainingTime = (TimeSpan)data["RemainingTime"]; } else if (IsRecurring == false && IsOneTimeTimer == true) { DateTime tmpStartedAtForFirstTime = (DateTime)data["StartedAtForFirstTime"]; TimeSpan diff = Interval - DateTime.UtcNow.Subtract(tmpStartedAtForFirstTime); if (diff <= TimeSpan.FromSeconds(0)) { this.TimerReachedAlready = true; this.RemainingTime = TimeSpan.FromSeconds(2); } else if (diff < TimeSpan.FromSeconds(2)) { this.RemainingTime = TimeSpan.FromSeconds(2); } else { this.RemainingTime = diff; } } else { this.RemainingTime = Interval; } this.StartedAtForFirstTime = null; this.StartedTime = null; this.IsRunning = false; this.Handler = handler; }
internal PSTimer(Dictionary<string, object> data, WorkflowTimerElapsedHandler handler) { this.TimerType = (WorkflowTimerType)data["TimerType"]; this.IsRecurring = (bool)data["IsRecurring"]; this.IsOneTimeTimer = (bool)data["IsOneTimeTimer"]; this.Interval = (TimeSpan)data["Interval"]; if (IsRecurring == false && IsOneTimeTimer == false) { this.RemainingTime = (TimeSpan)data["RemainingTime"]; } else if (IsRecurring == false && IsOneTimeTimer == true) { DateTime tmpStartedAtForFirstTime = (DateTime)data["StartedAtForFirstTime"]; TimeSpan diff = Interval - DateTime.UtcNow.Subtract(tmpStartedAtForFirstTime); if (diff <= TimeSpan.FromSeconds(0)) { this.TimerReachedAlready = true; this.RemainingTime = TimeSpan.FromSeconds(2); } else if (diff < TimeSpan.FromSeconds(2)) this.RemainingTime = TimeSpan.FromSeconds(2); else this.RemainingTime = diff; } else { this.RemainingTime = Interval; } this.StartedAtForFirstTime = null; this.StartedTime = null; this.IsRunning = false; this.Handler = handler; }
internal void StopTimer(WorkflowTimerType timerType) { if (disposed) return; if (_timers.ContainsKey(timerType)) { _timers[timerType].Stop(); } }
internal bool CheckIfTimerHasReachedAlready(WorkflowTimerType timerType) { if (disposed) return false; if (_timers.ContainsKey(timerType) && _timers[WorkflowTimerType.ElapsedTimer].TimerReachedAlready) return true; return false; }
internal void SetupTimer(WorkflowTimerType timerType, TimeSpan interval) { if (disposed) return; if (_timers.ContainsKey(timerType)) return; if (timerType == WorkflowTimerType.ElapsedTimer) { _timers.Add(timerType, new PSTimer(timerType, false, true, interval, Timer_WorkflowTimerElapsed)); } else if (timerType == WorkflowTimerType.RunningTimer) { _timers.Add(timerType, new PSTimer(timerType, false, false, interval, Timer_WorkflowTimerElapsed)); } }