public async Task IoManagerTestsAsync() { var file = Path.Combine(Common.GetWorkDir(), $"file1.dat"); List <string> lines = new List <string>(); for (int i = 0; i < 1000; i++) { string line = RandomString.AlphaNumeric(100); lines.Add(line); } // Single thread file operations. DigestableSafeIoManager ioman1 = new DigestableSafeIoManager(file); // Delete the file if Exist. ioman1.DeleteMe(); Assert.False(ioman1.Exists()); Assert.False(File.Exists(ioman1.DigestFilePath)); // Write the data to the file. await ioman1.WriteAllLinesAsync(lines); Assert.True(ioman1.Exists()); // Check if the digest file is created. Assert.True(File.Exists(ioman1.DigestFilePath));
public IndexStore(string workFolderPath, Network network, SmartHeaderChain smartHeaderChain) { WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true); IoHelpers.EnsureDirectoryExists(WorkFolderPath); var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat"); MatureIndexFileManager = new DigestableSafeIoManager(indexFilePath, useLastCharacterDigest: true); var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat"); ImmatureIndexFileManager = new DigestableSafeIoManager(immatureIndexFilePath, useLastCharacterDigest: true); Network = network; StartingFilter = StartingFilters.GetStartingFilter(Network); SmartHeaderChain = smartHeaderChain; }
public IndexStore(string workFolderPath, Network network, SmartHeaderChain hashChain) { WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true); IoHelpers.EnsureDirectoryExists(WorkFolderPath); var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat"); MatureIndexFileManager = new DigestableSafeIoManager(indexFilePath, digestRandomIndex: -1); var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat"); ImmatureIndexFileManager = new DigestableSafeIoManager(immatureIndexFilePath, digestRandomIndex: -1); Network = Guard.NotNull(nameof(network), network); StartingFilter = StartingFilters.GetStartingFilter(Network); SmartHeaderChain = Guard.NotNull(nameof(hashChain), hashChain); }
private async Task DeleteIfDeprecatedAsync(DigestableSafeIoManager ioManager) { string?firstLine; using (var content = ioManager.OpenText()) { firstLine = await content.ReadLineAsync().ConfigureAwait(false); } try { FilterModel.FromLine(firstLine); } catch { Logger.LogWarning("Old Index file detected. Deleting it."); MatureIndexFileManager.DeleteMe(); ImmatureIndexFileManager.DeleteMe(); Logger.LogWarning("Successfully deleted old Index file."); } }