Beispiel #1
0
 public static void TaskProgressing(TaskBase task)
 {
     try
     {
     }
     catch (Exception exc)
     {
         ErrorLogger.SchedulerProcessException(exc);
     }
 }
Beispiel #2
0
        public static void TaskStarted(TaskBase task)
        {
            bool ActiveThreadCountIncremented = false;

            try
            {
                task.TaskRecordItem.ThreadID = Thread.CurrentThread.GetHashCode();
                if (task.TaskRecordItem.Status != true)
                {
                    task.TaskRecordItem.Status = false;
                }
                task.TaskRecordItem.ReturnText = "Process Started";

                IPHostEntry entries = Dns.GetHostByName(Dns.GetHostName());
                task.TaskRecordItem.Server = entries.AddressList[0].ToString();

                RemoveFromScheduleQueue(task.TaskRecordItem);
                AddToScheduleInProgress(task.TaskRecordItem);

                Interlocked.Increment(ref ActiveThreadCount);
                ActiveThreadCountIncremented = true;

                task.TaskRecordItem.HistoryStartDate  = DateTime.Now;
                task.TaskRecordItem.ScheduleHistoryID = SchedulerController.AddTaskHistory(task.TaskRecordItem);
            }
            catch (Exception exc)
            {
                if (ActiveThreadCountIncremented)
                {
                    Interlocked.Decrement(ref ActiveThreadCount);
                }
                if (task.TaskRecordItem != null)
                {
                    ErrorLogger.SchedulerProcessException(exc);
                }
            }
        }
Beispiel #3
0
        public static void TaskCompleted(TaskBase task)
        {
            try
            {
                ScheduleHistory objScheduleHistory = task.TaskRecordItem;
                objScheduleHistory = task.TaskRecordItem;

                RemoveFromScheduleInProgress(objScheduleHistory);
                Interlocked.Decrement(ref ActiveThreadCount);

                objScheduleHistory.HistoryEndDate = DateTime.Now;

                objScheduleHistory.Status    = true;
                objScheduleHistory.NextStart = SchedulerController.GetNextStart(objScheduleHistory);

                task.TaskRecordItem.ReturnText = "Successfully completed";

                SchedulerController.UpdateTaskHistory(objScheduleHistory);

                if (!string.IsNullOrEmpty(objScheduleHistory.NextStart))
                {
                    objScheduleHistory.HistoryStartDate = null;
                    objScheduleHistory.HistoryEndDate   = null;
                    objScheduleHistory.ReturnText       = "";
                    objScheduleHistory.ProcessGroup     = -1;
                    objScheduleHistory.Status           = false;
                    AddToScheduleQueue(objScheduleHistory);
                }
            }
            catch (Exception exc)
            {
                if (task.TaskRecordItem != null)
                {
                    ErrorLogger.SchedulerProcessException(exc);
                }
            }
        }
