public async Task <AuditLog> ReadAllEvents <TDataType>(int id) where TDataType : DataEntity { using (_logger.BeginScope("{Operation} is {Action} for {DataType} with id ({id})", nameof(FileAuditWorker), "reading all events", typeof(TDataType).Name, id)) { var filename = GetFileName <TDataType>(id); if (!await FileStreamer.Exists(filename)) { return(null); } var maxAttempts = MaxAttempts <TDataType>(); _logger.LogTrace("Will try to write to {filename} {MaxAttempts} times", filename, maxAttempts >= 0 ? maxAttempts.ToString() : "until success"); var attempts = 0; while (maxAttempts == -1 || attempts < maxAttempts) { attempts++; _logger.LogTrace("Attempt number {Attempt}", attempts); if (await FileStreamer.GetLockForFile(filename)) { try { var audit = await FileStreamer.ReadDataFromStream <AuditLog>(filename); _logger.LogInformation("Read audit from disk"); return(audit); } catch (Exception exception) { _logger.LogWarning(exception, "Failed to read audit"); } }
public async Task <bool> ExistsWhenItDoesNotExist() { MockFile .Setup(x => x.Exists(Filename)) .ReturnsAsync(false); return(await FileStreamer.Exists(Filename)); }
public Task <bool> IndexExist <TDataType>(string indexName) where TDataType : DataEntity { using (_logger.BeginScope("{Operation} is {Action} {IndexName} for {DataType}", nameof(FileIndexWorker), "checking existence of", indexName, typeof(TDataType).Name)) { return(FileStreamer.Exists(GetFileName <TDataType>(indexName))); } }
public async Task <bool> ExistsWhenItDoesExist() { return(await FileStreamer.Exists(Filename)); }