Skip to content

Commit

Permalink
Moves to dispatch async for sending command. Adds better catching for…
Browse files Browse the repository at this point in the history
… errors on dispatch
  • Loading branch information
Alex Johnson committed May 12, 2021
1 parent be8386e commit d044c24
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions PanasonicCameraEpi/HttpCommandQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ protected override object ProcessQueue(object obj)

Debug.Console(1, client, "Dispatching request: {0}", request.Url.PathAndParams);

var response = client.Client.Dispatch(request);
using (response)
{
if (!String.IsNullOrEmpty(response.ContentString))
OnResponseReceived(response);
}
client.Client.DispatchAsync(request, OnResponseReceived);
}
catch (Exception ex)
{
Expand All @@ -64,13 +59,31 @@ protected override object ProcessQueue(object obj)
return null;
}

private void OnResponseReceived(HttpClientResponse response)
private void OnResponseReceived(HttpClientResponse response, HTTP_CALLBACK_ERROR error)
{
var handler = ResponseReceived;
if (handler == null)
return;
try
{
Debug.Console(1, this, "Panasonic camera client response code: {0}", response.Code);
if (error != HTTP_CALLBACK_ERROR.COMPLETED)
{
Debug.Console(1, this, "Panasonic camera client callback error: {0}", error);
return;
}
if (response.Code < 200 || response.Code >= 300)
{
Debug.Console(1, this, "Panasonic camera client callback http code error: {0}", response.Code);
return;
}

handler.Invoke(this, new GenericHttpClientEventArgs(response.ContentString, response.ResponseUrl, HTTP_CALLBACK_ERROR.COMPLETED));
if (ResponseReceived == null)
return;
ResponseReceived.Invoke(this, new GenericHttpClientEventArgs(response.ContentString, response.ResponseUrl, HTTP_CALLBACK_ERROR.COMPLETED));

}
catch (Exception ex)
{
Debug.Console(1, this, "Panasonic camera client callback exception: {0}", ex.Message);
}
}
}
}

0 comments on commit d044c24

Please sign in to comment.