public async Task <RecordResult> RecordAsync(RecordRequest request) { // scrape var resultStream = new MemoryStream(); using (var textWriter = new StreamWriter(resultStream, new UTF8Encoding(false), 4096, true)) using (var jsonWriter = new JsonTextWriter(textWriter)) { var writer = new JsonScrapeResultWriter(jsonWriter); await _scraper.RealTimeScrapeAsync(writer); } resultStream.Seek(0, SeekOrigin.Begin); // initialize storage var blobUploadRequest = new UniqueUploadRequest { ConnectionString = request.StorageConnectionString, Container = request.StorageContainer, ContentType = "application/json", PathFormat = request.BlobPathFormat, Stream = resultStream, Trace = TextWriter.Null, UploadDirect = true, EqualsAsync = async x => { var comparer = new ScrapeResultEqualityComparer(); var equals = await comparer.EqualsAsync(x.Stream, resultStream, CancellationToken.None); resultStream.Seek(0, SeekOrigin.Begin); return(equals); } }; // upload UploadResult blobUploadResult; using (resultStream) { blobUploadResult = await _uniqueClient.UploadAsync(blobUploadRequest); } // record status var statusUploadResult = await _statusRecorder.RecordStatusAsync(blobUploadResult, request); return(new RecordResult { BlobUploadResult = blobUploadResult, StatusUploadResult = statusUploadResult }); }
public async Task <RecordResult> RecordAsync(ScrapeResult scrapeResult, bool groupAmPm, RecordRequest request) { using (var resultStream = new MemoryStream()) { // convert the scrape result to a GTFS .zip file var gtfsFeed = _converter.ConvertToFeed(scrapeResult, groupAmPm); await _serializer.SerializeAsync(resultStream, gtfsFeed); resultStream.Seek(0, SeekOrigin.Begin); var uploadRequest = new UniqueUploadRequest { ConnectionString = request.StorageConnectionString, Stream = resultStream, ContentType = "application/octet-stream", PathFormat = request.BlobPathFormat, Container = request.StorageContainer, UploadDirect = true, Trace = TextWriter.Null, EqualsAsync = async x => { var comparer = new ZipArchiveEqualityComparer(); var equals = await comparer.EqualsAsync(resultStream, x.Stream, CancellationToken.None); resultStream.Seek(0, SeekOrigin.Begin); return(equals); } }; // upload the .zip file var blobUploadResult = await _uniqueClient.UploadAsync(uploadRequest); // record status var statusUploadResult = await _statusRecorder.RecordStatusAsync(blobUploadResult, request); return(new RecordResult { BlobUploadResult = blobUploadResult, StatusUploadResult = statusUploadResult }); } }