Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaquay committed Jun 18, 2018
1 parent 7cafe81 commit 107b9b7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 82 deletions.
31 changes: 10 additions & 21 deletions src/mtdel/DeleteProgressMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,20 @@
namespace mtdel {
public class DeleteProgressMonitor : ProgressMonitor {
protected override void DisplayStatus(Statistics statistics) {
var elapsed = statistics.ElapsedTime;
var totalSeconds = elapsed.TotalSeconds;

var directoriesDeletedText = string.Format("{0:n0}",
statistics.DirectoryDeletedCount);

var filesDeletedText = string.Format("{0:n0}",
statistics.FileDeletedCount + statistics.SymlinkDeletedCount);

var diskSizeText = string.Format("({0:n0} MB)",
statistics.FileDeletedTotalSize / 1024 / 1024);

var deletedPerSecondText = string.Format("{0:n0}",
(statistics.FileDeletedCount + statistics.SymlinkDeletedCount) / totalSeconds);

var elapsedText = string.Format("{0}",
FormatHelpers.FormatElapsedTime(elapsed));

var elapsedTimeText = string.Format("{0}", FormatHelpers.FormatElapsedTime(statistics.ElapsedTime));
var cpuTimeText = string.Format("{0}", FormatHelpers.FormatElapsedTime(statistics.TotalProcessorTime));
var directoriesDeletedText = string.Format("{0:n0}", statistics.DirectoryDeletedCount);
var filesDeletedText = string.Format("{0:n0}", statistics.FileDeletedCount + statistics.SymlinkDeletedCount);
var filesDeletedSizeText = string.Format("({0:n0} MB)", statistics.FileDeletedTotalSize / 1024 / 1024);
var entriesPerSecondText = string.Format("{0:n0}", (statistics.FileDeletedCount + statistics.SymlinkDeletedCount) / statistics.ElapsedTime.TotalSeconds);
var errorsText = string.Format("{0:n0}", statistics.Errors.Count);

var fields = new[] {
new PrinterEntry("Elapsed time", elapsedText, valueAlign:Align.Right),
new PrinterEntry("Elapsed time", elapsedTimeText, valueAlign:Align.Right),
new PrinterEntry("CPU time", cpuTimeText, valueAlign:Align.Right),
new PrinterEntry("# of directories deleted", directoriesDeletedText, shortName: "directories", valueAlign:Align.Right),
new PrinterEntry("# of files deleted", filesDeletedText, shortName: "files", valueAlign:Align.Right, extraValue: diskSizeText),
new PrinterEntry("# of files deleted/sec", deletedPerSecondText, shortName: "files/sec", valueAlign:Align.Right),
new PrinterEntry("# of files deleted", filesDeletedText, shortName: "files", valueAlign:Align.Right, extraValue: filesDeletedSizeText),
new PrinterEntry("# of files deleted/sec", entriesPerSecondText, shortName: "files/sec", valueAlign:Align.Right),
new PrinterEntry("# of errors", errorsText, shortName:"errors", valueAlign:Align.Right),
};
Print(fields);
Expand Down
32 changes: 10 additions & 22 deletions src/mtinfo/InfoProgressMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,26 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;
using mtsuite.shared;
using mtsuite.shared.Utils;

namespace mtinfo {
public class InfoProgressMonitor : ProgressMonitor {
protected override void DisplayStatus(Statistics statistics) {
var elapsed = statistics.ElapsedTime;
var totalSeconds = statistics.ElapsedTime.TotalSeconds;

var directoriesText = string.Format("{0:n0}",
statistics.DirectoryTraversedCount);

var filesText = string.Format("{0:n0}",
statistics.EntryEnumeratedCount);

var diskSizeText = string.Format("({0:n0} MB)",
statistics.FileEnumeratedTotalSize / 1024 / 1024);

var statsText = string.Format("{0:n0}",
statistics.EntryEnumeratedCount / totalSeconds);

var elapsedText = string.Format("{0}",
FormatHelpers.FormatElapsedTime(elapsed));

var elapsedTimeText = string.Format("{0}", FormatHelpers.FormatElapsedTime(statistics.ElapsedTime));
var cpuTimeText = string.Format("{0}", FormatHelpers.FormatElapsedTime(statistics.TotalProcessorTime));
var directoriesText = string.Format("{0:n0}", statistics.DirectoryTraversedCount);
var filesText = string.Format("{0:n0}", statistics.EntryEnumeratedCount);
var filesExtraText = string.Format("({0:n0} MB)", statistics.FileEnumeratedTotalSize / 1024 / 1024);
var entriesPerSecondText = string.Format("{0:n0}", statistics.EntryEnumeratedCount / statistics.ElapsedTime.TotalSeconds);
var errorsText = string.Format("{0:n0}", statistics.Errors.Count);

var fields = new[] {
new PrinterEntry("Elapsed time", elapsedText, valueAlign: Align.Right),
new PrinterEntry("Elapsed time", elapsedTimeText, valueAlign: Align.Right),
new PrinterEntry("CPU time", cpuTimeText, valueAlign:Align.Right),
new PrinterEntry("# of directories", directoriesText, shortName: "directories", valueAlign: Align.Right),
new PrinterEntry("# of files", filesText, shortName: "files", valueAlign: Align.Right, extraValue: diskSizeText),
new PrinterEntry("# of files/sec", statsText, shortName:"files/sec", valueAlign: Align.Right),
new PrinterEntry("# of files", filesText, shortName: "files", valueAlign: Align.Right, extraValue: filesExtraText),
new PrinterEntry("# of files/sec", entriesPerSecondText, shortName:"files/sec", valueAlign: Align.Right),
new PrinterEntry("# of errors", errorsText, shortName:"errors", valueAlign: Align.Right),
};
Print(fields);
Expand Down
3 changes: 3 additions & 0 deletions src/mtsuite.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/AutopopupEnabled/AutopopupEnabled/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/CSharpCompletingCharacters/CompleteOnSpace/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/ParenthesesInsertType/@EntryValue">None</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertClosureToMethodGroup/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToLambdaExpression/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ACCESSOR_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String>
Expand Down
59 changes: 21 additions & 38 deletions src/shared/CopyProgressMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,32 @@ protected override void DisplayStatus(Statistics statistics) {
statistics.DirectoryDeletedCount + statistics.FileDeletedCount + statistics.SymlinkDeletedCount +
statistics.FileSkippedCount;

var directoriesText = string.Format("{0:n0}", statistics.DirectoryEnumeratedCount);

var filesText = string.Format("{0:n0}", statistics.EntryEnumeratedCount);

var diskSizeText = string.Format("({0:n0} MB)", statistics.FileEnumeratedTotalSize / 1024 / 1024);

var entriesPerSecondText = string.Format("{0:n0}", totalEntriesCount / totalSeconds);

var elapsedTimeText = string.Format("{0}", FormatHelpers.FormatElapsedTime(elapsed));

var cpuTimeText = string.Format("{0}", FormatHelpers.FormatElapsedTime(statistics.TotalProcessorTime));
var sourceDirectoriesText = string.Format("{0:n0}", statistics.DirectoryEnumeratedCount);
var sourceFilesText = string.Format("{0:n0}", statistics.EntryEnumeratedCount);
var sourceFilesExtraText = string.Format("({0:n0} MB)", statistics.FileEnumeratedTotalSize / 1024 / 1024);
var filesCopiedText = string.Format("{0:n0}", statistics.FileCopiedCount + statistics.SymlinkCopiedCount);
var filesCopiedExtraText = string.Format("({0:n0} MB)", fileCopiedTotalSizeMb);
var filesSkippedText = string.Format("{0:n0}", statistics.FileSkippedCount + statistics.SymlinkSkippedCount);
var filesSkippedExtraText = string.Format("({0:n0} MB)", fileSkippedTotalSizeMb);
var directoriesDeletedText = string.Format("{0:n0}", statistics.DirectoryDeletedCount);
var filesDeletedText = string.Format("{0:n0}", statistics.FileDeletedCount + statistics.SymlinkDeletedCount);
var filesDeletedExtraText = string.Format("({0:n0} MB)", statistics.FileDeletedTotalSize / 1024 / 1024);
var entriesPerSecondText = string.Format("{0:n0}", totalEntriesCount / totalSeconds);
var errorsText = string.Format("{0:n0}", statistics.Errors.Count);

var copyText = string.Format("{0:n0}", statistics.FileCopiedCount + statistics.SymlinkCopiedCount);

var copyExtraText = string.Format("({0:n0} MB)", fileCopiedTotalSizeMb);

var deleteFilesText = string.Format("{0:n0}", statistics.FileDeletedCount + statistics.SymlinkDeletedCount);

var deleteExtraText = string.Format("({0:n0} MB)",
statistics.FileDeletedTotalSize / 1024 / 1024);

var deleteDirectoriesText = string.Format(
"{0:n0}",
statistics.DirectoryDeletedCount);

var skippedFilesText = string.Format(
"{0:n0}",
statistics.FileSkippedCount + statistics.SymlinkSkippedCount);

var skippedExtraText = string.Format(
"({0:n0} MB)",
fileSkippedTotalSizeMb);

var fields = new[] {
new PrinterEntry("Elapsed time", elapsedTimeText),
new PrinterEntry("Source", null),
new PrinterEntry("# of directories", directoriesText, indent: 2, shortName: "directories", valueAlign: Align.Right),
new PrinterEntry("# of files", filesText, indent: 2, shortName: "files", valueAlign: Align.Right, extraValue: diskSizeText),
new PrinterEntry("Destination", null),
new PrinterEntry("# of files copied", copyText, indent: 2, shortName: "copied", valueAlign: Align.Right, extraValue: copyExtraText),
new PrinterEntry("# of files skipped", skippedFilesText, indent: 2, shortName: "skipped", valueAlign: Align.Right, extraValue: skippedExtraText),
new PrinterEntry("# of extra directories deleted", deleteDirectoriesText, indent: 2, shortName: "directories deleted", valueAlign: Align.Right),
new PrinterEntry("# of extra files deleted", deleteFilesText, indent: 2, shortName: "files deleted", valueAlign: Align.Right, extraValue: deleteExtraText),
new PrinterEntry("CPU time", cpuTimeText, valueAlign:Align.Right),
new PrinterEntry("Source"),
new PrinterEntry("# of directories", sourceDirectoriesText, indent: 2, shortName: "directories", valueAlign: Align.Right),
new PrinterEntry("# of files", sourceFilesText, indent: 2, shortName: "files", valueAlign: Align.Right, extraValue: sourceFilesExtraText),
new PrinterEntry("Destination"),
new PrinterEntry("# of files copied", filesCopiedText, indent: 2, shortName: "copied", valueAlign: Align.Right, extraValue: filesCopiedExtraText),
new PrinterEntry("# of files skipped", filesSkippedText, indent: 2, shortName: "skipped", valueAlign: Align.Right, extraValue: filesSkippedExtraText),
new PrinterEntry("# of extra directories deleted", directoriesDeletedText, indent: 2, shortName: "directories deleted", valueAlign: Align.Right),
new PrinterEntry("# of extra files deleted", filesDeletedText, indent: 2, shortName: "files deleted", valueAlign: Align.Right, extraValue: filesDeletedExtraText),
new PrinterEntry("# of entries processed/sec", entriesPerSecondText, shortName: "files/sec", valueAlign: Align.Right),
new PrinterEntry("# of errors", errorsText, shortName: "errors", valueAlign: Align.Right),
};
Expand Down
2 changes: 1 addition & 1 deletion src/shared/PrinterEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace mtsuite.shared {
public class PrinterEntry {
public PrinterEntry(string displayName, string value, Align valueAlign = Align.Left, string valueUnit = null,
public PrinterEntry(string displayName, string value = null, Align valueAlign = Align.Left, string valueUnit = null,
string shortName = null, int indent = 0, string extraValue = null) {
DisplayName = displayName;
Value = value;
Expand Down

0 comments on commit 107b9b7

Please sign in to comment.