public void ShowRecupFilesDetails(List <RecupFile> recupFiles) { var tableContent = new List <List <string> >(); tableContent.Add(new List <string>() { "Extension", "Count", "Total size" }); tableContent.Add(null); var groups = recupFiles.GroupBy(t => t.Extension).OrderByDescending(t => t.Sum(z => z.Size)); foreach (var group in groups) { tableContent.Add(new List <string>() { group.Key, group.Count().ToString(), ValuesToStringHelper.BytesToString(group.Sum(t => t.Size)) }); } tableContent.Add(null); tableContent.Add(new List <string>() { "Total:", recupFiles.Count.ToString(), ValuesToStringHelper.BytesToString(recupFiles.Sum(t => t.Size)) }); var str = TableToTextPrinter.TableToText(tableContent); Console.WriteLine(str); }
public void ConvertsSecondsToHours() { //Arrange //Act var result = ValuesToStringHelper.SecondsToString(3800L).Replace('.', ','); //Assert Assert.Equal("1,1 Hours", result); }
public void ConvertsBytesToTb() { //Arrange //Act var result = ValuesToStringHelper.BytesToString(12345678000000L).Replace('.', ','); //Assert Assert.Equal("11,2TB", result); }
public void ConvertsSecondsToHoursNLCulture() { //Arrange //Act var result = ValuesToStringHelper.SecondsToString(3800L, CultureInfo.GetCultureInfo("nl-nl")); //Assert Assert.Equal("1,1 Hours", result); }
public void ConvertsBytesToKbWithNLCulture() { //Arrange //Act var result = ValuesToStringHelper.BytesToString(1155L, CultureInfo.GetCultureInfo("nl-nl")); //Assert Assert.Equal("1,1KB", result); }
public void ConvertsBytesToKbWithInvariantCulture() { //Arrange //Act var result = ValuesToStringHelper.BytesToString(1155L, CultureInfo.InvariantCulture); //Assert Assert.Equal("1.1KB", result); }
public void ConvertsBytesToKb() { //Arrange //Act var result = ValuesToStringHelper.BytesToString(1024L).Replace('.', ','); //Assert Assert.Equal("1KB", result); }
public void ConvertsALotOfBytesToEB() { //Arrange //Act var result = ValuesToStringHelper.BytesToString(long.MaxValue - 1).Replace('.', ','); //Assert Assert.Equal("8EB", result); }
public void ConvertMaxOfSeconds() { //Arrange //Act var result = ValuesToStringHelper.SecondsToString(long.MaxValue).Replace('.', ','); //Assert Assert.Equal("2562047788015215,5 Hours", result); }
public void ConvertALotOfSeconds() { //Arrange //Act var result = ValuesToStringHelper.SecondsToString(1234567890123L).Replace('.', ','); //Assert Assert.Equal("342935525 Hours", result); }
public void Converts0SecondsToSeconds() { //Arrange //Act var result = ValuesToStringHelper.SecondsToString(0L).Replace('.', ','); //Assert Assert.Equal("0 Seconds", result); }
public void ConvertsSecondsToMinutes() { //Arrange //Act var result = ValuesToStringHelper.SecondsToString(120L).Replace('.', ','); //Assert Assert.Equal("2 Minutes", result); }
public void Converts0BytesToB() { //Arrange //Act var result = ValuesToStringHelper.BytesToString(0L).Replace('.', ','); //Assert Assert.Equal("0B", result); }
public void ConvertsSecondsToHoursInvariantCulture() { //Arrange //Act var result = ValuesToStringHelper.SecondsToString(3800L, CultureInfo.InvariantCulture); //Assert Assert.Equal("1.1 Hours", result); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(string.Empty); } var ofr = (OptimizableFileUI)value; return(ValuesToStringHelper.BytesToString(ofr.OriginalSize - ofr.OptimizedSize)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(string.Empty); } var ofr = (ObservableCollection <OptimizableFileUI>)value; var totalOptimizedSize = ofr.Sum(t => t.OriginalSize); return(ValuesToStringHelper.BytesToString(totalOptimizedSize)); }
public List <RecupFile> FindFiles() { Console.WriteLine($"Handling root directory: {RootRecupDir}"); var recupDirs = GetRecupDirs(RootRecupDir).ToList(); var foundRecupFiles = new List <RecupFile>(); var lastNumber = recupDirs.LastOrDefault()?.Number; int totCount = 0; long totSize = 0; foreach (var recupDir in recupDirs) { var toPrint = $"Processing {recupDir.RecupDirName} / {lastNumber}"; Console.Write(toPrint); int count = 0; long size = 0; foreach (var file in Directory.GetFiles(recupDir.RecupDirPath)) { var recupFile = new RecupFile(RootRecupDir, file); foundRecupFiles.Add(recupFile); count++; size += recupFile.Size; } var padding = "".PadRight(Math.Max(1, 40 - toPrint.Length)); var toPrint2 = $"{padding}(Count: {count}, Size: {ValuesToStringHelper.BytesToString(size)})"; Console.Write(toPrint2); totCount += count; totSize += size; var padding2 = "".PadRight(Math.Max(1, 72 - (toPrint2.Length + toPrint.Length))); Console.WriteLine($"{padding2}(Total count: {totCount}, Total size: {ValuesToStringHelper.BytesToString(totSize)})"); } return(foundRecupFiles); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return(ValuesToStringHelper.BytesToString((long)value)); }
public static void GoFix(List <Block <int> > data) { var w = Stopwatch.StartNew(); //find missing parity block var missingBlocks = data.Where(t => t.Data == null); //find data valid blocks var validBlocks = data.Where(t => t.Data != null).ToList(); if (missingBlocks.Count() != 1) { throw new ArgumentException("Too much parity data is missing"); } var missingBlock = missingBlocks.Single(); var maxLength = validBlocks.Max(t => t.Data.Length); var newParityData = new int[maxLength]; for (int i = 0; i < maxLength; i++) { int thisData = validBlocks[0].Data[i]; for (int y = 1; y < validBlocks.Count; y++) { thisData = thisData ^ validBlocks[y].Data[i]; } newParityData[i] = thisData; } missingBlock.Data = newParityData; w.Stop(); Console.WriteLine($"Time taken for Raid 5 repair:{w.Elapsed} Mb per second: {ValuesToStringHelper.BytesToString((long)(maxLength / w.Elapsed.TotalSeconds) * sizeof(int))}"); }
public static string GetCommitDescriptionForPullRequest(string clonedRepoPath, string branchName, IEnumerable <OptimizableFile> optimizedFileResults, string commitDate) { var templateText = Templates.CommitInPullRequestMarkdownTemplate.Trim(); templateText = templateText.Replace("{CommitDate}", commitDate); templateText = templateText.Replace("{SupportedFileExtensions}", string.Join(" ", ConstantsFileExtensions.AllValidExtensions)); templateText = templateText.Replace("{Version}", Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion.ToString()); var totalBytesBefore = optimizedFileResults.Sum(t => t.OriginalSize); var totalBytesSaved = optimizedFileResults.Where(t => t.OptimizationResult == OptimizationResult.Success).Sum(t => t.OriginalSize - t.OptimizedSize); var totalBytesAfter = totalBytesBefore - totalBytesSaved; var percentageRemaining = Math.Round(totalBytesAfter / (double)totalBytesBefore * 100.0, 2); var timeSpan = TimeSpan.Zero; foreach (var duration in optimizedFileResults.Select(t => t.Duration)) { timeSpan += duration; } templateText = templateText.Replace("{OptimizableFileCount}", optimizedFileResults.Count().ToString()); templateText = templateText.Replace("{FilesOptimizedSuccessfully}", optimizedFileResults.Count(t => t.OptimizationResult == OptimizationResult.Success).ToString()); templateText = templateText.Replace("{FilesAlreadyOptimized}", optimizedFileResults.Count(t => t.OptimizationResult == OptimizationResult.Skipped).ToString()); templateText = templateText.Replace("{FilesFailedOptimization}", optimizedFileResults.Count(t => t.OptimizationResult == OptimizationResult.Failed).ToString()); templateText = templateText.Replace("{TotalBytesBefore}", ValuesToStringHelper.BytesToString(totalBytesBefore)); templateText = templateText.Replace("{TotalBytesAfter}", ValuesToStringHelper.BytesToString(totalBytesAfter)); templateText = templateText.Replace("{PercentageRemaining}", $"{percentageRemaining}%"); templateText = templateText.Replace("{TotalBytesSaved}", ValuesToStringHelper.BytesToString(totalBytesSaved)); templateText = templateText.Replace("{OptimizationDuration}", ValuesToStringHelper.SecondsToString((long)timeSpan.TotalSeconds)); var optimizedFilesTable = new StringBuilder(); optimizedFilesTable.AppendLine(templateText); optimizedFilesTable.AppendLine(); optimizedFilesTable.AppendLine("FileName | Original Size | Optimized Size | Bytes Saved | Duration | Status"); optimizedFilesTable.AppendLine("-- | -- | -- | -- | -- | --"); var filesToPrint = optimizedFileResults //Don't list items that where skipped or did succeed but did not get optimized anything .Where(t => (t.OptimizationResult == OptimizationResult.Success && t.OriginalSize > t.OptimizedSize) || t.OptimizationResult == OptimizationResult.Failed) .OrderByDescending(t => t.OptimizationResult == OptimizationResult.Failed) //This ensures the Failed items come first .ThenByDescending(t => t.OriginalSize - t.OptimizedSize) .ToList(); for (int i = 0; i < filesToPrint.Count; i++) { var fileResult = filesToPrint[i]; //Reduce length of filename string fileName = Path.GetFileName(fileResult.Path); var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName); if (fileNameWithoutExtension.Length > 20) { var fileNameWithoutExtensionShortened = fileNameWithoutExtension.Substring(0, Math.Min(fileNameWithoutExtension.Length, 20)); var extension = Path.GetExtension(fileName); fileName = $"{fileNameWithoutExtensionShortened}..{extension}"; } var relativeGitPath = RelativeGitPathHelper.GetRelativeGitPath(clonedRepoPath, fileResult.Path, branchName); if (relativeGitPath != null) { fileName = $"[{fileName}]({HttpUtility.UrlPathEncode(relativeGitPath)})"; } var originalSize = ValuesToStringHelper.BytesToString(fileResult.OriginalSize); var optimizedSize = ValuesToStringHelper.BytesToString(fileResult.OptimizedSize); var bytesSaved = ValuesToStringHelper.BytesToString(fileResult.OriginalSize - fileResult.OptimizedSize); var newLine = $"{fileName} | {originalSize} | {optimizedSize} | {bytesSaved} | {ValuesToStringHelper.SecondsToString((long)fileResult.Duration.TotalSeconds)} | {fileResult.OptimizationResult}{Environment.NewLine}"; var truncateMessage = ""; if (i < filesToPrint.Count - 1) { //Not the last item truncateMessage = $"{Environment.NewLine}Remaining {filesToPrint.Count - i} items got truncated."; } if (optimizedFilesTable.Length + newLine.Length + truncateMessage.Length > Constants.MaxLengthPullRequestDescriptionAndComment) { optimizedFilesTable.Append(truncateMessage); return(optimizedFilesTable.ToString()); } else { optimizedFilesTable.Append(newLine); } } return(optimizedFilesTable.ToString()); }