Changeset 2487
- Timestamp:
- 3/13/2012 11:37:30 PM (15 months ago)
- Location:
- branches/eraser6/pluginsRewrite
- Files:
-
- 3 edited
-
Eraser.Manager/DirectExecutor.cs (modified) (2 diffs)
-
Eraser.Manager/Task.cs (modified) (6 diffs)
-
Eraser.Plugins/ProgressManager.cs (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/pluginsRewrite/Eraser.Manager/DirectExecutor.cs
r2470 r2487 254 254 if (task != null) 255 255 { 256 LogSink sessionLog = new LogSink(); 257 task.Log.Add(sessionLog); 258 256 259 //Start a new log session to separate this session's events 257 260 //from previous ones. 258 LogSink sessionLog = new LogSink(); 259 task.Log.Add(sessionLog); 260 using (new LogSession(sessionLog)) 261 try 261 262 { 262 ExecuteTask(task); 263 using (new LogSession(sessionLog)) 264 { 265 //Set the currently executing task. 266 currentTask = task; 267 268 //Prevent the system from sleeping. 269 Power.ExecutionState = ExecutionState.Continuous | 270 ExecutionState.SystemRequired; 271 272 task.Execute(); 273 } 274 } 275 finally 276 { 277 //Allow the system to sleep again. 278 Power.ExecutionState = ExecutionState.Continuous; 279 280 //If the task is a recurring task, reschedule it for the next execution 281 //time since we are done with this one. 282 if (task.Schedule is RecurringSchedule) 283 ScheduleTask(task); 284 285 //Remove the actively executing task from our instance variable 286 currentTask = null; 263 287 } 264 288 } … … 266 290 //Wait for half a minute to check for the next scheduled task. 267 291 schedulerInterrupt.WaitOne(30000, false); 268 }269 }270 271 /// <summary>272 /// Executes the given task.273 /// </summary>274 /// <param name="task">The task to execute.</param>275 private void ExecuteTask(Task task)276 {277 //Set the currently executing task.278 currentTask = task;279 280 //Prevent the system from sleeping.281 Power.ExecutionState = ExecutionState.Continuous | ExecutionState.SystemRequired;282 283 try284 {285 //Broadcast the task started event.286 task.Canceled = false;287 task.OnTaskStarted();288 289 //Run the task290 foreach (IErasureTarget target in task.Targets)291 try292 {293 target.Execute();294 }295 catch (FatalException)296 {297 throw;298 }299 catch (OperationCanceledException)300 {301 throw;302 }303 catch (SharingViolationException)304 {305 }306 }307 catch (FatalException e)308 {309 Logger.Log(e.Message, LogLevel.Fatal);310 }311 catch (OperationCanceledException e)312 {313 Logger.Log(e.Message, LogLevel.Fatal);314 }315 catch (SharingViolationException)316 {317 }318 finally319 {320 //Allow the system to sleep again.321 Power.ExecutionState = ExecutionState.Continuous;322 323 //If the task is a recurring task, reschedule it since we are done.324 if (task.Schedule is RecurringSchedule)325 {326 ((RecurringSchedule)task.Schedule).Reschedule(DateTime.Now);327 ScheduleTask(task);328 }329 330 //And the task finished event.331 task.OnTaskFinished();332 333 //If the task is an execute on restart task or run immediately task, it is334 //only run once and can now be restored to a manually run task335 if (task.Schedule == Schedule.RunOnRestart || task.Schedule == Schedule.RunNow)336 task.Schedule = Schedule.RunManually;337 338 //Remove the actively executing task from our instance variable339 currentTask = null;340 292 } 341 293 } -
branches/eraser6/pluginsRewrite/Eraser.Manager/Task.cs
r2485 r2487 41 41 public class Task : ITask, ISerializable 42 42 { 43 #region ErasureTargetProgressManagerStep 44 /// <summary> 45 /// Returns the progress of an erasure target, since that comprises the 46 /// steps of the Task Progress. 47 /// </summary> 48 private class ErasureTargetProgressManagerStep : SteppedProgressManagerStepBase 49 { 50 /// <summary> 51 /// Constructor. 52 /// </summary> 53 /// <param name="target">The erasure target represented by this object.</param> 54 /// <param name="steps">The number of targets in the task.</param> 55 public ErasureTargetProgressManagerStep(IErasureTarget target, int targets) 56 : base(1.0f / targets) 57 { 58 Target = target; 59 } 60 61 public override ProgressManagerBase Progress 62 { 63 get 64 { 65 return Target.Progress; 66 } 67 set 68 { 69 throw new InvalidOperationException(); 70 } 71 } 72 73 private IErasureTarget Target; 74 } 75 #endregion 76 43 77 #region Serialization code 44 78 protected Task(SerializationInfo info, StreamingContext context) … … 88 122 89 123 /// <summary> 90 /// Cancels the task from running, or, if the task is queued for running,91 /// removes the task from the queue.92 /// </summary>93 public void Cancel()94 {95 Executor.UnqueueTask(this);96 Canceled = true;97 }98 99 /// <summary>100 124 /// The Executor object which is managing this task. 101 125 /// </summary> … … 152 176 return S._("{0} and {1} other targets", result, Targets.Count - 3); 153 177 } 154 }155 156 /// <summary>157 /// Gets the status of the task - whether it is being executed.158 /// </summary>159 public bool Executing { get; private set; }160 161 /// <summary>162 /// Gets whether this task is currently queued to run. This is true only163 /// if the queue it is in is an explicit request, i.e will run when the164 /// executor is idle.165 /// </summary>166 public bool Queued167 {168 get169 {170 return Executor.IsTaskQueued(this);171 }172 }173 174 /// <summary>175 /// Gets whether the task has been cancelled from execution.176 /// </summary>177 public bool Canceled178 {179 get;180 internal set;181 178 } 182 179 … … 242 239 } 243 240 241 /// <summary> 242 /// Gets the status of the task - whether it is being executed. 243 /// </summary> 244 public bool Executing { get; private set; } 245 246 /// <summary> 247 /// Gets whether this task is currently queued to run. This is true only 248 /// if the queue it is in is an explicit request, i.e will run when the 249 /// executor is idle. 250 /// </summary> 251 public bool Queued 252 { 253 get 254 { 255 if (Executor == null) 256 throw new InvalidOperationException(); 257 258 return Executor.IsTaskQueued(this); 259 } 260 } 261 262 /// <summary> 263 /// Gets whether the task has been cancelled from execution. 264 /// </summary> 265 public bool Canceled 266 { 267 get; 268 private set; 269 } 270 271 /// <summary> 272 /// Cancels the task from running, or, if the task is queued for running, 273 /// removes the task from the queue. 274 /// </summary> 275 public void Cancel() 276 { 277 Executor.UnqueueTask(this); 278 Canceled = true; 279 } 280 281 /// <summary> 282 /// Executes the task in the context of the calling thread. 283 /// </summary> 284 public void Execute() 285 { 286 OnTaskStarted(); 287 Executing = true; 288 Canceled = false; 289 Progress = new SteppedProgressManager(); 290 291 try 292 { 293 //Run the task 294 foreach (IErasureTarget target in Targets) 295 try 296 { 297 Progress.Steps.Add(new ErasureTargetProgressManagerStep( 298 target, Targets.Count)); 299 target.Execute(); 300 } 301 catch (FatalException) 302 { 303 throw; 304 } 305 catch (OperationCanceledException) 306 { 307 throw; 308 } 309 catch (SharingViolationException) 310 { 311 } 312 } 313 catch (FatalException e) 314 { 315 Logger.Log(e.Message, LogLevel.Fatal); 316 } 317 catch (OperationCanceledException e) 318 { 319 Logger.Log(e.Message, LogLevel.Fatal); 320 } 321 catch (SharingViolationException) 322 { 323 } 324 finally 325 { 326 //If the task is a recurring task, reschedule it since we are done. 327 if (Schedule is RecurringSchedule) 328 { 329 ((RecurringSchedule)Schedule).Reschedule(DateTime.Now); 330 } 331 332 //If the task is an execute on restart task or run immediately task, it is 333 //only run once and can now be restored to a manually run task 334 if (Schedule == Schedule.RunOnRestart || Schedule == Schedule.RunNow) 335 Schedule = Schedule.RunManually; 336 337 Progress = null; 338 Executing = false; 339 OnTaskFinished(); 340 } 341 } 342 244 343 private Executor executor; 245 344 private Schedule schedule; … … 274 373 /// Broadcasts the task execution start event. 275 374 /// </summary> 276 internalvoid OnTaskStarted()375 private void OnTaskStarted() 277 376 { 278 377 if (TaskStarted != null) 279 378 TaskStarted(this, EventArgs.Empty); 280 Executing = true;281 Progress = new SteppedProgressManager();282 379 } 283 380 … … 285 382 /// Broadcasts the task execution completion event. 286 383 /// </summary> 287 internal void OnTaskFinished() 288 { 289 Progress = null; 290 Executing = false; 384 private void OnTaskFinished() 385 { 291 386 if (TaskFinished != null) 292 387 TaskFinished(this, EventArgs.Empty); -
branches/eraser6/pluginsRewrite/Eraser.Plugins/ProgressManager.cs
r2486 r2487 351 351 /// The class which manages the steps which comprise the overall progress. 352 352 /// </summary> 353 private class StepsList : IList<SteppedProgressManagerStep >353 private class StepsList : IList<SteppedProgressManagerStepBase> 354 354 { 355 355 public StepsList(SteppedProgressManager manager) 356 356 { 357 List = new List<SteppedProgressManagerStep >();357 List = new List<SteppedProgressManagerStepBase>(); 358 358 ListLock = manager.ListLock; 359 359 } … … 361 361 #region IList<SteppedProgressManagerStep> Members 362 362 363 public int IndexOf(SteppedProgressManagerStep item)363 public int IndexOf(SteppedProgressManagerStepBase item) 364 364 { 365 365 lock (ListLock) … … 367 367 } 368 368 369 public void Insert(int index, SteppedProgressManagerStep item)369 public void Insert(int index, SteppedProgressManagerStepBase item) 370 370 { 371 371 lock (ListLock) … … 385 385 } 386 386 387 public SteppedProgressManagerStep this[int index]387 public SteppedProgressManagerStepBase this[int index] 388 388 { 389 389 get … … 407 407 #region ICollection<SteppedProgressManagerStep> Members 408 408 409 public void Add(SteppedProgressManagerStep item)409 public void Add(SteppedProgressManagerStepBase item) 410 410 { 411 411 lock (ListLock) … … 425 425 } 426 426 427 public bool Contains(SteppedProgressManagerStep item)427 public bool Contains(SteppedProgressManagerStepBase item) 428 428 { 429 429 lock (ListLock) … … 431 431 } 432 432 433 public void CopyTo(SteppedProgressManagerStep [] array, int arrayIndex)433 public void CopyTo(SteppedProgressManagerStepBase[] array, int arrayIndex) 434 434 { 435 435 lock (ListLock) … … 451 451 } 452 452 453 public bool Remove(SteppedProgressManagerStep item)453 public bool Remove(SteppedProgressManagerStepBase item) 454 454 { 455 455 int index = List.IndexOf(item); … … 464 464 #region IEnumerable<SteppedProgressManagerStep> Members 465 465 466 public IEnumerator<SteppedProgressManagerStep > GetEnumerator()466 public IEnumerator<SteppedProgressManagerStepBase> GetEnumerator() 467 467 { 468 468 return List.GetEnumerator(); … … 502 502 /// The list storing the steps for this instance. 503 503 /// </summary> 504 private List<SteppedProgressManagerStep > List;504 private List<SteppedProgressManagerStepBase> List; 505 505 506 506 /// <summary> … … 621 621 /// The list of steps involved in completion of the task. 622 622 /// </summary> 623 public IList<SteppedProgressManagerStep > Steps623 public IList<SteppedProgressManagerStepBase> Steps 624 624 { 625 625 get; … … 631 631 /// no steps are executing (also when the task is complete) 632 632 /// </summary> 633 public SteppedProgressManagerStep CurrentStep633 public SteppedProgressManagerStepBase CurrentStep 634 634 { 635 635 get … … 640 640 return null; 641 641 642 foreach (SteppedProgressManagerStep step in Steps)642 foreach (SteppedProgressManagerStepBase step in Steps) 643 643 if (step.Progress.Progress < 1.0f) 644 644 return step; … … 680 680 /// Represents one step in the list of steps to complete. 681 681 /// </summary> 682 public class SteppedProgressManagerStep 682 public abstract class SteppedProgressManagerStepBase 683 { 684 /// <summary> 685 /// Constructor. 686 /// </summary> 687 /// <param name="weight">The weight of this step. The weight is a decimal 688 /// number in the range [0.0, 1.0] which represents the percentage of the 689 /// entire process this particular step is.</param> 690 protected SteppedProgressManagerStepBase(float weight) 691 : this(weight, null) 692 { 693 } 694 695 /// <summary> 696 /// Constructor. 697 /// </summary> 698 /// <param name="weight">The weight of this step. The weight is a decimal 699 /// number in the range [0.0, 1.0] which represents the percentage of the 700 /// entire process this particular step is.</param> 701 /// <param name="name">A user-specified value of the name of this step. 702 /// This value is not used by the class at all.</param> 703 protected SteppedProgressManagerStepBase(float weight, string name) 704 { 705 if (float.IsInfinity(weight) || float.IsNaN(weight)) 706 throw new ArgumentException("The weight of a progress manager step must be " + 707 "a valid floating-point value."); 708 709 Weight = weight; 710 Name = name; 711 } 712 713 /// <summary> 714 /// The <see cref="ProgressManagerBase"/> instance which measures the 715 /// progress of the step. 716 /// </summary> 717 public abstract ProgressManagerBase Progress 718 { 719 get; 720 set; 721 } 722 723 /// <summary> 724 /// The weight associated with this step. 725 /// </summary> 726 public float Weight 727 { 728 get; 729 private set; 730 } 731 732 /// <summary> 733 /// The name of this step. 734 /// </summary> 735 public string Name 736 { 737 get; 738 set; 739 } 740 } 741 742 public class SteppedProgressManagerStep : SteppedProgressManagerStepBase 683 743 { 684 744 /// <summary> … … 706 766 /// This value is not used by the class at all.</param> 707 767 public SteppedProgressManagerStep(ProgressManagerBase progress, float weight, string name) 708 { 709 if (float.IsInfinity(weight) || float.IsNaN(weight)) 710 throw new ArgumentException("The weight of a progress manager step must be " + 711 "a valid floating-point value."); 712 768 : base(weight, name) 769 { 713 770 Progress = progress; 714 Weight = weight;715 Name = name;716 771 } 717 772 … … 720 775 /// progress of the step. 721 776 /// </summary> 722 public ProgressManagerBase Progress 723 { 724 get; 725 set; 726 } 727 728 /// <summary> 729 /// The weight associated with this step. 730 /// </summary> 731 public float Weight 732 { 733 get; 734 private set; 735 } 736 737 /// <summary> 738 /// The name of this step. 739 /// </summary> 740 public string Name 777 public override ProgressManagerBase Progress 741 778 { 742 779 get;
Note: See TracChangeset
for help on using the changeset viewer.
