Skip to content

Commit

Permalink
Make sure we can use the activity more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbob92 committed May 19, 2020
1 parent e7e0e2a commit 641f6e9
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions KlippaOCRAPI/Activities/ParseDocumentActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public class ParseDocument: AsyncCodeActivity
public OutArgument<APIResponse> APIResponse { get; set; }

private HttpClient httpClient;
private MultipartFormDataContent formData;
private FileStream fs;

public ParseDocument()
{
BasePath = "https://custom-ocr.klippa.com/api/v1";
PDFTextExtraction = PDFTextExtractionType.Fast;
httpClient = new HttpClient();
formData = new MultipartFormDataContent();
httpClient = new HttpClient
{
Timeout = TimeSpan.FromSeconds(600)
};
}

protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
Expand Down Expand Up @@ -145,23 +145,18 @@ protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResul
}
finally
{
if (httpClient != null)
{
httpClient.Dispose();
}
if (formData != null)
if (task.Result != null)
{
formData.Dispose();
}
if (fs != null)
{
fs.Dispose();
task.Result.Dispose();
}
}
}

Task<HttpResponseMessage> ExecuteAsync(CodeActivityContext context)
{
MultipartFormDataContent formData = new MultipartFormDataContent();
FileStream fs = null;

var basePath = BasePath.Get(context);
var request = new HttpRequestMessage()
{
Expand Down Expand Up @@ -225,8 +220,7 @@ Task<HttpResponseMessage> ExecuteAsync(CodeActivityContext context)
}

request.Content = formData;
request.Properties["RequestTimeout"] = TimeSpan.FromSeconds(60);
httpClient.Timeout = TimeSpan.FromSeconds(60);
request.Properties["RequestTimeout"] = TimeSpan.FromSeconds(600);

return httpClient.SendAsync(request);
}
Expand Down

0 comments on commit 641f6e9

Please sign in to comment.