private async Task SubmitEvents(List<string> rowIds, List<Amazon.MobileAnalytics.Model.Event> eventList)
#endif
{
PutEventsRequest putRequest = new PutEventsRequest();
putRequest.Events = eventList;
putRequest.ClientContext = Convert.ToBase64String(
System.Text.Encoding.UTF8.GetBytes(_clientContext.ToJsonString()));
putRequest.ClientContextEncoding = "base64";
_logger.DebugFormat("Client Context is : {0}", _clientContext.ToJsonString());
PutEventsResponse resp = null;
try
{
resp = await _mobileAnalyticsLowLevelClient.PutEventsAsync(putRequest).ConfigureAwait(false);
}
catch (AmazonMobileAnalyticsException e)
{
_logger.Error(e, "An AmazonMobileAnalyticsException occurred while sending Amazon Mobile Analytics request: error code is {0} ; error type is {1} ; request id is {2} ; status code is {3} ; error message is {4}", e.ErrorCode, e.ErrorType, e.RequestId, e.StatusCode, e.Message);
// Delete events in any of the three error codes.
if (e.StatusCode == HttpStatusCode.BadRequest &&
(e.ErrorCode.Equals("ValidationException", StringComparison.CurrentCultureIgnoreCase) ||
e.ErrorCode.Equals("SerializationException", StringComparison.CurrentCultureIgnoreCase) ||
e.ErrorCode.Equals("BadRequestException", StringComparison.CurrentCultureIgnoreCase)))
{
MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "Amazon Mobile Analytics Service returned an error.", e, eventList);
_maManager.OnRaiseErrorEvent(eventArgs);
_logger.InfoFormat("The error code is not retriable. Delete {0} events from local storage.", rowIds.Count);
_eventStore.DeleteEvent(rowIds);
}
else
{
MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "Amazon Mobile Analytics Service returned an error.", e, new List<Amazon.MobileAnalytics.Model.Event>());
_maManager.OnRaiseErrorEvent(eventArgs);
}
}
catch (AmazonServiceException e)
{
_logger.Error(e, "An AmazonServiceException occurred while sending Amazon Mobile Analytics request: error code is {0} ; error type is {1} ; request id is {2} ; status code is {3} ; error message is {4} ", e.ErrorCode, e.ErrorType, e.RequestId, e.StatusCode, e.Message);
MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "Amazon Web Service returned an error.", e, new List<Amazon.MobileAnalytics.Model.Event>());
_maManager.OnRaiseErrorEvent(eventArgs);
}
catch (Exception e)
{
_logger.Error(e, "An exception occurred while sending Amazon Mobile Analytics request.");
MobileAnalyticsErrorEventArgs eventArgs = new MobileAnalyticsErrorEventArgs(this.GetType().Name, "An exception occurred when sending request to Amazon Mobile Analytics.", e, new List<Amazon.MobileAnalytics.Model.Event>());
_maManager.OnRaiseErrorEvent(eventArgs);
}
finally
{
if (resp != null && resp.HttpStatusCode == HttpStatusCode.Accepted)
{
_logger.InfoFormat("Mobile Analytics client successfully delivered {0} events to service. Delete those events from local storage.", rowIds.Count);
_eventStore.DeleteEvent(rowIds);
}
lock (_deliveryLock)
{
_deliveryInProgress = false;
}
}
}
#endif