private void ExecuteAction(Shows.Action action) { LogScheduleInfoEntry(string.Format("ExecuteAction: {0} with state of {1}", action.ShowItem.Name, State)); if (State != StateType.Waiting) { if (!action.PreProcessingCompleted) { ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Pre-processing action: " + action.ShowItem.Name); // Do this in a task so we don't stop Vixen while pre-processing! tokenSourcePreProcess = new CancellationTokenSource(); Task preProcessTask = new Task(() => action.PreProcess(), tokenSourcePreProcess.Token); preProcessTask.ContinueWith(task => { ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Starting action: " + action.ShowItem.Name); action.Execute(); RunningActions.Add(action); } ); preProcessTask.Start(); } else { ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Starting action: " + action.ShowItem.Name); action.Execute(); RunningActions.Add(action); } } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { isDisposing = true; // TODO: dispose managed state (managed objects). _actionStartSignal.Set(); _actionStartSignal.Close(); CallbackBufferBlock.Stop(); TimeoutManager.Stop(); ActionCaseConsumer.Stop(); RunningActions.ForEach(action => { action.Token.SetCancelled(); action.Token.SetCompletedSignal(); return(false); }); } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
public void Stop(bool graceful) { if (tokenSourcePreProcess != null && tokenSourcePreProcess.Token.CanBeCanceled) { tokenSourcePreProcess.Cancel(false); } if (tokenSourcePreProcessAll != null && tokenSourcePreProcessAll.Token.CanBeCanceled) { tokenSourcePreProcessAll.Cancel(false); } if (graceful) { State = StateType.Shutdown; ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Show stopping gracefully"); } else { State = StateType.Waiting; int runningCount = RunningActions.Count(); ItemQueue.Clear(); for (int i = 0; i < runningCount; i++) { ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Stopping action: " + RunningActions[i].ShowItem.Name); RunningActions[i].Stop(); } Show.ReleaseAllActions(); ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Show stopped immediately"); } }
public void OnShutdownActionComplete(object sender, EventArgs e) { Shows.Action action = (sender as Shows.Action); action.ActionComplete -= OnShutdownActionComplete; RunningActions.Remove(action); ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Shutdown action complete: " + action.ShowItem.Name); ExecuteNextShutdownItem(); }
public void OnHandleToken(ActionToken actionToken) { RunningActions.ForEach(action => { if (action.Token == actionToken) { ActionCaseConsumer.Add(action); } return(false); }); }
public void OnSequentialActionComplete(object sender, EventArgs e) { Shows.Action action = (sender as Shows.Action); action.ActionComplete -= OnSequentialActionComplete; RunningActions.Remove(action); ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Sequential action complete: " + action.ShowItem.Name); if (!StartShutdownIfRequested()) { LogScheduleInfoEntry("OnSequentialActionComplete: Shutdown was NOT requested"); ExecuteNextSequentialItem(); } }
public void TokenExpired(ActionToken actionToken) { RunningActions.ForEach(action => { if (action.Token == actionToken) { action.Token.SetExpiring(); ActionCaseConsumer.Add(action); } return(false); }); }
public void Cancel(Type actionType) { RunningActions.ForEach(type => { if (type.GetType() == actionType) { type.Token.SetCancelling(); ActionCaseConsumer.Add(type); } return(false); }); }
public void OnBackgroundActionComplete(object sender, EventArgs e) { Shows.Action action = (sender as Shows.Action); action.ActionComplete -= OnBackgroundActionComplete; RunningActions.Remove(action); ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Background action complete: " + action.ShowItem.Name); // Run it again and again and again and again and again and again and again and... if (!CheckForShutdown()) { ExecuteBackgroundAction(action); } }
public void OnStartupActionComplete(object sender, EventArgs e) { var action = (sender as Shows.Action); if (action != null) { action.ActionComplete -= OnStartupActionComplete; RunningActions.Remove(action); ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Startup action complete: " + action.ShowItem.Name); action.Dispose(); } ExecuteNextStartupItem(); }
public void Cancel(ActionToken actionToken) { if (actionToken != null && !actionToken.IsStateFinished) { RunningActions.ForEach(action => { if (action.Token == actionToken) { action.Token.SetCancelling(); ActionCaseConsumer.Add(action); } return(false); }); } }
public void Stop(bool graceful) { if (tokenSourcePreProcess != null && tokenSourcePreProcess.Token.CanBeCanceled) { tokenSourcePreProcess.Cancel(false); } if (tokenSourcePreProcessAll != null && tokenSourcePreProcessAll.Token.CanBeCanceled) { tokenSourcePreProcessAll.Cancel(false); } if (graceful) { State = StateType.Shutdown; ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Show stopping gracefully"); } else { State = StateType.Waiting; ItemQueue.Clear(); Action[] actions; lock (_actionLock) { actions = RunningActions.ToArray(); } foreach (var action in actions) { ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Stopping action: " + action.ShowItem.Name); action.Stop(); } if (Show != null) { Show.ReleaseAllActions(); ScheduleExecutor.AddSchedulerLogEntry(Show.Name, "Show stopped immediately"); } else { ScheduleExecutor.AddSchedulerLogEntry("No show selected", "Nothing to stop."); } } }
private void TryHandleDataFrame(CustomDataFrame actionCase, List <ActionHandlerResult> ahResults) { lock (_actionStateLock) { RunningActions.ForEach(x => { if (!actionCase.IsHandled) { var ahr = x.TryHandle(actionCase); if (ahr != null) { ahResults.Add(ahr); } } return(false); }); } }
private void ProcessCompleted(ActionBase action) { if (action.Token.IsStateFinished) { if (RunningActions.Remove(action)) { action.Token.Name = action.Name + ": " + action.AboutMeSafe(); if (_actionChangeCallback != null) { _actionChangeCallback(action.Token); } action.Token.SetCompletedSignal(); if (!SuppressDebugOutput) { "{0:X2} {1}"._DLOG(SessionId, action.GetName() + action.AboutMeSafe()); } CallbackBufferBlock.Add(action); ActionCaseConsumer.Add(action); } } }
public bool IsEmpty() { if (WentLive) { return(false); } if (FinishedFeatures.Any()) { return(false); } if (RunningActions.Any()) { return(false); } if (!string.IsNullOrEmpty(InProgressFeature)) { return(false); } if (ConvertedUsersCountDifference > 0) { return(false); } if (NewUsersCountDifference > 0) { return(false); } if (AverageOrderAmountDifference > 0) { return(false); } return(true); }
private void HandleActionCaseInner(IActionCase actionCase) { var customDataFrame = actionCase as CustomDataFrame; var timeInterval = actionCase as TimeInterval; var action = actionCase as ActionBase; if (customDataFrame != null) { CustomDataFrame dataFrameOri = customDataFrame; var ahResults = new List <ActionHandlerResult>(); Dictionary <SubstituteIncomingFlags, CustomDataFrame> substitutedDataFrames = new Dictionary <SubstituteIncomingFlags, CustomDataFrame>(); var dataFrame = SubstituteIncoming(dataFrameOri, ahResults, substitutedDataFrames); if (dataFrame != null) { TryHandleDataFrame(dataFrame, ahResults); if (dataFrame.Parent != null) { TryHandleDataFrame(dataFrame.Parent, ahResults); } ProcessSubstituteManagers(dataFrame, ahResults, substitutedDataFrames); foreach (var ahResult in ahResults) { ProcessNext(ahResult); if (ahResult.Parent != null) { ProcessCompleted(ahResult.Parent); } } } } else if (timeInterval != null) { if (timeInterval.ParentAction != null) { ProcessNext(timeInterval.ParentAction.TryHandle(actionCase)); if (timeInterval.ParentAction != null) { ProcessCompleted(timeInterval.ParentAction); } } } else if (action != null) { if (action.Token.IsStateFinished) { ProcessCompleted(action); if (action.IsExclusive) { _isExclusiveBusy = false; var pendingAction = PendingExclusiveActions.Dequeue(); if (pendingAction != null) { _actionCaseConsumer.Add(pendingAction); } } RunningActions.ForEach(x => { if (x.ParentAction == action) { if (x.ParentAction.Token.State == ActionStates.Expired || x.ParentAction.Token.State == ActionStates.Cancelled) { x.Token.SetCancelling(); var ahResult = x.TryHandleStopped(); ProcessNext(ahResult); x.Token.SetCancelled(); ProcessCompleted(x); } else { x.Token.SetCancelled(); ProcessCompleted(x); } } return(false); }); if (action.ParentAction != null && action.ParentAction.Token.IsStateActive) { var ahResult = action.ParentAction.TryHandle(action); ProcessNext(ahResult); action.ParentAction.FixStates(); ProcessCompleted(action.ParentAction); } } else { if (action.Token.State == ActionStates.None) { var actionStartSignal = action.Token.StartSignal; action.SessionId = SessionId; if (action.IsSequenceNumberRequired) { action.SequenceNumber = NextFuncId(); } action = SubstituteAction(action); if (action.IsExclusive) { if (!SuppressDebugOutput) { "{0:X2} (W){1}"._DLOG(SessionId, action.GetName() + action.AboutMeSafe()); } if (_isExclusiveBusy) { PendingExclusiveActions.Enqueue(action); return; } else { _isExclusiveBusy = true; } //CheckPoint.Pass(action); } var ahResult = action.Start(); if (_actionChangeCallback != null) { _actionChangeCallback(action.Token); } if (action.IsFirstPriority) { RunningActions.AddFirst(action); } else { RunningActions.AddLast(action); } if (!SuppressDebugOutput) { "{0:X2} {1}"._DLOG(SessionId, action.GetName() + action.AboutMeSafe()); } ProcessNext(ahResult); if (action.Token.TimeoutMs > 0) { TimeoutManager.AddTimer(action.Token); } if (actionStartSignal != null && !isDisposing) { actionStartSignal.Set(); } } else if (action.Token.Result.State == ActionStates.Cancelling) { var ahResult = action.TryHandleStopped(); ProcessNext(ahResult); } else if (action.Token.Result.State == ActionStates.Expiring) { var ahResult = action.TryHandleStopped(); ProcessNext(ahResult); } action.FixStates(); ProcessCompleted(action); } } }