public async Task RecordSessionAsync(Http.HttpRequest request, Http.HttpResponse response, TimeSpan duration) { int sessionId = -1; lock(this) { sessionId = nextSessionNumber++; } // Write client request var requestPart = this.outputPackage.CreatePart(UriForPart(sessionId, 'c'), "text/plain"); using (var requestStream = requestPart.GetStream(System.IO.FileMode.Create)) { await request.WriteToStreamAsync(requestStream); } var responsePart = this.outputPackage.CreatePart(UriForPart(sessionId, 's'), "text/plain"); using (var responseStream = responsePart.GetStream(System.IO.FileMode.Create)) { await response.WriteToStreamAsync(responseStream); } var metadataPart = this.outputPackage.CreatePart(UriForPart(sessionId, 'm'), "application/xml"); var metadata = CreateMetadataForSession(sessionId, request.StartTime, duration); using (var metadataStream = metadataPart.GetStream(System.IO.FileMode.Create)) { await metadata.WriteToStreamAsync(metadataStream); } }