Example #1
0
 public void Stop()
 {
     if (CurrentState == State.Stopped)
     {
         throw new InvalidOperationException("The profile has already been stopped!");
     }
     _OneSecondTimer.Stop();
     CurrentState = State.Stopped;
     ExecutionFinished?.Invoke(this, new EventArgs());
 }
Example #2
0
        /// <summary>
        /// Data sources can use this to indicate an executionDetails has finished.
        /// </summary>
        /// <param name="executionDetails">The executionDetails.</param>
        /// <param name="startTime">The start time.</param>
        /// <param name="endTime">The end time.</param>
        /// <param name="rowsAffected">The number of rows affected.</param>
        /// <param name="state">User defined state, usually used for logging.</param>
        /// <exception cref="ArgumentNullException">executionDetails - executionDetails is null.</exception>
        protected void OnExecutionFinished(ExecutionToken executionDetails, DateTimeOffset startTime, DateTimeOffset endTime, int?rowsAffected, object?state)
        {
            if (executionDetails == null)
            {
                throw new ArgumentNullException(nameof(executionDetails), $"{nameof(executionDetails)} is null.");
            }

            ExecutionFinished?.Invoke(this, new ExecutionEventArgs(executionDetails, startTime, endTime, rowsAffected, state));
            if (!SuppressGlobalEvents)
            {
                GlobalExecutionFinished?.Invoke(this, new ExecutionEventArgs(executionDetails, startTime, endTime, rowsAffected, state));
            }
        }
Example #3
0
        public void OnExecutionFinished(ExecutionEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e), $"{nameof(e)} is null.");
            }

            ExecutionFinished?.Invoke(this, e);
            if (!SuppressGlobalEvents && GlobalExecutionFinished != null)
            {
                GlobalExecutionFinished(this, e);
            }
        }
