public void OnStreamClosed() { EnsureNotDisposed(); // do not allow to process twice if (isClosed) { return; } // compute hash of last part ComputeCurrentPartHash(); // trim last data file if (currentPart != null) { long lastDataFileLength = currentPart.FileStream.Position; currentPart.FileStream.SetLength(lastDataFileLength); } // dispose all DisposeCurrentPart(); // build result var sequenceInfo = new PackageSequenceInfo(sequenceBaseInfo, totalSize); packageId = new Dto.PackageHashes(version, segmentHashes, cryptoProvider, sequenceInfo); logger.LogDebug($"Closed package data files. Written {SizeFormatter.ToString(totalSize)}. Hash is {packageId.PackageId:s}."); isClosed = true; }
public void Run_HasFileLength_LengthIsWrittenToConsole() { var fileEntry = new FileEntry { FullName = "SomeFile.txt", Length = 123456789 }; string expectedLengthString = SizeFormatter.GetSizeString(fileEntry.Length); // Setup var settingsRepoMock = new Mock <ISettingsRepository>(); Dependency.RegisterInstance(settingsRepoMock.Object); var consoleAdapterMock = new Mock <IConsoleAdapter>(); Dependency.RegisterInstance(consoleAdapterMock.Object); // Test var displayController = new DisplayController(); displayController.Display(new RunSettings(), fileEntry.AsArray()); // Assert consoleAdapterMock.Verify(ca => ca.Write(expectedLengthString), Times.Once()); }
public void PrintFreeDiskSpace(long freeDiskSpace) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("Free space: "); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(SizeFormatter.Format(freeDiskSpace)); Console.WriteLine(); }
public void ConvertTest() { var target = new SizeFormatter(); const string parameter1 = "Parameter1"; const string parameter2 = "Parameter2"; var result = target.Convert(new object[] { parameter1, parameter2 }, null, null, null); var expected = $"{parameter1} {parameter2}"; Assert.AreEqual(result, expected); }
public void Allocate(string path, PackageSequenceInfo sequence, bool overwrite) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (sequence == null) { throw new ArgumentNullException(nameof(sequence)); } logger.LogInformation($"Allocating {SizeFormatter.ToString(sequence.PackageSize)} for package data in {path}"); Directory.CreateDirectory(path); // check disk space and throw error if not enough var driveInfo = new DriveInfo(Directory.GetDirectoryRoot(path)); long freeSpace = driveInfo.TotalFreeSpace; if (freeSpace < sequence.PackageSize) { throw new InvalidOperationException($"There is not enough disk space on drive {driveInfo.Name}. Free space is {SizeFormatter.ToString(freeSpace)} but required is {SizeFormatter.ToString(sequence.PackageSize)}."); } // prepare parts var sequencer = new PackagePartsSequencer(); var parts = sequencer.GetDataFilesForPackage(path, sequence).ToArray(); if (!overwrite) { // check if already exists foreach (var part in parts) { if (File.Exists(part.Path)) { throw new Exception($"File already exists: {part.Path}"); } } } // allocate foreach (var part in parts) { using (var fs = new FileStream(part.Path, overwrite ? FileMode.OpenOrCreate : FileMode.CreateNew, FileAccess.Write, FileShare.None)) { fs.SetLength(part.PartLength); } } logger.LogDebug("Allocation completed."); }
private string FormatSizeWithLabel(Int64 sizeInBytes, SizeFormatter sizeFormatter) { if (this.byteFactor == GIGABYTE_FACTOR) { return(string.Format("{0} {1}", sizeFormatter(sizeInBytes), this.GigaSizeLabel)); } else if (this.byteFactor == MEGABYTE_FACTOR) { return(string.Format("{0} {1}", sizeFormatter(sizeInBytes), this.MegaSizeLabel)); } else { return(string.Format("{0} {1}", sizeFormatter(sizeInBytes), this.KiloSizeLabel)); } }
protected override void OnTimer(TickEventArgs args, Time sinceLastTimer) { base.OnTimer(args, sinceLastTimer); Program.Logger.PrintLine("ECHO", "{5}T\t | ▼{1} ({4})\t | ▲{0} ({3})\t | {2}t/s", new object[] { SizeFormatter.GetUnitFromSize(Program.Hack.Memory.BytesOut, true), SizeFormatter.GetUnitFromSize(Program.Hack.Memory.BytesIn, true), ((int)Program.Hack.TicksPerSecond).ToString(), //(int)args.TicksPerSecond.TPS, SizeFormatter.GetUnitFromSize(Program.Hack.Memory.BytesOut - lastOut, true), SizeFormatter.GetUnitFromSize(Program.Hack.Memory.BytesIn - lastIn, true), args.TicksPerSecond.TotalTicks.ToString().PadLeft(6, ' ') }); lastIn = Program.Hack.Memory.BytesIn; lastOut = Program.Hack.Memory.BytesOut; }
/// <summary> /// Rebalances files on pool to ensure a good average across all drives. /// </summary> public void Rebalance() { var mountPoint = this; Logger($"Pool {mountPoint.Name}({mountPoint.Description})"); var drives = mountPoint.Volumes.ToArray(); var drivesWithSpaceFree = drives.ToDictionary(d => d, d => d.BytesFree); foreach (var drive in drives.OrderBy(i => i.Name)) { Logger( $@" + Drive {drive.Name} {drive.BytesUsed * 100f / drive.BytesTotal:0.#}% ({ SizeFormatter.Format(drive.BytesUsed)} used, { SizeFormatter.Format(drive.BytesFree)} free, { SizeFormatter.Format(drive.BytesTotal)} total)"); } var avgBytesFree = drives.Sum(i => drivesWithSpaceFree[i]) / (ulong)drives.Length; Logger($" * Average free {SizeFormatter.Format(avgBytesFree)}"); const ulong MIN_BYTES_DIFFERENCE_BEFORE_ACTING = 2 * 1024 * 1024UL; Logger($" * Difference per drive before balancing {SizeFormatter.Format(MIN_BYTES_DIFFERENCE_BEFORE_ACTING)}"); if (avgBytesFree < MIN_BYTES_DIFFERENCE_BEFORE_ACTING) { return; } var valueBeforeGettingDataFrom = avgBytesFree - MIN_BYTES_DIFFERENCE_BEFORE_ACTING; var valueBeforePuttingDataTo = avgBytesFree + MIN_BYTES_DIFFERENCE_BEFORE_ACTING; while (_DoRebalanceRun( drives, drivesWithSpaceFree, valueBeforeGettingDataFrom, valueBeforePuttingDataTo, avgBytesFree)) { ; } }
public void GetSizeString_SizeIs9Exabytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(9000000000000000000); Assert.AreEqual(" 9 EB", sizeString); }
public void GetSizeString_SizeIs290Bytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(290); Assert.AreEqual("290 B ", sizeString); }
public void GetSizeString_SizeIs567Petabytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(567000000000000000); Assert.AreEqual("567 PB", sizeString); }
public void GetSizeString_PassesZero_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(0); Assert.AreEqual(" 0 B ", sizeString); }
public void GetSizeString_SizeIs1Petabyte_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(1000000000000000); Assert.AreEqual(" 1 PB", sizeString); }
public void GetSizeString_SizeIs42Petabytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(42000000000000001); Assert.AreEqual(" 42 PB", sizeString); }
public void GetSizeString_SizeIs55Megabytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(55000222); Assert.AreEqual(" 55 MB", sizeString); }
public void ShouldStringify() { var formatter = new SizeFormatter(10.123); Assert.Equal("10.12 kb", formatter.ToString()); }
public void GetSizeString_SizeIs69Gigabytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(69123123123); Assert.AreEqual(" 69 GB", sizeString); }
public void GetSizeString_SizeIs23Kilobytes_ReturnsCorrectStringAndTruncatesDigits() { string sizeString = SizeFormatter.GetSizeString(23567); Assert.AreEqual(" 23 KB", sizeString); }
public void ConvertBackTest() { var target = new SizeFormatter(); var result = target.ConvertBack("Some string", null, null, null); }
public void Format_SizeIs19986MB_ReturnsNoDecimalPortion() { string sizeString = SizeFormatter.Format(9986000); sizeString.Should().Be(" 10 MB"); }
public void Format_SizeIs5200Gigabytes_ReturnsDecimal() { string sizeString = SizeFormatter.Format(5200000000000L); sizeString.Should().Be("5.2 TB"); }
public void Format_SizeIs5Bytes_Returns5B() { string sizeString = SizeFormatter.Format(5); sizeString.Should().Be(" 5 B "); }
public void ShouldMatchUnit(double size, string unit) { var formatter = new SizeFormatter(size); Assert.Equal(unit, formatter.Unit); }
public void GetSizeString_SizeIs123Kilobytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(123000); Assert.AreEqual("123 KB", sizeString); }
protected override void AfterPluginsTick(TickEventArgs args) { dbg = Program.Hack.Overlay.Renderer.Fonts[dbg]; if (Process.IsInForeground) { //Input Overlay.Menu.DrawString(Color.White, dbg, Vector2.Unit * 20f, Input.MousePos.ToString() + "\n" + Input.MouseMoveDist.ToString() + "\n" + string.Join(", ", Input.KeysDown.Select(x => x.ToString()))); //Mem var str = string.Format( "=============================\n" + "RPM: {0} calls\n" + " {1} total\n" + " {2}/s\n" + "WPM: {3} calls\n" + " {4} total\n" + " {5}/s\n" + "=============================", Memory.RPMCalls.ToString("N0"), SizeFormatter.GetUnitFromSize(Memory.BytesIn, true), SizeFormatter.GetUnitFromSize(Memory.BytesIn / args.Time.TotalTime.TotalSeconds, true), Memory.WPMCalls.ToString("N0"), SizeFormatter.GetUnitFromSize(Memory.BytesOut, true), SizeFormatter.GetUnitFromSize(Memory.BytesOut / args.Time.TotalTime.TotalSeconds, true)); var size = dbg.MeasureString(str); Overlay.Menu.DrawString(Color.White, dbg, Vector2.UnitY * (Overlay.Size.Y * 0.75f - size.Y * 0.5f), str); //Specs var lp = StateMod.LocalPlayer.Value; Color drawColor = Color.White; if (CSLocalPlayer.IsProcessable(lp) && !lp.IsDormant) { var players = StateMod.GetPlayersSet(true, false, true); Func <CSPlayer, bool> filter = null; filter = (x) => x.m_iID != lp.m_iID && x.m_hObserverTarget == lp.m_iID; if (players.Any(filter)) { var specs = players.Where(filter); if (specs.Any(x => x.m_iObserverMode == ObserverMode.Ego)) { drawColor = Color.Red; } else if (specs.Any(x => x.m_iObserverMode == ObserverMode.ThirdPerson)) { drawColor = Color.Orange; } string text = string.Join("\n", specs.Select(x => string.Format("▻ {0} ({1})", Program.Hack.StateMod.PlayerResources.Value.m_sNames[x.m_iID], x.m_iObserverMode.ToString()) ) ); Overlay.Menu.DrawString( drawColor, dbg, Vector2.UnitY * (Overlay.Size.Y / 2f), "[Specs]\n" + text); } else { Overlay.Menu.DrawString(drawColor, dbg, Vector2.UnitY * (Overlay.Size.Y / 2f), "[Specs]\n<none>"); } } else { Overlay.Menu.DrawString(drawColor, dbg, Vector2.UnitY * (Overlay.Size.Y / 2f), "[Specs]\n<not ingame>"); } } base.AfterPluginsTick(args); }
public void GetSizeString_SizeIs234Megabytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(234000000); Assert.AreEqual("234 MB", sizeString); }
public void ShouldConvertUnit(double size, double convertedSize) { var formatter = new SizeFormatter(size); Assert.Equal(convertedSize, formatter.Size); }
public override string ToString() => $"\"{Metadata.Name}\" {Id:s} ({SizeFormatter.ToString(Metadata.PackageSize)})";
public void GetSizeString_PassesNegativeSize_ThrowsArgumentException() { SizeFormatter.GetSizeString(-1); }
public void OnStreamPartChange(PackageDataStreamPart oldPart, PackageDataStreamPart newPart) { EnsureNotDisposed(); bool keepSameStream = oldPart != null && newPart != null && oldPart.Path == newPart.Path; // compute hash if (oldPart != null) { ComputeCurrentPartHash(); } if (!keepSameStream) { // close old one if (oldPart != null) { DisposeCurrentPart(); } // open new part if (newPart != null) { logger.LogDebug($"Creating new data file {Path.GetFileName(newPart.Path)}. Already wrote {SizeFormatter.ToString(totalSize)}."); currentPart = new CurrentPart { Part = newPart, FileStream = new FileStream(newPart.Path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None) }; currentPart.FileStream.SetLength(newPart.DataFileLength); } } // update current part if (newPart != null) { currentPart.Part = newPart; currentPart.FileStream.Seek(newPart.SegmentOffsetInDataFile, SeekOrigin.Begin); currentPart.HashAlgorithm = cryptoProvider.CreateHashAlgorithm(); currentPart.HashStream = new CryptoStream(currentPart.FileStream, currentPart.HashAlgorithm, CryptoStreamMode.Write, leaveOpen: true); currentPart.Part.Stream = currentPart.HashStream; } }
public void GetSizeString_SizeIs345Gigabytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(345000000000); Assert.AreEqual("345 GB", sizeString); }
public void Start(string[] arguments) { string path = "."; if (arguments?.Length > 0) { path = arguments[0]; } string fullPath = Path.GetFullPath(path); _console.WriteLine(fullPath); _console.ForegroundColor = ConsoleColor.DarkGray; _console.WriteLine(new string( '-', fullPath.Length )); _console.ForegroundColor = ConsoleColor.Gray; var fileDescriptors = _fileSystem.GetFiles(path); long totalSize = 0; if (fileDescriptors.Length == 0) { _console.WriteLine("Empty"); } else { foreach (var fileDescriptor in fileDescriptors) { var oldColor = _console.ForegroundColor; if (fileDescriptor.IsDirectory) { string trimmedFile = Path.GetFileName(fileDescriptor.FullPath); _console.ForegroundColor = ColorProvider.FolderColor; _console.Write("Folder"); _console.ForegroundColor = ConsoleColor.DarkGray; _console.Write(" | "); _console.ForegroundColor = fileDescriptor.IsHidden ? ColorProvider.HiddenColor : ColorProvider.FolderColor; _console.WriteLine(trimmedFile + "/"); } else { string trimmedFile = Path.GetFileName(fileDescriptor.FullPath); totalSize += fileDescriptor.Size; string sizeString = SizeFormatter.Format(fileDescriptor.Size); ConsoleColor extensionColor; if (fileDescriptor.IsHidden) { extensionColor = ColorProvider.HiddenColor; } else { string extension = Path.GetExtension(trimmedFile); extensionColor = ColorProvider.GetColor(extension); } _console.ForegroundColor = extensionColor; _console.Write(sizeString); _console.ForegroundColor = ConsoleColor.DarkGray; _console.Write(" | "); _console.ForegroundColor = extensionColor; _console.WriteLine(trimmedFile); } _console.ForegroundColor = oldColor; } } string totalSizeString = SizeFormatter.Format(totalSize); _console.ForegroundColor = ConsoleColor.DarkGray; _console.WriteLine("-------+-----------"); _console.ForegroundColor = ConsoleColor.Gray; _console.Write(totalSizeString); _console.ForegroundColor = ConsoleColor.DarkGray; _console.Write(" | "); _console.ForegroundColor = ConsoleColor.Gray; _console.WriteLine("Total size"); }
public void GetSizeString_SizeIs456Terabytes_ReturnsCorrectString() { string sizeString = SizeFormatter.GetSizeString(456000000000000); Assert.AreEqual("456 TB", sizeString); }