Changeset 1765


Ignore:
Timestamp:
2/8/2010 6:44:59 AM (4 years ago)
Author:
lowjoel
Message:

Removed the TaskProcessing? and TaskProcessed? events in Executor which duplicate the TaskStarted? and TaskFinished? events in Task. The TaskEventArgs? class can't disappear just yet as the TaskAdded? and TaskDeleted? events still need them (the sender is not the task, it's the executor) Addresses #275: Code Review

Location:
branches/eraser6/CodeReview
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/CodeReview/Eraser.Manager/DirectExecutor.cs

    r1745 r1765  
    2727using System.Threading; 
    2828using System.IO; 
     29using System.Runtime.Serialization; 
     30using System.Runtime.Serialization.Formatters.Binary; 
    2931 
    3032using Eraser.Util; 
    3133using Eraser.Util.ExtensionMethods; 
    32 using System.Security.Principal; 
    33 using System.Runtime.Serialization; 
    34 using System.Runtime.Serialization.Formatters.Binary; 
    35 using System.Security.Permissions; 
    3634 
    3735namespace Eraser.Manager 
     
    152150        } 
    153151 
    154         private void OnTaskEdited(object sender, TaskEventArgs e) 
     152        private void OnTaskEdited(object sender, EventArgs e) 
    155153        { 
    156154            //Find all schedule entries containing the task - since the user cannot make 
    157155            //edits to the task when it is queued (only if it is scheduled) remove 
    158156            //all task references and add them back 
     157            Task task = (Task)sender; 
    159158            lock (tasksLock) 
    160159                for (int i = 0; i != scheduledTasks.Count; ++i) 
     
    162161                    { 
    163162                        Task currentTask = scheduledTasks.Values[i][j]; 
    164                         if (currentTask == e.Task) 
     163                        if (currentTask == task) 
    165164                            scheduledTasks.Values[i].RemoveAt(j); 
    166165                        else 
     
    169168 
    170169            //Then reschedule the task 
    171             if (e.Task.Schedule is RecurringSchedule) 
    172                 ScheduleTask(e.Task); 
     170            if (task.Schedule is RecurringSchedule) 
     171                ScheduleTask(task); 
    173172        } 
    174173 
     
    248247                        //Broadcast the task started event. 
    249248                        task.Canceled = false; 
    250                         task.OnTaskStarted(new TaskEventArgs(task)); 
    251                         OnTaskProcessing(new TaskEventArgs(task)); 
     249                        task.OnTaskStarted(); 
    252250 
    253251                        //Run the task 
     
    318316 
    319317                        //And the task finished event. 
    320                         task.OnTaskFinished(new TaskEventArgs(task)); 
    321                         OnTaskProcessed(new TaskEventArgs(task)); 
     318                        task.OnTaskFinished(); 
    322319 
    323320                        //Remove the actively executing task from our instance variable 
  • branches/eraser6/CodeReview/Eraser.Manager/Executor.cs

    r1681 r1765  
    126126                TaskDeleted(this, e); 
    127127        } 
    128  
    129         /// <summary> 
    130         /// The task processing event object. 
    131         /// </summary> 
    132         public EventHandler<TaskEventArgs> TaskProcessing { get; set; } 
    133  
    134         /// <summary> 
    135         /// Helper function for the Task processing event. 
    136         /// </summary> 
    137         protected void OnTaskProcessing(TaskEventArgs e) 
    138         { 
    139             if (TaskProcessing != null) 
    140                 TaskProcessing(this, e); 
    141         } 
    142  
    143         /// <summary> 
    144         /// The task processed event object. 
    145         /// </summary> 
    146         public EventHandler<TaskEventArgs> TaskProcessed { get; set; } 
    147  
    148         /// <summary> 
    149         /// Helper function for the Task processed event. 
    150         /// </summary> 
    151         protected void OnTaskProcessed(TaskEventArgs e) 
    152         { 
    153             if (TaskProcessed != null) 
    154                 TaskProcessed(this, e); 
    155         } 
    156128    } 
    157129 
  • branches/eraser6/CodeReview/Eraser.Manager/Task.cs

    r1745 r1765  
    226226        /// The task has been edited. 
    227227        /// </summary> 
    228         public EventHandler<TaskEventArgs> TaskEdited { get; set; } 
     228        public EventHandler TaskEdited { get; set; } 
    229229 
    230230        /// <summary> 
    231231        /// The start of the execution of a task. 
    232232        /// </summary> 
    233         public EventHandler<TaskEventArgs> TaskStarted { get; set; } 
     233        public EventHandler TaskStarted { get; set; } 
    234234 
    235235        /// <summary> 
     
    241241        /// The completion of the execution of a task. 
    242242        /// </summary> 
    243         public EventHandler<TaskEventArgs> TaskFinished { get; set; } 
     243        public EventHandler TaskFinished { get; set; } 
    244244 
    245245        /// <summary> 
     
    249249        { 
    250250            if (TaskEdited != null) 
    251                 TaskEdited(this, new TaskEventArgs(this)); 
     251                TaskEdited(this, EventArgs.Empty); 
    252252        } 
    253253 
     
    255255        /// Broadcasts the task execution start event. 
    256256        /// </summary> 
    257         /// <param name="e"></param> 
    258         internal void OnTaskStarted(TaskEventArgs e) 
     257        internal void OnTaskStarted() 
    259258        { 
    260259            if (TaskStarted != null) 
    261                 TaskStarted(this, e); 
     260                TaskStarted(this, EventArgs.Empty); 
    262261            Executing = true; 
    263262            Progress = new SteppedProgressManager(); 
     
    294293        /// Broadcasts the task execution completion event. 
    295294        /// </summary> 
    296         /// <param name="e"></param> 
    297         internal void OnTaskFinished(TaskEventArgs e) 
     295        internal void OnTaskFinished() 
    298296        { 
    299297            if (TaskFinished != null) 
    300                 TaskFinished(this, e); 
     298                TaskFinished(this, EventArgs.Empty); 
    301299            Executing = false; 
    302300            Progress = null; 
  • branches/eraser6/CodeReview/Eraser/MainForm.cs

    r1745 r1765  
    5454            Theming.ApplyTheme(notificationMenu); 
    5555 
    56             //Connect to the executor task processing and processed events. 
    57             Program.eraserClient.TaskProcessing += OnTaskProcessing; 
    58             Program.eraserClient.TaskProcessed += OnTaskProcessed; 
     56            //For every task we need to register the Task Started and Task Finished 
     57            //event handlers for progress notifications 
     58            foreach (Task task in Program.eraserClient.Tasks) 
     59                OnTaskAdded(this, new TaskEventArgs(task)); 
     60            Program.eraserClient.TaskAdded += OnTaskAdded; 
     61            Program.eraserClient.TaskDeleted += OnTaskDeleted; 
    5962 
    6063            //Check the notification area context menu's minimise to tray item. 
     
    305308 
    306309        #region Task processing code (for notification area animation) 
    307         void OnTaskProcessing(object sender, TaskEventArgs e) 
     310        void OnTaskAdded(object sender, TaskEventArgs e) 
     311        { 
     312            e.Task.TaskStarted += OnTaskProcessing; 
     313            e.Task.TaskFinished += OnTaskProcessed; 
     314        } 
     315 
     316        void OnTaskDeleted(object sender, TaskEventArgs e) 
     317        { 
     318            e.Task.TaskStarted -= OnTaskProcessing; 
     319            e.Task.TaskFinished -= OnTaskProcessed; 
     320        } 
     321 
     322        void OnTaskProcessing(object sender, EventArgs e) 
    308323        { 
    309324            if (InvokeRequired) 
    310325            { 
    311                 Invoke((EventHandler<TaskEventArgs>)OnTaskProcessing, sender, e); 
     326                Invoke((EventHandler)OnTaskProcessing, sender, e); 
    312327                return; 
    313328            } 
    314329 
    315             string iconText = S._("Eraser") + " - " + S._("Processing:") + ' ' + e.Task.UIText; 
     330            Task task = (Task)sender; 
     331            string iconText = S._("Eraser") + " - " + S._("Processing:") + ' ' + task.UIText; 
    316332            if (iconText.Length >= 64) 
    317333                iconText = iconText.Remove(60) + "..."; 
     
    322338        } 
    323339 
    324         void OnTaskProcessed(object sender, TaskEventArgs e) 
     340        void OnTaskProcessed(object sender, EventArgs e) 
    325341        { 
    326342            if (InvokeRequired) 
    327343            { 
    328                 Invoke((EventHandler<TaskEventArgs>)OnTaskProcessed, sender, e); 
     344                Invoke((EventHandler)OnTaskProcessed, sender, e); 
    329345                return; 
    330346            } 
  • branches/eraser6/CodeReview/Eraser/ProgressForm.cs

    r1745 r1765  
    8989        } 
    9090 
    91         private void task_TaskFinished(object sender, TaskEventArgs e) 
     91        private void task_TaskFinished(object sender, EventArgs e) 
    9292        { 
    9393            if (IsDisposed || !IsHandleCreated) 
     
    9595            if (InvokeRequired) 
    9696            { 
    97                 Invoke((EventHandler<TaskEventArgs>)task_TaskFinished, sender, e); 
     97                Invoke((EventHandler)task_TaskFinished, sender, e); 
    9898                return; 
    9999            } 
    100100 
    101101            //Update the UI. Set everything to 100% 
     102            Task task = (Task)sender; 
    102103            timeLeft.Text = item.Text = pass.Text = string.Empty; 
    103104            overallProgressLbl.Text = S._("Total: {0,2:#0.00%}", 1.0); 
     
    109110            //Inform the user on the status of the task. 
    110111            LogLevel highestLevel = LogLevel.Information; 
    111             LogEntryCollection entries = e.Task.Log.LastSessionEntries; 
     112            LogEntryCollection entries = task.Log.LastSessionEntries; 
    112113            foreach (LogEntry log in entries) 
    113114                if (log.Level > highestLevel) 
  • branches/eraser6/CodeReview/Eraser/SchedulerPanel.cs

    r1745 r1765  
    186186        /// </summary> 
    187187        /// <param name="e">The task event object.</param> 
    188         void task_TaskStarted(object sender, TaskEventArgs e) 
     188        void task_TaskStarted(object sender, EventArgs e) 
    189189        { 
    190190            if (InvokeRequired) 
    191191            { 
    192                 Invoke((EventHandler<TaskEventArgs>)task_TaskStarted, sender, e); 
     192                Invoke((EventHandler)task_TaskStarted, sender, e); 
    193193                return; 
    194194            } 
    195195 
    196196            //Get the list view item 
    197             ListViewItem item = GetTaskItem(e.Task); 
     197            Task task = (Task)sender; 
     198            ListViewItem item = GetTaskItem(task); 
    198199 
    199200            //Update the status. 
     
    228229        /// Handles the task completion event. 
    229230        /// </summary> 
    230         void task_TaskFinished(object sender, TaskEventArgs e) 
     231        void task_TaskFinished(object sender, EventArgs e) 
    231232        { 
    232233            if (InvokeRequired) 
    233234            { 
    234                 Invoke((EventHandler<TaskEventArgs>)task_TaskFinished, sender, e); 
     235                Invoke((EventHandler)task_TaskFinished, sender, e); 
    235236                return; 
    236237            } 
    237238 
    238239            //Get the list view item 
    239             ListViewItem item = GetTaskItem(e.Task); 
     240            Task task = (Task)sender; 
     241            ListViewItem item = GetTaskItem(task); 
    240242            if (item == null) 
    241243                return; 
     
    250252            //Get the exit status of the task. 
    251253            LogLevel highestLevel = LogLevel.Information; 
    252             LogEntryCollection logs = e.Task.Log.LastSessionEntries; 
     254            LogEntryCollection logs = task.Log.LastSessionEntries; 
    253255            foreach (LogEntry log in logs) 
    254256                if (log.Level > highestLevel) 
     
    269271                { 
    270272                    case LogLevel.Warning: 
    271                         message = S._("The task {0} has completed with warnings.", e.Task.UIText); 
     273                        message = S._("The task {0} has completed with warnings.", task.UIText); 
    272274                        icon = ToolTipIcon.Warning; 
    273275                        break; 
    274276                    case LogLevel.Error: 
    275                         message = S._("The task {0} has completed with errors.", e.Task.UIText); 
     277                        message = S._("The task {0} has completed with errors.", task.UIText); 
    276278                        icon = ToolTipIcon.Error; 
    277279                        break; 
    278280                    case LogLevel.Fatal: 
    279                         message = S._("The task {0} did not complete.", e.Task.UIText); 
     281                        message = S._("The task {0} did not complete.", task.UIText); 
    280282                        icon = ToolTipIcon.Error; 
    281283                        break; 
    282284                    default: 
    283                         message = S._("The task {0} has completed.", e.Task.UIText); 
     285                        message = S._("The task {0} has completed.", task.UIText); 
    284286                        icon = ToolTipIcon.Info; 
    285287                        break; 
     
    292294            //If the user requested us to remove completed one-time tasks, do so. 
    293295            if (EraserSettings.Get().ClearCompletedTasks && 
    294                 (e.Task.Schedule == Schedule.RunNow) && highestLevel < LogLevel.Warning) 
    295             { 
    296                 Program.eraserClient.Tasks.Remove(e.Task); 
     296                (task.Schedule == Schedule.RunNow) && highestLevel < LogLevel.Warning) 
     297            { 
     298                Program.eraserClient.Tasks.Remove(task); 
    297299            } 
    298300 
     
    319321                //category since run-on-restart tasks will be changed to immediately 
    320322                //run tasks. 
    321                 CategorizeTask(e.Task, item); 
     323                CategorizeTask(task, item); 
    322324 
    323325                //Update the status of the task. 
Note: See TracChangeset for help on using the changeset viewer.