Example #4
0
        private void ResetBeatAfterSeconds(float time)
        {
            _currentNotes.Clear();
            _currentQualities.Clear();
            _beatStarterEnabled = false;
            int streakPower = _streakPower;

            _coroutineProvider.StartCoroutine(Coroutines.ExecuteAfterSeconds(time, () => {
                if (_currentSong != null)
                {
                    _currentSong.FinishCommandExecution();
                    ExecutionFinishing?.Invoke(_currentSong, streakPower);
                    Song activeSong = _currentSong;
                    _coroutineProvider.StartCoroutine(Coroutines.ExecuteAfterSeconds(HALF_NOTE_TIME, () => {
                        ExecutionFinished?.Invoke(activeSong, streakPower);
                        EnableTouchHandler();
                    }));
                }

                _currentCommandUpdate = Constants.Noop;
                _currentSong          = null;
                _beatStarterEnabled   = true;
            }));
        }
        internal async Task StartSubscribe()
        {
            var reader = TaskQueueReader;

            SubscriberStarted?.Invoke(this);
            while (true)
            {
                T newPayload;
                try
                {
                    newPayload = await reader.ReadAsync(TaskManagerCancellationToken.Token).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    break;
                }
                catch (Exception e)
                {
                    TaskPayloadFetchException?.Invoke(this, e);
                    continue;
                }

                var cts = TaskManagerCancellationToken;
                CancellationTokenSource localCts = null;
                var timeout = ExecutionTimeout;
                if (timeout.HasValue)
                {
                    localCts = new CancellationTokenSource(timeout.Value);
                    cts      = CancellationTokenSource.CreateLinkedTokenSource(
                        TaskManagerCancellationToken.Token,
                        localCts.Token);
                }
                try
                {
                    ExecutionStarting?.Invoke(this);
                    await Execution(newPayload, cts).ConfigureAwait(false);

                    ExecutionFinished?.Invoke(this);
                }
                catch (OperationCanceledException ex)
                {
                    if (localCts?.IsCancellationRequested ?? false)
                    {
                        ExecutionTimeoutEvent?.Invoke(this);
                    }
                    else
                    {
                        SubscriberCancelled?.Invoke(this, ex);
                        break;
                    }
                }
                catch (ObjectDisposedException ed)
                {
                    SubscriberCancelled?.Invoke(this, ed);
                    break;
                }
                catch (Exception e)
                {
                    ExecutionException?.Invoke(this, e);
                }

                if (TaskManagerCancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }
            TaskSubscriberFinalized?.Invoke(this);
        }
Example #6
0
        // Event invocation, break handling and so on
        private void Execute(IExecutionEnvironment environment, IList <IInstruction> instructions, int waitMs)
        {
            Reset();
            IsFinished = false;
            IsAborted  = false;
            IsHalted   = false;

            ExecutionStarted?.Invoke(this, new EventArgs());

            while (!IsFinished && !IsAborted)
            {
                // Set the instruction for this cycle
                SetCurrentInstruction(environment, instructions);

                // Check if instruction is marked as a breakpoint and if it is active
                if (_breakPoints.ContainsKey(CurrentInstruction) && _breakPoints[CurrentInstruction])
                {
                    BreakExecution(CurrentInstruction, instructions.IndexOf(CurrentInstruction));
                }
                else if (IsHalted)
                {
                    // If instruction is not a breakpoint and IsHalted was already true, we stepped one instruction further
                    ExecutionStepped?.Invoke(this, new InstructionExecuteEventArgs(CurrentInstruction, CurrentInstructionIndex));
                }

                // Halt the thread if a breakpoint was reached
                if (IsHalted)
                {
                    try
                    {
                        Thread.Sleep(Timeout.Infinite);
                    }
                    catch (ThreadInterruptedException)
                    {
                        // Through an interrupt, the thread will continue from here
                    }
                    catch (ThreadAbortException)
                    {
                        // The further execution will be aborted
                        IsAborted = true;
                        break;
                    }
                }

                // Execute instruction
                InstructionExecuting?.Invoke(this, new InstructionExecuteEventArgs(CurrentInstruction, CurrentInstructionIndex));

                Thread.Sleep(waitMs);
                try
                {
                    ExecuteInternal(environment, instructions);
                }
                catch (Exception e)
                {
                    // Abort execution when the instruction throws
                    Logger.Log(LogLevel.Fatal, e.Message);
                    AbortExecution(true);
                    break;
                }

                InstructionExecuted?.Invoke(this, new InstructionExecuteEventArgs(CurrentInstruction, CurrentInstructionIndex));
            }

            if (!IsAborted)
            {
                ExecutionFinished?.Invoke(this, new EventArgs());
            }
        }
        internal async Task PullTaskAsync(CancellationToken token)
        {
            var alreadyLogout = false;

            TaskPullerStarted?.Invoke(this);
            while (true)
            {
                if (TaskManagerCancellationToken.IsCancellationRequested)
                {
                    break;
                }

                if (!LinkedMetadata.IsExecutorEnabled)
                {
                    break;
                }

                var cts = TaskManagerCancellationToken;
                CancellationTokenSource localCts = null;
                var timeout = ExecutionTimeout;
                if (timeout.HasValue)
                {
                    localCts = new CancellationTokenSource(timeout.Value);
                    cts      = CancellationTokenSource.CreateLinkedTokenSource(
                        TaskManagerCancellationToken.Token,
                        localCts.Token);
                }

                try
                {
                    ExecutionStarting?.Invoke(this);
                    await Execution(cts).ConfigureAwait(false);

                    ExecutionFinished?.Invoke(this);
                }
                catch (OperationCanceledException)
                {
                    if (localCts?.IsCancellationRequested ?? false)
                    {
                        ExecutionTimeoutEvent?.Invoke(this);
                    }
                    else
                    {
                        ExecutionCancelled?.Invoke(this);
                        break;
                    }
                }
                catch (ObjectDisposedException)
                {
                    break;
                }
                catch (Exception e)
                {
                    ExecutionExceptionHandler?.Invoke(this, e);
                }

                if (TaskManagerCancellationToken.IsCancellationRequested)
                {
                    break;
                }

                if (!LinkedMetadata.IsExecutorEnabled)
                {
                    break;
                }

                if (LinkedMetadata.GlobalApproveNewExecutorCreationCriteriaInContext() && ShouldTryToCreateNewPuller())
                {
                    CreatingNewPuller?.Invoke(this);
#pragma warning disable 4014
                    LinkedMetadata.CreateNewTaskExecutor(token);
#pragma warning restore 4014
                    NewPullerCreated?.Invoke(this);
                }

                if (!ShouldTryTerminateCurrentPuller())
                {
                    continue;
                }

                //Try kill itself
                if (await LinkedMetadata.TryPerformLogoutAsync().ConfigureAwait(false))
                {
                    alreadyLogout = true;
                    break;
                }
            }

            if (!alreadyLogout)
            {
                await LinkedMetadata.ForceLogoutAsync().ConfigureAwait(false);
            }

            TaskPullerFinalized?.Invoke(this);
        }
 protected void fireExecutionFinished(bool canceled, RuntimeError error)
 {
     ExecutionFinished?.Invoke(canceled, error);
 }
Example #9
0
        protected override void OnPostExecute(object result)
        {
            base.OnPostExecute(result);

            ExecutionFinished?.Invoke(this, EventArgs.Empty);
        }
Example #10
0
        /// <summary>
        /// Raises the event <see cref="ExecutionFinished"/>.
        /// </summary>
        protected internal void RaiseExecutionFinished()
        {
            _log.Debug(nameof(RaiseExecutionFinished));

            ExecutionFinished?.Invoke(this, EventArgs.Empty);
        }