示例#1
0
        public static ReportExecution GetNextJob()
        {
            ReportExecution exec = null;

            #region logging

            Logger.TraceEvent(
                TraceEventType.Verbose,
                0,
                "{0}: BEGIN GetNextJob()",
                System.Threading.Thread.CurrentThread.ManagedThreadId);

            #endregion

            try
            {
                using (ReportingDataContext data = new ReportingDataContext())
                {
                    //get the next execution from the queue
                    var execRow =
                        (from e in data.GetExecutionFromQueue()
                         where e.ScheduledStartDate.HasValue
                         select e).FirstOrDefault();

                    if (execRow == null)
                    {
                        return(null);
                    }

                    try
                    {
                        var format       = data.GetFormat(execRow.ReportFormatID).FirstOrDefault();
                        var report       = data.GetReport(execRow.ReportID, execRow.EnvironmentID).FirstOrDefault();
                        var subscription = data.GetSubscription(execRow.ReportSubscriptionID).FirstOrDefault();
                        exec = GetReportExecutionFromRow(execRow, format, report, subscription);
                    }
                    catch (Exception ex)
                    {
                        //WI #2889: mark the execution for retry on exception
                        data.SetExecutionRetry(
                            execRow.ReportExecutionID,
                            execRow.Name,
                            null,
                            null,
                            ex.ToString(),
                            null,
                            execRow.ErrorCount + 1,
                            execRow.ScheduledStartDate,
                            "SYSTEM",
                            DateTime.Now);

                        //re-throw exception
                        throw;
                    }
                }
            }

            #region logging

            finally
            {
                Logger.TraceEvent(
                    TraceEventType.Verbose,
                    0,
                    "{0}: END GetNextJob(id={1}, state={2}, run={3}, nextRun={4}, subscription={5}, reportId={6}, path={7}, formatId={8}, format={9})",
                    System.Threading.Thread.CurrentThread.ManagedThreadId,
                    exec != null ? exec.Id : null,
                    exec != null ? (ReportExecutionStateEnum?)exec.State : null,
                    exec != null ? exec.ScheduledRunTime : null,
                    exec != null ? exec.NextScheduledRunTime : null,
                    exec != null ? exec.SubscriptionId : null,
                    exec != null ? (int?)exec.ReportId : null,
                    exec != null ? exec.ReportPath : null,
                    exec != null ? (int?)exec.FormatId : null,
                    exec != null ? exec.Format : null);
            }

            #endregion

            return(exec);
        }