Changeset 1102
- Timestamp:
- 6/3/2009 3:55:56 AM (4 years ago)
- Location:
- trunk/eraser6
- Files:
-
- 6 edited
-
Eraser.Manager/DirectExecutor.cs (modified) (7 diffs)
-
Eraser.Manager/Executor.cs (modified) (1 diff)
-
Eraser.Manager/RemoteExecutor.cs (modified) (1 diff)
-
Eraser.Manager/Schedule.cs (modified) (14 diffs)
-
Eraser.Manager/Task.cs (modified) (8 diffs)
-
Eraser/SchedulerPanel.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Manager/DirectExecutor.cs
r1085 r1102 45 45 public DirectExecutor() 46 46 { 47 TaskAdded += OnTaskAdded; 48 TaskDeleted += OnTaskDeleted; 47 49 Tasks = new DirectExecutorTasksCollection(this); 48 50 thread = new Thread(Main); … … 71 73 lock (tasksLock) 72 74 { 73 //Set the task variable to indicate that the task is already74 //waiting to be executed.75 task.Queued = true;76 77 75 //Queue the task to be run immediately. 78 76 DateTime executionTime = DateTime.Now; … … 117 115 for (int i = 0; i != scheduledTasks.Count; ++i) 118 116 for (int j = 0; j < scheduledTasks.Values[i].Count; ++j) 119 if (scheduledTasks.Values[i][j] == task) 117 { 118 Task currentTask = scheduledTasks.Values[i][j]; 119 if (currentTask == task && 120 (!(currentTask.Schedule is RecurringSchedule) || 121 ((RecurringSchedule)currentTask.Schedule).NextRun != scheduledTasks.Keys[i])) 120 122 { 121 123 scheduledTasks.Values[i].RemoveAt(i); 122 123 if (scheduledTasks.Values[i].Count == 0)124 scheduledTasks.RemoveAt(i);125 break;126 124 } 125 } 126 } 127 128 internal override bool IsTaskQueued(Task task) 129 { 130 lock (tasksLock) 131 foreach (KeyValuePair<DateTime, List<Task>> tasks in scheduledTasks) 132 foreach (Task i in tasks.Value) 133 if (task == i) 134 if (task.Schedule is RecurringSchedule) 135 { 136 if (((RecurringSchedule)task.Schedule).NextRun != tasks.Key) 137 return true; 138 } 139 else 140 return true; 141 142 return false; 143 } 144 145 private void OnTaskAdded(object sender, TaskEventArgs e) 146 { 147 e.Task.TaskEdited += OnTaskEdited; 148 } 149 150 private void OnTaskEdited(object sender, TaskEventArgs e) 151 { 152 //Find all schedule entries containing the task - since the user cannot make 153 //edits to the task when it is queued (only if it is scheduled) remove 154 //all task references and add them back 155 lock (tasksLock) 156 for (int i = 0; i != scheduledTasks.Count; ++i) 157 for (int j = 0; j < scheduledTasks.Values[i].Count; ) 158 { 159 Task currentTask = scheduledTasks.Values[i][j]; 160 if (currentTask == e.Task) 161 scheduledTasks.Values[i].RemoveAt(j); 162 else 163 j++; 164 } 165 166 //Then reschedule the task 167 if (e.Task.Schedule is RecurringSchedule) 168 ScheduleTask(e.Task); 169 } 170 171 private void OnTaskDeleted(object sender, TaskEventArgs e) 172 { 173 e.Task.TaskEdited -= OnTaskEdited; 127 174 } 128 175 … … 144 191 lock (tasksLock) 145 192 { 146 if (scheduledTasks.Count != 0 && scheduledTasks.Values[0].Count != 0 && 147 scheduledTasks.Keys[0] <= DateTime.Now) 148 { 149 List<Task> tasks = scheduledTasks.Values[0]; 150 task = tasks[0]; 151 tasks.RemoveAt(0); 152 153 //Remove the entry from the sorted list if the list of tasks 154 //with that one time to run has all been executed 155 if (tasks.Count == 0) 193 while (scheduledTasks.Count != 0) 194 if (scheduledTasks.Values[0].Count == 0) 195 { 196 //Clean all all time slots at the start of the queue which are 197 //empty 156 198 scheduledTasks.RemoveAt(0); 157 } 199 } 200 else 201 { 202 if (scheduledTasks.Keys[0] <= DateTime.Now) 203 { 204 List<Task> tasks = scheduledTasks.Values[0]; 205 task = tasks[0]; 206 tasks.RemoveAt(0); 207 } 208 209 //Do schedule queue maintenance: clean up all empty timeslots 210 if (task == null) 211 { 212 for (int i = 0; i < scheduledTasks.Count; ) 213 if (scheduledTasks.Values[i].Count == 0) 214 scheduledTasks.RemoveAt(i); 215 else 216 ++i; 217 } 218 219 break; 220 } 158 221 } 159 222 … … 170 233 171 234 //Broadcast the task started event. 172 task.Queued = false;173 235 task.Canceled = false; 174 236 task.OnTaskStarted(new TaskEventArgs(task)); … … 186 248 progress.Event.CurrentTarget = target; 187 249 ++progress.Event.CurrentTargetIndex; 188 if (target is UnusedSpaceTarget) 189 EraseUnusedSpace(task, (UnusedSpaceTarget)target, progress); 190 else if (target is FileSystemObjectTarget) 191 EraseFilesystemObject(task, (FileSystemObjectTarget)target, progress); 250 251 UnusedSpaceTarget unusedSpaceTarget = 252 target as UnusedSpaceTarget; 253 FileSystemObjectTarget fileSystemObjectTarget = 254 target as FileSystemObjectTarget; 255 256 if (unusedSpaceTarget != null) 257 EraseUnusedSpace(task, unusedSpaceTarget, progress); 258 else if (fileSystemObjectTarget != null) 259 EraseFilesystemObject(task, fileSystemObjectTarget, progress); 192 260 else 193 261 throw new ArgumentException(S._("Unknown erasure target.")); … … 695 763 EraseFileClusterTips(files[i], method); 696 764 } 697 catch ( Exception e)765 catch (IOException e) 698 766 { 699 767 task.Log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " + -
trunk/eraser6/Eraser.Manager/Executor.cs
r1012 r1102 71 71 /// Removes the given task from the execution queue. 72 72 /// </summary> 73 /// <remarks>If the task given runs a recurring schedule, the task will only 74 /// remove requested tasks and not the scheduled ones</remarks> 73 75 /// <param name="task">The task to cancel.</param> 74 76 public abstract void UnqueueTask(Task task); 77 78 /// <summary> 79 /// Gets whether a task is currently queued for execution, outside of the 80 /// scheduled time. 81 /// </summary> 82 /// <param name="task">The task to query.</param> 83 /// <returns>True if the task is currently queued, false otherwise.</returns> 84 internal abstract bool IsTaskQueued(Task task); 75 85 76 86 /// <summary> -
trunk/eraser6/Eraser.Manager/RemoteExecutor.cs
r1024 r1102 396 396 } 397 397 398 internal override bool IsTaskQueued(Task task) 399 { 400 throw new NotImplementedException(); 401 } 402 398 403 public override ExecutorTasksCollection Tasks { get; protected set; } 399 404 -
trunk/eraser6/Eraser.Manager/Schedule.cs
r957 r1102 97 97 98 98 /// <summary> 99 /// The owner of this schedule item. 100 /// </summary> 101 public Task Owner 102 { 103 get; 104 internal set; 105 } 106 107 /// <summary> 99 108 /// Populates a SerializationInfo with the data needed to serialize the 100 109 /// target object. … … 186 195 monthlySchedule = (int)info.GetValue("MonthlySchedule", typeof(int)); 187 196 188 lastRun = (DateTime)info.GetDateTime("LastRun");189 nextRun= (DateTime)info.GetDateTime("NextRun");197 LastRun = (DateTime)info.GetDateTime("LastRun"); 198 NextRunCache = (DateTime)info.GetDateTime("NextRun"); 190 199 } 191 200 … … 198 207 info.AddValue("WeeklySchedule", weeklySchedule); 199 208 info.AddValue("MonthlySchedule", monthlySchedule); 200 info.AddValue("LastRun", lastRun);201 info.AddValue("NextRun", nextRun);209 info.AddValue("LastRun", LastRun); 210 info.AddValue("NextRun", NextRunCache); 202 211 } 203 212 #endregion … … 216 225 { 217 226 get { return type; } 218 set { type = value; } 227 set 228 { 229 type = value; 230 if (Owner != null) 231 Owner.OnTaskEdited(); 232 } 219 233 } 220 234 … … 241 255 242 256 frequency = value; 257 if (Owner != null) 258 Owner.OnTaskEdited(); 243 259 } 244 260 } … … 250 266 { 251 267 get { return executionTime; } 252 set { executionTime = value; } 268 set 269 { 270 executionTime = value; 271 if (Owner != null) 272 Owner.OnTaskEdited(); 273 } 253 274 } 254 275 … … 275 296 276 297 weeklySchedule = value; 298 if (Owner != null) 299 Owner.OnTaskEdited(); 277 300 } 278 301 } … … 292 315 return monthlySchedule; 293 316 } 294 set { monthlySchedule = value; } 317 set 318 { 319 monthlySchedule = value; 320 321 if (Owner != null) 322 Owner.OnTaskEdited(); 323 } 295 324 } 296 325 … … 301 330 public DateTime LastRun 302 331 { 303 get { return lastRun; } 332 get; 333 private set; 304 334 } 305 335 … … 318 348 if (nextRun == DateTime.MinValue) 319 349 nextRun = DateTime.Now; 320 nextRun = nextRun.AddHours(executionTime.Hour - nextRun.Hour); 321 nextRun = nextRun.AddMinutes(executionTime.Minute - nextRun.Minute); 322 nextRun = nextRun.AddSeconds(executionTime.Second - nextRun.Second); 350 nextRun = new DateTime(nextRun.Year, nextRun.Month, nextRun.Day, executionTime.Hour, 351 executionTime.Minute, executionTime.Second); 323 352 324 353 switch (ScheduleType) … … 339 368 { 340 369 while (nextRun < DateTime.Now || 341 lastRun.DayOfWeek == DayOfWeek.Saturday ||342 lastRun.DayOfWeek == DayOfWeek.Sunday)370 LastRun.DayOfWeek == DayOfWeek.Saturday || 371 LastRun.DayOfWeek == DayOfWeek.Sunday) 343 372 nextRun = nextRun.AddDays(1); 344 373 break; … … 398 427 get 399 428 { 400 return lastRun != DateTime.MinValue && NextRun != nextRun;429 return LastRun != DateTime.MinValue && NextRun != NextRunCache; 401 430 } 402 431 } … … 422 451 internal void Reschedule(DateTime lastRun) 423 452 { 424 this.lastRun = lastRun;425 nextRun= NextRun;453 LastRun = lastRun; 454 NextRunCache = NextRun; 426 455 } 427 456 … … 432 461 private int monthlySchedule; 433 462 434 private DateTime lastRun; 435 private DateTime nextRun; 463 /// <summary> 464 /// The next time the task is scheduled to run - this is cached from the previous 465 /// calculation of the next run time to determine if the task's schedule was missed 466 /// </summary> 467 private DateTime NextRunCache; 436 468 } 437 469 -
trunk/eraser6/Eraser.Manager/Task.cs
r1085 r1102 47 47 Targets.Owner = this; 48 48 Log = (Logger)info.GetValue("Log", typeof(Logger)); 49 Canceled = false; 49 50 50 51 Schedule schedule = (Schedule)info.GetValue("Schedule", typeof(Schedule)); … … 80 81 Targets = new ErasureTargetsCollection(this); 81 82 Schedule = Schedule.RunNow; 83 Canceled = false; 82 84 Log = new Logger(); 83 85 } … … 138 140 /// executor is idle. 139 141 /// </summary> 140 public bool Queued { get; internal set; } 142 public bool Queued 143 { 144 get 145 { 146 return Executor.IsTaskQueued(this); 147 } 148 } 141 149 142 150 /// <summary> … … 153 161 /// The schedule for running the task. 154 162 /// </summary> 155 public Schedule Schedule { get; set; } 163 public Schedule Schedule 164 { 165 get 166 { 167 return schedule; 168 } 169 set 170 { 171 if (schedule.Owner != null) 172 throw new ArgumentException(S._("The schedule provided can only " + 173 "belong to one task at a time")); 174 175 if (schedule is RecurringSchedule) 176 ((RecurringSchedule)schedule).Owner = null; 177 schedule = value; 178 if (schedule is RecurringSchedule) 179 ((RecurringSchedule)schedule).Owner = this; 180 OnTaskEdited(); 181 } 182 } 156 183 157 184 /// <summary> … … 160 187 public Logger Log { get; private set; } 161 188 189 private Schedule schedule; 190 162 191 #region Events 163 192 /// <summary> 193 /// The task has been edited. 194 /// </summary> 195 public EventHandler<TaskEventArgs> TaskEdited { get; set; } 196 197 /// <summary> 164 198 /// The start of the execution of a task. 165 199 /// </summary> … … 175 209 /// </summary> 176 210 public EventHandler<TaskEventArgs> TaskFinished { get; set; } 211 212 /// <summary> 213 /// Broadcasts the task edited event. 214 /// </summary> 215 internal void OnTaskEdited() 216 { 217 if (TaskEdited != null) 218 TaskEdited(this, new TaskEventArgs(this)); 219 } 177 220 178 221 /// <summary> … … 613 656 result.AddRange(GetFiles(dir)); 614 657 } 615 catch ( Exception e)658 catch (DirectoryNotFoundException e) 616 659 { 617 660 //Ignore, but log. … … 720 763 foreach (FileSystemInfo fsInfo in info.GetFileSystemInfos()) 721 764 { 722 if (fsInfo is FileInfo) 765 FileInfo fileInfo = fsInfo as FileInfo; 766 if (fileInfo != null) 723 767 { 724 totalSize += ((FileInfo)fsInfo).Length;725 GetPathADSes(paths, out totalSize, f sInfo.FullName);726 paths.Add(f sInfo.FullName);768 totalSize += fileInfo.Length; 769 GetPathADSes(paths, out totalSize, fileInfo.FullName); 770 paths.Add(fileInfo.FullName); 727 771 } 728 772 else -
trunk/eraser6/Eraser/SchedulerPanel.cs
r1068 r1102 455 455 456 456 editTaskToolStripMenuItem.Enabled = scheduler.SelectedItems.Count == 1 && 457 !((Task)scheduler.SelectedItems[0].Tag).Executing; 457 !((Task)scheduler.SelectedItems[0].Tag).Executing && 458 !((Task)scheduler.SelectedItems[0].Tag).Queued; 458 459 deleteTaskToolStripMenuItem.Enabled = !aTaskExecuting; 459 460 } … … 540 541 private void editTaskToolStripMenuItem_Click(object sender, EventArgs e) 541 542 { 542 if (scheduler.SelectedItems.Count != 1) 543 return; 543 if (scheduler.SelectedItems.Count != 1 || 544 ((Task)scheduler.SelectedItems[0].Tag).Executing || 545 ((Task)scheduler.SelectedItems[0].Tag).Queued) 546 { 547 return; 548 } 544 549 545 550 //Make sure that the task is not being executed, or else. This can
Note: See TracChangeset
for help on using the changeset viewer.
