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 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 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; }