public async Task <HttpResponseMessage> DownloadArchivedDump(string dumplingid, CancellationToken cancelToken) { using (var dumplingDb = new DumplingDb()) { var dump = await dumplingDb.Dumps.FindAsync(cancelToken, dumplingid); if (dump == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } var archiveTasks = new List <Task>(); dumplingDb.Entry(dump).Collection(d => d.Properties).Load(); var fileName = dump.DisplayName + ".zip"; var tempFile = CreateTempFile(); try { using (var zipArchive = new ZipArchive(tempFile, ZipArchiveMode.Create, true)) using (var archiveLock = new SemaphoreSlim(1, 1)) { //find all the artifacts associated with the dump foreach (var dumpArtifact in dump.DumpArtifacts.Where(da => da.Hash != null)) { await dumplingDb.Entry(dumpArtifact).Reference(d => d.Artifact).LoadAsync(cancelToken); archiveTasks.Add(DownloadArtifactToArchiveAsync(dumpArtifact, zipArchive, archiveLock, cancelToken)); } await Task.WhenAll(archiveTasks.ToArray()); await tempFile.FlushAsync(); } await tempFile.FlushAsync(); tempFile.Position = 0; HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(tempFile); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = fileName; return(result); } catch { tempFile.Dispose(); throw; } } }
public async Task <ActionResult> Index(int?days) { var queryDict = new Dictionary <string, string>(); foreach (var key in this.Request.QueryString.AllKeys) { queryDict[key] = this.Request.QueryString.Get(key); } days = days.HasValue ? days : 10; var minTime = DateTime.UtcNow.AddDays(days.Value * -1); var maxTime = DateTime.UtcNow.AddDays(1); List <Dump> loadedDumps = null; using (var dumplingDb = new DumplingDb()) { loadedDumps = dumplingDb.FindDumps(minTime, maxTime, queryDict).ToList(); foreach (var dump in loadedDumps) { dumplingDb.Entry(dump).Reference(d => d.Failure).Load(); dumplingDb.Entry(dump).Collection(d => d.Properties).Load(); } } var dumpsByFailure = loadedDumps.GroupBy(d => d.FailureHash); var failures = new List <string>(); foreach (var failure in dumpsByFailure.OrderByDescending(g => g.Count())) { failures.Add(failure.Key ?? "UNTRIAGED"); var dumps = failure.OrderByDescending(d => d.DumpTime).ToArray(); ViewData[failure.Key ?? "UNTRIAGED"] = dumps; foreach (var dump in dumps) { ViewData["dumpid." + dump.DumpId] = JsonConvert.SerializeObject(dump.GetPropertyBag()); } } ViewBag.Title = "dumpling"; ViewData["Failures"] = failures.ToArray(); return(View("Index")); }
public async Task <Dump> GetDumplingManifest(string dumplingId) { using (var op1 = new TrackedOperation("GetDumplingManifest")) { using (DumplingDb dumplingDb = new DumplingDb()) { Dump dump = null; using (var op2 = new TrackedOperation("FindDumpAsync")) { dump = await dumplingDb.Dumps.FindAsync(dumplingId); } if (dump != null) { using (var op3 = new TrackedOperation("LoadDumpArtifactsAsync")) { await dumplingDb.Entry(dump).Collection(d => d.DumpArtifacts).LoadAsync(); } } return(dump); } } }