Пример #1
0
        public void Run(ScheduleHistoryItem objScheduleHistoryItem)
        {
            SchedulerClient Process = null;

            try
            {
                //This is called from RunPooledThread()
                ticksElapsed = Environment.TickCount - ticksElapsed;
                Process      = GetSchedulerClient(objScheduleHistoryItem.TypeFullName, objScheduleHistoryItem);
                Process.ScheduleHistoryItem = objScheduleHistoryItem;

                //Set up the handlers for the CoreScheduler
                Process.ProcessStarted     += Scheduler.CoreScheduler.WorkStarted;
                Process.ProcessProgressing += Scheduler.CoreScheduler.WorkProgressing;
                Process.ProcessCompleted   += Scheduler.CoreScheduler.WorkCompleted;
                Process.ProcessErrored     += Scheduler.CoreScheduler.WorkErrored;
                //This kicks off the DoWork method of the class
                //type specified in the configuration.

                Process.Started();
                try
                {
                    Process.ScheduleHistoryItem.Succeeded = false;
                    Process.DoWork();
                }
                catch (Exception exc)
                {
                    //in case the scheduler client
                    //didn't have proper exception handling
                    //make sure we fire the Errored event
                    Logger.Error(exc);

                    if (Process != null)
                    {
                        if (Process.ScheduleHistoryItem != null)
                        {
                            Process.ScheduleHistoryItem.Succeeded = false;
                        }
                        Process.Errored(ref exc);
                    }
                }
                if (Process.ScheduleHistoryItem.Succeeded)
                {
                    Process.Completed();
                }

                //If all processes in this ProcessGroup have
                //completed, set the ticksElapsed and raise
                //the Completed event.
                //I don't think this is necessary with the
                //other events.  I'll leave it for now and
                //will probably take it out later.

                if (processesCompleted == numberOfProcesses)
                {
                    if (processesCompleted == numberOfProcesses)
                    {
                        ticksElapsed = Environment.TickCount - ticksElapsed;
                        if (Completed != null)
                        {
                            Completed();
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                //in case the scheduler client
                //didn't have proper exception handling
                //make sure we fire the Errored event
                if (Process != null)
                {
                    if (Process.ScheduleHistoryItem != null)
                    {
                        Process.ScheduleHistoryItem.Succeeded = false;
                    }
                    Process.Errored(ref exc);
                }
                else
                {
                    //when the schedule has invalid config and can't initialize the Process,
                    //we need also trigger work errored event so that the schedule can remove from inprogress and inqueue list to prevent endless loop.
                    Scheduler.CoreScheduler.WorkStarted(objScheduleHistoryItem);
                    objScheduleHistoryItem.Succeeded = false;
                    Scheduler.CoreScheduler.WorkErrored(objScheduleHistoryItem, exc);
                }
            }
            finally
            {
                //Track how many processes have completed for
                //this instanciation of the ProcessGroup
                numberOfProcessesInQueue -= 1;
                processesCompleted       += 1;
            }
        }