private async Task <DumpArtifact> AddDumpArtifactToDbAsync(DumplingDb dumplingDb, string dumpId, string localPath, string hash, CancellationToken cancelToken) { using (var opTracker = new TrackedOperation("AddDumpArtifactToDbAsync")) { //if the specified dumpId is not valid throw an exception if (await dumplingDb.Dumps.FindAsync(cancelToken, dumpId) == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The specified dumpling id is invalid.")); } var dumpArtifact = new DumpArtifact() { DumpId = dumpId, LocalPath = localPath, DebugCritical = true, ExecutableImage = false, Hash = hash }; dumplingDb.DumpArtifacts.AddOrUpdate(dumpArtifact); await dumplingDb.SaveChangesAsync(cancelToken); return(dumpArtifact); } }
private async Task AddLoadedModulesAsync() { try { IList <DumpArtifact> loadedModules; switch (this.Format) { case "elfcore": loadedModules = ReadELFCoreLoadedModules(DumpId); break; default: loadedModules = new DumpArtifact[] { }; break; } foreach (var dumpArt in loadedModules) { _dumplingDb.DumpArtifacts.AddOrUpdate(dumpArt); await _dumplingDb.SaveChangesAsync(); } } catch (Exception e) when(Telemetry.TrackExceptionFilter(e)) { } }
private async Task DownloadArtifactToArchiveAsync(DumpArtifact dumpArtifact, ZipArchive archive, SemaphoreSlim archiveLock, CancellationToken cancelToken) { if (!cancelToken.IsCancellationRequested) { var blob = DumplingStorageClient.BlobClient.GetBlobReferenceFromServer(new Uri(dumpArtifact.Artifact.Url)); //download the compressed dump artifact to a temp file using (var tempStream = CreateTempFile()) { using (var compStream = CreateTempFile()) { await blob.DownloadToStreamAsync(compStream, cancelToken); compStream.Position = 0; using (var gunzipStream = new GZipStream(compStream, CompressionMode.Decompress, false)) { await gunzipStream.CopyToAsync(tempStream); } await tempStream.FlushAsync(); } tempStream.Position = 0; await archiveLock.WaitAsync(cancelToken); if (!cancelToken.IsCancellationRequested) { try { var entry = archive.CreateEntry(FixupLocalPath(dumpArtifact.LocalPath)); using (var entryStream = entry.Open()) { await tempStream.CopyToAsync(entryStream); await entryStream.FlushAsync(); } } finally { archiveLock.Release(); } } } } }
protected virtual async Task <Artifact> CreateArtifactAsync() { FileName = Path.GetFileName(_path).ToLowerInvariant(); CompressedSize = new FileInfo(_path).Length; var artifact = new Artifact { Hash = ExpectedHash, FileName = FileName, Format = ArtifactFormat.Unknown, CompressedSize = CompressedSize, UploadTime = DateTime.UtcNow }; bool newArtifact = await _dumplingDb.TryAddAsync(artifact) == artifact; DumpArtifact dumpArtifact = null; if (DumpId != null) { dumpArtifact = new DumpArtifact() { DumpId = DumpId, LocalPath = LocalPath, DebugCritical = DebugCritical }; _dumplingDb.DumpArtifacts.AddOrUpdate(dumpArtifact); } await _dumplingDb.SaveChangesAsync(); if (newArtifact) { //upload the artifact to blob storage await StoreArtifactBlobAsync(artifact); } return(newArtifact ? artifact : null); }