Beispiel #4
0
        private TaskBase GetTaskBase(string strProcess, ScheduleHistory objScheduleHistory)
        {
            //This is a method to encapsulate returning
            //an object whose class inherits TaskBase.
            Type t     = BuildManager.GetType(strProcess, true, true);
            var  param = new ScheduleHistory[1];

            param[0] = objScheduleHistory;
            var types = new Type[1];

            //Get the constructor for the Class
            types[0] = typeof(ScheduleHistory);
            System.Reflection.ConstructorInfo objConstructor;
            objConstructor = t.GetConstructor(types);

            TaskBase taskBase = null;

            if (objConstructor != null)
            {
                taskBase = (TaskBase)objConstructor.Invoke(param);
            }

            return(taskBase);
        }
        public static void TaskStarted(TaskBase task)
        {

            bool ActiveThreadCountIncremented = false;
            try
            {
                task.TaskRecordItem.ThreadID = Thread.CurrentThread.GetHashCode();
                if (task.TaskRecordItem.Status != true)
                    task.TaskRecordItem.Status = false;
                task.TaskRecordItem.ReturnText = "Process Started";

                IPHostEntry entries = Dns.GetHostByName(Dns.GetHostName());
                task.TaskRecordItem.Server = entries.AddressList[0].ToString();

                RemoveFromScheduleQueue(task.TaskRecordItem);
                AddToScheduleInProgress(task.TaskRecordItem);

                Interlocked.Increment(ref ActiveThreadCount);
                ActiveThreadCountIncremented = true;

                task.TaskRecordItem.HistoryStartDate = DateTime.Now;
                task.TaskRecordItem.ScheduleHistoryID = SchedulerController.AddTaskHistory(task.TaskRecordItem);
            }
            catch (Exception exc)
            {
                if (ActiveThreadCountIncremented)
                    Interlocked.Decrement(ref ActiveThreadCount);
                if (task.TaskRecordItem != null) ErrorLogger.SchedulerProcessException(exc);

            }

        }
        public static void TaskProgressing(TaskBase task)
        {
            try
            {

            }
            catch (Exception exc)
            {
                ErrorLogger.SchedulerProcessException(exc);
            }
        }
        public static void TaskErrored(TaskBase task, Exception exception)
        {
            try
            {
                ScheduleHistory objScheduleHistoryItem = task.TaskRecordItem;

                RemoveFromScheduleInProgress(objScheduleHistoryItem);

                Interlocked.Decrement(ref ActiveThreadCount);

                objScheduleHistoryItem.HistoryEndDate = DateTime.Now;

                DateTime startedTime = objScheduleHistoryItem.HistoryStartDate ?? DateTime.Now;

                if (objScheduleHistoryItem.RetryTimeLapse > 0)
                {
                    switch (objScheduleHistoryItem.RetryFrequencyUnit)
                    {
                        case 1:
                            startedTime.AddSeconds(objScheduleHistoryItem.RetryTimeLapse);
                            break;
                        case 2:
                            startedTime.AddMinutes(objScheduleHistoryItem.RetryTimeLapse);
                            break;
                        case 3:
                            startedTime.AddHours(objScheduleHistoryItem.RetryTimeLapse);
                            break;
                        case 4:
                            startedTime.AddDays(objScheduleHistoryItem.RetryTimeLapse);
                            break;
                    }
                    objScheduleHistoryItem.NextStart = Convert.ToString(startedTime);
                }

                objScheduleHistoryItem.Status = false;
                string error = "";

                StringBuilder errorlog = new StringBuilder();

                errorlog.AppendLine("Error");
                if ((exception != null))
                {
                    error = exception.Message;
                }
                errorlog.AppendLine(error);

                task.TaskRecordItem.ReturnText = errorlog.ToString();

                SchedulerController.UpdateTaskHistory(objScheduleHistoryItem);

                if (!string.IsNullOrEmpty(objScheduleHistoryItem.NextStart) && objScheduleHistoryItem.RetryTimeLapse > 0)
                {
                    objScheduleHistoryItem.HistoryStartDate = null;
                    objScheduleHistoryItem.HistoryEndDate = null;
                    objScheduleHistoryItem.ReturnText = "";
                    objScheduleHistoryItem.ProcessGroup = -1;
                    AddToScheduleQueue(objScheduleHistoryItem);
                }
            }
            catch (Exception exc)
            {
                if (task.TaskRecordItem != null) ErrorLogger.SchedulerProcessException(exc);
            }
        }
        public static void TaskCompleted(TaskBase task)
        {
            try
            {
                ScheduleHistory objScheduleHistory = task.TaskRecordItem;
                objScheduleHistory = task.TaskRecordItem;

                RemoveFromScheduleInProgress(objScheduleHistory);
                Interlocked.Decrement(ref ActiveThreadCount);

                objScheduleHistory.HistoryEndDate = DateTime.Now;

                objScheduleHistory.Status = true;
                objScheduleHistory.NextStart = SchedulerController.GetNextStart(objScheduleHistory);

                task.TaskRecordItem.ReturnText = "Successfully completed";

                SchedulerController.UpdateTaskHistory(objScheduleHistory);

                if (!string.IsNullOrEmpty(objScheduleHistory.NextStart))
                {
                    objScheduleHistory.HistoryStartDate = null;
                    objScheduleHistory.HistoryEndDate = null;
                    objScheduleHistory.ReturnText = "";
                    objScheduleHistory.ProcessGroup = -1;
                    objScheduleHistory.Status = false;
                    AddToScheduleQueue(objScheduleHistory);
                }
            }
            catch (Exception exc)
            {
                if (task.TaskRecordItem != null) ErrorLogger.SchedulerProcessException(exc);
            }
        }
