public void Emit(string logEntry, LogLevel level) { if (fileControllerWatched.GetSize() >= splittingFileSize) { _ = Split(); } }
public async Task DownloadFromResponseAsync(HttpResponseMessage response, string destination, IStatus status) { response.EnsureSuccessStatusCode(); var filename = response.RequestMessage.RequestUri.Segments.Last(); var fullPath = Path.Combine(destination, filename); int bufferSize = 1024 * 1024; // 1M byte[] buffer = new byte[bufferSize]; int bytesRead = 0; long totalBytesRead = 0; // don't redownload file with the same name and size if (fileController.Exists(fullPath) && fileController.GetSize(fullPath) == response.Content.Headers.ContentLength) { await statusController.InformAsync( status, $"File {fullPath} already exists and matches response size, will not be redownloading"); return; } using (var writeableStream = streamController.OpenWritable(fullPath)) using (var responseStream = await response.Content.ReadAsStreamAsync()) { while ((bytesRead = await responseStream.ReadAsync(buffer, 0, bufferSize)) > 0) { totalBytesRead += bytesRead; var contentLength = response.Content.Headers.ContentLength != null ? (long) response.Content.Headers.ContentLength : totalBytesRead; await writeableStream.WriteAsync(buffer, 0, bytesRead); await statusController.UpdateProgressAsync( status, totalBytesRead, contentLength, filename, DataUnits.Bytes); } } }
public bool VerifySize(string uri, long expectedSize) { return(fileController.GetSize(uri) == expectedSize); }