Ejemplo n.º 1
0
        private SchedulerClient GetSchedulerClient(string strProcess, ScheduleHistoryItem objScheduleHistoryItem)
        {
            try
            {
                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                // This is a method to encapsulate returning
                // an object whose class inherits SchedulerClient.
                // ''''''''''''''''''''''''''''''''''''''''''''''''''

                // Return value
                SchedulerClient objRetClient = null;
                // The constructor we've found
                System.Reflection.ConstructorInfo objConstructor = null;

                // The type we need
                Type t = Type.GetType(strProcess, true);

                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                // Get the default constructor for the class
                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                objConstructor = t.GetConstructor(System.Type.EmptyTypes);
                if (null != objConstructor)
                {
                    // Found the default constructor
                    objRetClient = (SchedulerClient)objConstructor.Invoke(null);
                }
                else
                {
                    // ''''''''''''''''''''''''''''''''''''''''''''''''''
                    // Get the parameterised constructor for the class
                    // ''''''''''''''''''''''''''''''''''''''''''''''''''

                    // Parameters we pass to the constructor
                    ScheduleHistoryItem[] param = new ScheduleHistoryItem[1];
                    param[0] = objScheduleHistoryItem;
                    // Parameter types we pass to the constructor
                    Type[] types = new Type[1];
                    types[0] = typeof(ScheduleHistoryItem);
                    // Get the parameterised contructor
                    objConstructor = t.GetConstructor(types);
                    // Call the constructor
                    objRetClient = (SchedulerClient)objConstructor.Invoke(param);
                }

                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                // Return an instance of the class as an object
                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                return(objRetClient);
            }
            catch (Exception exc)
            {
                //Exceptions.ProcessSchedulerException(exc);
                throw exc;
            }
            return(null);
        }
Ejemplo n.º 2
0
        public void Run(ScheduleHistoryItem objScheduleHistoryItem)
        {
            try
            {
                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                // This is called from RunPooledThread()
                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                ticksElapsed = Environment.TickCount - ticksElapsed;
                // This is what we're running
                SchedulerClient Process = null;
                // Create an instance of our SchedulerClient derived class using Reflection
                Process = GetSchedulerClient(objScheduleHistoryItem.TypeFullName, objScheduleHistoryItem);
                // Store the schedule info/item in the instance
                Process.ScheduleHistoryItem = objScheduleHistoryItem;

                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                // Set up the handlers to the CoreScheduler from our instance
                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                Process.ProcessStarted     += new WorkStarted(Scheduler.CoreScheduler.WorkStarted);
                Process.ProcessProgressing += new WorkProgressing(Scheduler.CoreScheduler.WorkProgressing);
                Process.ProcessCompleted   += new WorkCompleted(Scheduler.CoreScheduler.WorkCompleted);
                Process.ProcessErrored     += new WorkErrored(Scheduler.CoreScheduler.WorkErrored);

                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                // This kicks off the DoWork method of the class
                // type specified in the configuration.
                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                Process.Started();

                // Do the actual work
                try
                {
                    // Do the actual work
                    Process.DoWork();
                }
                catch (Exception exc)
                {
                    // In case the scheduler client
                    // didn't have proper exception handling
                    // make sure we fire the Errored event
                    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)
                {
                    ticksElapsed = (Environment.TickCount - ticksElapsed);
                    if (null != Completed)
                    {
                        Completed();
                    }
                }
            }
            catch (Exception exc)
            {
                //Exceptions.ProcessSchedulerException(exc);
                throw exc;
            }
            finally
            {
                // See if we need to undo impersonation
                //if (null != impersonationContext)
                //{
                //    Globals.UndoImpersonation(impersonationContext);
                //}

                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                // Track how many processes have completed for
                // this instanciation of the ProcessGroup
                // ''''''''''''''''''''''''''''''''''''''''''''''''''
                numberOfProcessesInQueue -= 1;
                processesCompleted++;
            }
        }