Beispiel #9
0
        public static void TaskErrored(TaskBase task, Exception exception)
        {
            try
            {
                ScheduleHistory objScheduleHistoryItem = task.TaskRecordItem;

                RemoveFromScheduleInProgress(objScheduleHistoryItem);

                Interlocked.Decrement(ref ActiveThreadCount);

                objScheduleHistoryItem.HistoryEndDate = DateTime.Now;

                DateTime startedTime = objScheduleHistoryItem.HistoryStartDate ?? DateTime.Now;

                if (objScheduleHistoryItem.RetryTimeLapse > 0)
                {
                    switch (objScheduleHistoryItem.RetryFrequencyUnit)
                    {
                    case 1:
                        startedTime.AddSeconds(objScheduleHistoryItem.RetryTimeLapse);
                        break;

                    case 2:
                        startedTime.AddMinutes(objScheduleHistoryItem.RetryTimeLapse);
                        break;

                    case 3:
                        startedTime.AddHours(objScheduleHistoryItem.RetryTimeLapse);
                        break;

                    case 4:
                        startedTime.AddDays(objScheduleHistoryItem.RetryTimeLapse);
                        break;
                    }
                    objScheduleHistoryItem.NextStart = Convert.ToString(startedTime);
                }

                objScheduleHistoryItem.Status = false;
                string error = "";

                StringBuilder errorlog = new StringBuilder();

                errorlog.AppendLine("Error");
                if ((exception != null))
                {
                    error = exception.Message;
                }
                errorlog.AppendLine(error);

                task.TaskRecordItem.ReturnText = errorlog.ToString();

                SchedulerController.UpdateTaskHistory(objScheduleHistoryItem);

                if (!string.IsNullOrEmpty(objScheduleHistoryItem.NextStart) && objScheduleHistoryItem.RetryTimeLapse > 0)
                {
                    objScheduleHistoryItem.HistoryStartDate = null;
                    objScheduleHistoryItem.HistoryEndDate   = null;
                    objScheduleHistoryItem.ReturnText       = "";
                    objScheduleHistoryItem.ProcessGroup     = -1;
                    AddToScheduleQueue(objScheduleHistoryItem);
                }
            }
            catch (Exception exc)
            {
                if (task.TaskRecordItem != null)
                {
                    ErrorLogger.SchedulerProcessException(exc);
                }
            }
        }
Beispiel #10
0
        public void Run(ScheduleHistory objScheduleHistory)
        {
            TaskBase Process = null;

            try
            {
                //This is called from RunPooledThread()
                ticksElapsed           = Environment.TickCount - ticksElapsed;
                Process                = GetTaskBase(objScheduleHistory.FullNamespace, objScheduleHistory);
                Process.TaskRecordItem = objScheduleHistory;

                //Set up the handlers for the CoreScheduler
                Process.ScheduleStarted += Scheduler.TaskStarted;
                // Process.ScheduleProcessing += Scheduler.CoreScheduler.WorkProgressing;
                Process.ScheduleCompleted += Scheduler.TaskCompleted;
                Process.ScheduleErrored   += Scheduler.TaskErrored;
                //This kicks off the DoWork method of the class
                //type specified in the configuration.

                Process.Started();
                try
                {
                    Process.TaskRecordItem.Status = false;
                    Process.Execute();
                }
                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.TaskRecordItem != null)
                        {
                            Process.TaskRecordItem.Status = false;
                        }
                        Process.Error(ref exc);
                    }
                }
                if (Process.TaskRecordItem.Status == true)
                {
                    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.TaskRecordItem != null)
                    {
                        Process.TaskRecordItem.Status = false;
                    }
                    Process.Error(ref exc);
                }
            }
            finally
            {
                //Track how many processes have completed for
                //this instanciation of the ProcessGroup
                numberOfProcessesInQueue -= 1;
                processesCompleted       += 1;

                if (Process != null)
                {
                    try
                    {
                        Process.Completed();
                        ((IDisposable)Process).Dispose();
                        Process = null;
                    }
                    catch (Exception)
                    {
                        Process.Completed();
                        Process = null;
                    }
                }
            }
        }