Changeset 804
- Timestamp:
- 12/12/2008 6:48:57 AM (3 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Manager/DirectExecutor.cs (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Manager/DirectExecutor.cs
r803 r804 310 310 311 311 //Run the task 312 ProgressManager progress = newProgressManager(currentTask);312 TaskProgressManager progress = new TaskProgressManager(currentTask); 313 313 foreach (Task.ErasureTarget target in task.Targets) 314 314 try … … 369 369 370 370 /// <summary> 371 /// Provides a common interface to track the progress made by the Erase functions.371 /// Manages the progress for any operation. 372 372 /// </summary> 373 373 private class ProgressManager 374 374 { 375 375 /// <summary> 376 /// Constructor.376 /// Starts measuring the speed of the task. 377 377 /// </summary> 378 public ProgressManager(Task task)378 public void Start() 379 379 { 380 380 startTime = DateTime.Now; 381 Event = new TaskProgressEventArgs(task);382 383 foreach (Task.ErasureTarget target in task.Targets)384 totalData += target.TotalData;385 381 } 386 382 387 383 /// <summary> 388 /// Computes the speed of the erase, in bytes per second, based on the 389 /// information collected in the previous 10 seconds. 384 /// Tracks the amount of the operation completed. 385 /// </summary> 386 public long Completed 387 { 388 get 389 { 390 return completed; 391 } 392 set 393 { 394 completed = value; 395 } 396 } 397 398 /// <summary> 399 /// The amount to reach before the operation completes. 400 /// </summary> 401 public long Total 402 { 403 get 404 { 405 return total; 406 } 407 set 408 { 409 total = value; 410 } 411 } 412 413 /// <summary> 414 /// Gets the percentage of the operation completed. 415 /// </summary> 416 public float Progress 417 { 418 get 419 { 420 return (float)((double)Completed / Total); 421 } 422 } 423 424 /// <summary> 425 /// Computes the speed of the erase, in units of completion per second, 426 /// based on the information collected in the previous 5 seconds. 390 427 /// </summary> 391 428 public int Speed … … 400 437 401 438 lastSpeedCalc = DateTime.Now; 402 lastSpeed = (int)( DataWritten/ (DateTime.Now - startTime).TotalSeconds);439 lastSpeed = (int)(Completed / (DateTime.Now - startTime).TotalSeconds); 403 440 return lastSpeed; 404 441 } … … 415 452 if (Speed == 0) 416 453 return new TimeSpan(0, 0, -1); 417 return new TimeSpan(0, 0, (int)(( totalData - DataWritten) / Speed));454 return new TimeSpan(0, 0, (int)((Total - Completed) / Speed)); 418 455 } 419 456 } 420 457 421 458 /// <summary> 422 /// T racks the amount of data written, to determine the speed of the erase.459 /// The starting time of the operation, used to determine average speed. 423 460 /// </summary> 424 public long DataWritten 425 { 426 get 427 { 428 return dataWritten; 429 } 430 set 431 { 432 dataWritten = value; 433 } 461 private DateTime startTime; 462 463 /// <summary> 464 /// The last time a speed calculation was computed so that speed is not 465 /// computed too often. 466 /// </summary> 467 private DateTime lastSpeedCalc; 468 469 /// <summary> 470 /// The last calculated speed of the operation. 471 /// </summary> 472 private int lastSpeed; 473 474 /// <summary> 475 /// The amount of the operation completed. 476 /// </summary> 477 private long completed; 478 479 /// <summary> 480 /// The amount to reach before the operation is completed. 481 /// </summary> 482 private long total; 483 } 484 485 /// <summary> 486 /// Provides a common interface to track the progress made by the Erase functions. 487 /// </summary> 488 private class TaskProgressManager : ProgressManager 489 { 490 /// <summary> 491 /// Constructor. 492 /// </summary> 493 public TaskProgressManager(Task task) 494 { 495 foreach (Task.ErasureTarget target in task.Targets) 496 Total += target.TotalData; 497 498 Event = new TaskProgressEventArgs(task); 499 Start(); 434 500 } 435 501 … … 450 516 } 451 517 452 private long totalData;453 private DateTime startTime;454 private DateTime lastSpeedCalc;455 private int lastSpeed;456 private long dataWritten;457 518 private TaskProgressEventArgs evt; 458 519 } … … 464 525 /// <param name="target">The target of the unused space erase.</param> 465 526 /// <param name="progress">The progress manager object managing the progress of the task</param> 466 private void EraseUnusedSpace(Task task, Task.UnusedSpace target, ProgressManager progress)527 private void EraseUnusedSpace(Task task, Task.UnusedSpace target, TaskProgressManager progress) 467 528 { 468 529 //Check for sufficient privileges to run the unused space erasure. 469 530 if (!Permissions.IsAdministrator()) 470 531 { 471 472 532 if (Environment.OSVersion.Platform == PlatformID.Win32NT && 473 533 Environment.OSVersion.Version >= new Version(6, 0)) … … 498 558 progress.Event.timeLeft = progress.TimeLeft; 499 559 task.OnProgressChanged(progress.Event); 500 560 561 ProgressManager tipProgress = new ProgressManager(); 562 tipProgress.Start(); 501 563 EraseClusterTips(task, target, method, 502 564 delegate(int currentFile, string currentFilePath, int totalFiles) 503 565 { 566 tipProgress.Total = totalFiles; 567 tipProgress.Completed = currentFile; 568 504 569 progress.Event.currentItemName = S._("(Tips) {0}", currentFilePath); 505 progress.Event.currentItemProgress = (float)currentFile / totalFiles;570 progress.Event.currentItemProgress = tipProgress.Progress; 506 571 progress.Event.CurrentTargetProgress = progress.Event.CurrentItemProgress / 10; 572 progress.Event.timeLeft = tipProgress.TimeLeft; 507 573 task.OnProgressChanged(progress.Event); 508 574 } … … 573 639 delegate(long lastWritten, int currentPass) 574 640 { 575 progress. DataWritten+= lastWritten;641 progress.Completed += lastWritten; 576 642 progress.Event.currentItemPass = currentPass; 577 progress.Event.currentItemProgress = (float)progress.DataWritten / totalSize;643 progress.Event.currentItemProgress = progress.Progress; 578 644 if (target.EraseClusterTips) 579 645 progress.Event.CurrentTargetProgress = (float) 580 (0.1 + progress.Event.currentItemProgress * 0.8);646 (0.1f + progress.Event.currentItemProgress * 0.8f); 581 647 else 582 648 progress.Event.CurrentTargetProgress = (float) 583 (progress.Event.currentItemProgress * 0.9 );649 (progress.Event.currentItemProgress * 0.9f); 584 650 progress.Event.timeLeft = progress.TimeLeft; 585 651 task.OnProgressChanged(progress.Event); … … 608 674 //Then clean the old file system entries 609 675 progress.Event.currentItemName = S._("Old file system entries"); 610 DateTime fsEntriesEraseStart = DateTime.Now; 676 ProgressManager fsEntriesProgress = new ProgressManager(); 677 fsEntriesProgress.Start(); 611 678 EraseOldFilesystemEntries(info.Parent, 612 679 delegate(int currentFile, int totalFiles) 613 680 { 614 progress.Event.currentItemProgress = (float)currentFile / totalFiles; 681 //Compute the progress 682 fsEntriesProgress.Total = totalFiles; 683 fsEntriesProgress.Completed = currentFile; 684 685 //Set the event parameters, then broadcast the progress event. 686 progress.Event.timeLeft = fsEntriesProgress.TimeLeft; 687 progress.Event.currentItemProgress = fsEntriesProgress.Progress; 615 688 progress.Event.CurrentTargetProgress = (float)( 616 689 0.9 + progress.Event.CurrentItemProgress / 10); 617 618 //Calculate how much time will be needed to complete the erase619 TimeSpan elapsedTime = DateTime.Now - fsEntriesEraseStart;620 if (elapsedTime > TimeSpan.Zero)621 {622 progress.Event.timeLeft = new TimeSpan(0, 0, (int)623 ((float)(totalFiles - currentFile) / currentFile *624 elapsedTime.TotalSeconds));625 }626 627 690 task.OnProgressChanged(progress.Event); 628 691 } … … 663 726 "erased because it is a hard link or a symbolic link.", 664 727 file.FullName), LogLevel.INFORMATION)); 665 else if ((file.Attributes & FileAttributes.Compressed) ||666 (file.Attributes & FileAttributes.Encrypted) ||667 (file.Attributes & FileAttributes.SparseFile) )728 else if ((file.Attributes & FileAttributes.Compressed) != 0 || 729 (file.Attributes & FileAttributes.Encrypted) != 0 || 730 (file.Attributes & FileAttributes.SparseFile) != 0) 668 731 { 669 732 task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips " + … … 915 978 /// <param name="progress">The progress manager for the current task.</param> 916 979 private void EraseFilesystemObject(Task task, Task.FilesystemObject target, 917 ProgressManager progress)980 TaskProgressManager progress) 918 981 { 919 982 //Retrieve the list of files to erase. … … 977 1040 { 978 1041 dataTotal -= lastWritten; 979 progress. DataWritten+= lastWritten;1042 progress.Completed += lastWritten; 980 1043 progress.Event.currentItemPass = currentPass; 981 1044 progress.Event.currentItemProgress = (float)
Note: See TracChangeset
for help on using the changeset viewer.
