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); } } }
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); } }
public void Increment(TrackedOperation operation) { if (!this.GetCounts.ContainsKey(operation)) { this.GetCounts.Add(operation, 1); } else { this.GetCounts[operation]++; } }
public static async Task <bool> DeleteArtifactAsync(string hash, string fileName, CancellationToken cancelToken) { using (var opTracker = new TrackedOperation("DeleteArtifactBlob", new Dictionary <string, string>() { { "Hash", hash } })) { var blob = _instance._artifactContainer.GetBlockBlobReference(hash + "/" + fileName); return(await blob.DeleteIfExistsAsync(cancelToken)); } }
public static async Task <string> StoreArtifactAsync(Stream stream, string hash, string fileName, CancellationToken cancelToken) { using (var opTracker = new TrackedOperation("StoreArtifactBlob", new Dictionary <string, string>() { { "Hash", hash } })) { var blob = _instance._artifactContainer.GetBlockBlobReference(hash + "/" + fileName); await blob.UploadFromStreamAsync(stream, cancelToken); return(blob.Uri.ToString()); } }
private async Task <Artifact> AddArtifactToDbAsync(DumplingDb dumplingDb, string hash, string localPath, CancellationToken cancelToken) { using (var opTracker = new TrackedOperation("AddArtifactToDbAsync")) { var artifact = new Artifact() { Hash = hash, FileName = Path.GetFileName(localPath), UploadTime = DateTime.UtcNow, Format = ArtifactFormat.Unknown, Uuid = null }; return(await dumplingDb.TryAddAsync(artifact, cancelToken) ? artifact : null); } }
public void Increment(TrackedOperation operation) { _count[operation] = ++_count[operation]; }
private async Task <Stream> UploadContentValidateHashAsync(HttpContent content, string expectedHash, CancellationToken cancelToken) { using (var opTracker = new TrackedOperation("UploadConentValidateHashAsync")) { string hash = null; long length = 0; using (var contentStream = await Request.Content.ReadAsStreamAsync()) { var operationMetrics = new Dictionary <string, double>() { { "FileLength", 0 } }; //we don't open the temp file in a using statement b/c we need to return to the caller Stream fileStream = CreateTempFile(); try { using (var sha1 = SHA1.Create()) { var buff = new byte[BUFF_SIZE]; int cbyte; while ((cbyte = await contentStream.ReadAsync(buff, 0, buff.Length)) > 0) { cancelToken.ThrowIfCancellationRequested(); length += cbyte; sha1.TransformBlock(buff, 0, cbyte, buff, 0); await fileStream.WriteAsync(buff, 0, cbyte); } await fileStream.FlushAsync(); sha1.TransformFinalBlock(buff, 0, 0); hash = string.Concat(sha1.Hash.Select(b => b.ToString("x2"))).ToLowerInvariant(); operationMetrics["FileLength"] = Convert.ToDouble(length); } } //if an exception was thrown while uploading delete the file and rethrow to prevent leaking the incomplete file catch (Exception) { fileStream.Dispose(); throw; } //if the hash doesn't match close the file so it deletes and throw an exception if (hash != expectedHash) { fileStream.Dispose(); throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The specified hash does not match hash of the uploaded content.")); } return(fileStream); } } }
public void Increment(TrackedOperation operation) { GetCounts[operation]++; }
public void Increment(TrackedOperation trackedOperation) { ++_count[trackedOperation]; }
public void Increment(TrackedOperation operation) { count[operation] += 1; }