Skip to content

Commit

Permalink
Billing for render (#2622)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullah248 authored Apr 28, 2023
1 parent 821af41 commit f8ff8eb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class DefaultDicomRequestContext : IDicomRequestContext

public long BytesTranscoded { get; set; }

public long BytesRendered { get; set; }

public long ResponseSize { get; set; }

public int PartCount { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public async Task GivenStoredInstancesWithFramesJpeg_WhenRetrieveRenderedForFram
resultStream.Position = 0;
AssertStreamsEqual(resultStream, response.ResponseStream);
Assert.Equal("image/jpeg", response.ContentType);
Assert.Equal(1, _dicomRequestContextAccessor.RequestContext.PartCount);
Assert.Equal(resultStream.Length, _dicomRequestContextAccessor.RequestContext.BytesRendered);

var retrieveRenderedRequest2 = new RetrieveRenderedRequest(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid, ResourceType.Frames, 2, 75, new[] { AcceptHeaderHelpers.CreateRenderAcceptHeader() });

Expand All @@ -210,6 +212,8 @@ public async Task GivenStoredInstancesWithFramesJpeg_WhenRetrieveRenderedForFram
resultStream2.Position = 0;
AssertStreamsEqual(resultStream2, response2.ResponseStream);
Assert.Equal("image/jpeg", response.ContentType);
Assert.Equal(1, _dicomRequestContextAccessor.RequestContext.PartCount);
Assert.Equal(resultStream2.Length, _dicomRequestContextAccessor.RequestContext.BytesRendered);

copyStream.Dispose();
streamAndStoredFileForFrame2.Dispose();
Expand Down Expand Up @@ -256,6 +260,8 @@ public async Task GivenStoredInstancesWithFramesJpeg_WhenRetrieveRenderedForFram
resultStream.Position = 0;
AssertStreamsEqual(resultStream, response.ResponseStream);
Assert.Equal("image/jpeg", response.ContentType);
Assert.Equal(1, _dicomRequestContextAccessor.RequestContext.PartCount);
Assert.Equal(resultStream.Length, _dicomRequestContextAccessor.RequestContext.BytesRendered);

var retrieveRenderedRequest2 = new RetrieveRenderedRequest(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid, ResourceType.Frames, 2, 20, new[] { AcceptHeaderHelpers.CreateRenderAcceptHeader() });

Expand All @@ -273,6 +279,8 @@ public async Task GivenStoredInstancesWithFramesJpeg_WhenRetrieveRenderedForFram
resultStream2.Position = 0;
AssertStreamsEqual(resultStream2, response2.ResponseStream);
Assert.Equal("image/jpeg", response.ContentType);
Assert.Equal(1, _dicomRequestContextAccessor.RequestContext.PartCount);
Assert.Equal(resultStream2.Length, _dicomRequestContextAccessor.RequestContext.BytesRendered);

copyStream.Dispose();
streamAndStoredFileForFrame2.Dispose();
Expand Down Expand Up @@ -314,6 +322,8 @@ public async Task GivenStoredInstancesWithFramesPNG_WhenRetrieveRenderedForFrame
resultStream.Position = 0;
AssertStreamsEqual(resultStream, response.ResponseStream);
Assert.Equal("image/png", response.ContentType);
Assert.Equal(1, _dicomRequestContextAccessor.RequestContext.PartCount);
Assert.Equal(resultStream.Length, _dicomRequestContextAccessor.RequestContext.BytesRendered);

var retrieveRenderedRequest2 = new RetrieveRenderedRequest(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid, ResourceType.Frames, 2, 75, new[] { AcceptHeaderHelpers.CreateRenderAcceptHeader(mediaType: KnownContentTypes.ImagePng) });

Expand All @@ -330,6 +340,8 @@ public async Task GivenStoredInstancesWithFramesPNG_WhenRetrieveRenderedForFrame
resultStream2.Position = 0;
AssertStreamsEqual(resultStream2, response2.ResponseStream);
Assert.Equal("image/png", response.ContentType);
Assert.Equal(1, _dicomRequestContextAccessor.RequestContext.PartCount);
Assert.Equal(resultStream2.Length, _dicomRequestContextAccessor.RequestContext.BytesRendered);

copyStream.Dispose();
streamAndStoredFileForFrame2.Dispose();
Expand Down Expand Up @@ -369,6 +381,8 @@ public async Task GivenStoredInstances_WhenRetrieveRenderedWithoutSpecifyingAcce
resultStream.Position = 0;
AssertStreamsEqual(resultStream, response.ResponseStream);
Assert.Equal("image/jpeg", response.ContentType);
Assert.Equal(1, _dicomRequestContextAccessor.RequestContext.PartCount);
Assert.Equal(resultStream.Length, _dicomRequestContextAccessor.RequestContext.BytesRendered);

response.ResponseStream.Dispose();
copyStream.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public DicomRequestContext(

public long BytesTranscoded { get; set; }

public long BytesRendered { get; set; }

public long ResponseSize { get; set; }

public int PartCount { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface IDicomRequestContext : IRequestContext

long BytesTranscoded { get; set; }

public long BytesRendered { get; set; }

int PartCount { get; set; }

PartitionEntry DataPartitionEntry { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public async Task<RetrieveRenderedResponse> RetrieveRenderedImageAsync(RetrieveR
Stopwatch sw = new Stopwatch();

int partitionKey = _dicomRequestContextAccessor.RequestContext.GetPartitionKey();
_dicomRequestContextAccessor.RequestContext.PartCount = 1;
AcceptHeader returnHeader = GetValidRenderAcceptHeader(request.AcceptHeaders);

try
Expand All @@ -96,6 +97,8 @@ public async Task<RetrieveRenderedResponse> RetrieveRenderedImageAsync(RetrieveR
sw.Stop();
_logger.LogInformation("Render from dicom to {OutputContentType}, uncompressed file size was {UncompressedFrameSize}, output frame size is {OutputFrameSize} and took {ElapsedMilliseconds} ms", outputContentType, stream.Length, resultStream.Length, sw.ElapsedMilliseconds);

_dicomRequestContextAccessor.RequestContext.BytesRendered = resultStream.Length;

return new RetrieveRenderedResponse(resultStream, resultStream.Length, outputContentType);
}

Expand Down

0 comments on commit f8ff8eb

Please sign in to comment.