/// <summary>
 /// Checks if the the task has been cancelled and finishes the process.
 /// </summary>
 /// <param name="cancellationToken">Cancellation Token</param>
 protected void checkCanceledTask(CancellationToken cancellationToken)
 {
     if (cancellationToken.IsCancellationRequested)
     {
         this._state = ScheduledTaskState.CANCELLED;
         cancellationToken.ThrowIfCancellationRequested();
     }
 }
        // == METHOD(S)
        // ======================================================================

        /// <summary>
        /// Method invoked when task starts the work.
        /// </summary>
        /// <returns>Object : Usually the return is NULL.</returns>
        private Object taskExecution()
        {
            Object retValue = null;

            try
            {
                if (this._state == ScheduledTaskState.ERROR)
                {
                    this._newTentative = true;
                }
                else
                {
                    this._newTentative = false;
                }

                this._state = ScheduledTaskState.RUNNING;

                // == TASK LIFE-CYCLE EXECUTION

                this._cancellationToken = new CancellationTokenSource();
                onStart();

                // PARAMETER TREATMENT

                JObject param = null;

                if (this.task.Param != null)
                {
                    try
                    {
                        param = JObject.Parse(this.task.Param);
                    }
                    catch (System.Exception e)
                    {
                        throw new AuctionMasterTaskException(ExceptionType.FATAL, "Invalid param formatting - Expected: Valid JSON.");
                    }
                }

                onExecute(param, this._cancellationToken.Token);

                onFinish();
                this._state = ScheduledTaskState.IDLE;
            }
            catch (System.Exception e)
            {
                if (!(e is AuctionMasterTaskException))
                {
                    e = new AuctionMasterTaskException(ExceptionType.FATAL, e.Message, e);
                }

                this._state = ScheduledTaskState.ERROR;

                this.onError((AuctionMasterTaskException)e);
                retValue = (AuctionMasterTaskException)e;
            }

            return(retValue);
        }
        // == CONSTRUCTOR(S)
        // ======================================================================

        public GenericScheduledTask(IServiceScopeFactory scopeFactory, ScheduledTask scheduledTask)
        {
            this._scopeFactory  = scopeFactory;
            this._scheduledTask = scheduledTask;
            this._state         = ScheduledTaskState.IDLE;
        }