public void Execute(IJobExecutionContext quartzContext)
        {
            var data         = quartzContext.JobDetail.JobDataMap;
            var realization  = data["realization"];
            var jobActivity  = ((Func <IJobActivity>)realization)();
            var traceContext = (TraceContext)data["context"];
            var parameters   = (IDictionary <string, string>)data["parameters"];
            var getAudit     = (Func <DateTime, Action <string> >)data["getAudit"];

            JobActivityTool.ControlledExecution(jobActivity, traceContext, getAudit(DateTime.Now), parameters);
        }
        /// <summary>
        /// Listens the process.
        /// </summary>
        /// <param name="cloudStorageAccount">The cloud storage account.</param>
        /// <param name="jobConstructor">The job constructor.</param>
        /// <param name="instance">The instance.</param>
        /// <param name="getSystemJob">The get system job.</param>
        /// <param name="getIsCancellationRequested">The get is cancellation requested.</param>
        private void ListenerProcess(CloudStorageAccount cloudStorageAccount, Func <Type, IJobActivity> jobConstructor,
                                     string instance, Func <SystemJob> getSystemJob, Func <bool> getIsCancellationRequested)
        {
            try
            {
                var job = getSystemJob();

                var systemJobId   = job.SystemJobId;
                var multiInstance = job.AllowMultipleInstances;
                var type          = Type.GetType(job.JobClassType);
                Debug.Assert(type != null, "Can't find job with class name " + job.JobClassType);
                var jobParameters = job.JobParameters.ToDictionary(k => k.Name.ToLowerInvariant(), v => v.Value);

                string prevTaskScheduleId = null;
                while (true)                 // actually we could finish it in case of configuration changed and task become disabled
                {
                    if (_isStoped)
                    {
                        break;
                    }
                    try
                    {
                        var isDisabled = getIsCancellationRequested();                         //_schedulerDbContext.IsDisabled(systemJobId, multiInstance);
                        if (isDisabled)
                        {
                            break;
                        }

                        var queueReference =
                            cloudStorageAccount.CreateCloudQueueClient().GetQueueReference(_settings.GetQueueName(systemJobId));
                        queueReference.CreateIfNotExists();

                        var message = multiInstance
                                                        ? queueReference.PeekMessage()
                                                        : queueReference.GetMessage(TimeSpan.FromMinutes(30) /* Invisibility Timeout*/);
                        string taskScheduleId = null;
                        if (message != null)
                        {
                            taskScheduleId = message.AsString;
                            Guid tmp;
                            var  test = Guid.TryParse(taskScheduleId, out tmp);
                            Debug.Assert(test);

                            if (!multiInstance)
                            {
                                try
                                {
                                    queueReference.DeleteMessage(message);                                     // remove to ensure that other machines cannot execute task
                                }
                                catch (Exception ex)
                                {
                                    _traceSource.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                                }
                            }
                        }

                        if (taskScheduleId != null && prevTaskScheduleId != taskScheduleId)
                        {
                            // EXECUTE THE JOB
                            var             startDateTime = DateTime.Now;
                            Action <string> audit         = errorMessage =>
                                                            _schedulerDbContext.CreateSystemJobLogEntry(systemJobId, startDateTime, DateTime.Now,
                                                                                                        errorMessage, instance, taskScheduleId, multiInstance);
                            JobActivityTool.ControlledExecution(() => jobConstructor(type), _traceSource, audit, jobParameters);

                            prevTaskScheduleId = taskScheduleId;
                        }
                    }
                    catch (Exception ex)
                    {
                        _traceSource.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                        throw;
                    }
                    Thread.Sleep(Settings.QueueListenerWakeupFrequency);
                }
            }
            catch (Exception ex)
            {
                _traceSource.TraceEvent(TraceEventType.Error, 0, Helper.FormatException(ex, "JobScheduler", "ListenerProcess"));
            }
        }