/// <summary> /// Persists a /// </summary> /// <param name="data"></param> /// <returns></returns> public async Task<SeriesDownload> PersistSeriesData(SeriesData data, string urlId, DateTimeOffset requestTime) { SeriesDownload result = new SeriesDownload() { SeriesID = data.SeriesID }; //assumes series is not already in storage using (MemoryStream ms = new MemoryStream()) { //write data to memory stream as csv await WriteDataToMemoryStreamAsCsv(data, ms); if (ms.Length > 0) { // persist memory stream as blob ms.Position = 0; CloudBlockBlob blob = await WriteMemoryStreamToBlobInGuidDirectory(data, ms, csa); //persist table storage record CloudTable tbl = csa.CreateCloudTableClient().GetTableReference(DiscoveryStorageTableNames.SeriesDownloads); await tbl.ExecuteAsync(TableOperation.InsertOrReplace( //optimistic concurrency new DataExportRequest(requestTime, data.myMetadata.StartDate.ToUniversalTime(), data.myMetadata.EndDate.ToUniversalTime(), blob.Uri.AbsoluteUri, data.SeriesID, data.myMetadata.ServURL) )); //fill result object uri result.Uri = blob.Uri.AbsoluteUri; } } return result; }
public async Task<MemoryStream> getCSVResultAsMemoryStream(SeriesData data) { SeriesDownload result = new SeriesDownload() { SeriesID = data.SeriesID }; //assumes series is not already in storage using (MemoryStream ms = new MemoryStream()) { //write data to memory stream as csv await WriteDataToMemoryStreamAsCsv(data, ms); if (ms.Length > 0) { // persist memory stream as blob ms.Position = 0; } return ms; } }