private async Task AddToQueueAsync(Models.GatewayServiceRequest.Content requestContent) { Models.LogMessage exceptionMsg = null; try { var serializedContent = JsonConvert.SerializeObject(requestContent); var queueItem = new Models.GatewayQueueItem { ID = Guid.NewGuid(), JsonSerializedRequestContent = serializedContent, QueuedDateTime = DateTime.Now }; try { await _queueItemRepository.InsertAsync(queueItem); } catch (Exception ex) { MvxTrace.Error("\"{0}\" in {1}.{2}\n{3}", ex.Message, "GatewayQueueItemRepository", "InsertAsync", ex.StackTrace); throw; } // Always attempt to sync with the MWF Mobile Gateway service whenever items are added to the queue (providing the GatewayQueueTimerService has been started) await UploadQueueAsync(); } catch (Exception ex) { exceptionMsg = _loggingService.GetExceptionLogMessage(ex); } if (exceptionMsg != null) { await _loggingService.LogEventAsync(exceptionMsg); } }
public async Task UploadQueueAsync() { Models.LogMessage exceptionMsg = null; try { await SubmitQueueAsync(); await _loggingService.UploadLoggedEventsAsync(); } catch (Exception ex) { exceptionMsg = _loggingService.GetExceptionLogMessage(ex); } if (exceptionMsg != null) { await _loggingService.LogEventAsync(exceptionMsg); } }
private async Task SubmitQueueAsync() { Mvx.Trace("Submit Queue"); if (_isSubmitting) { _submitAgainOnCompletion = true; return; } _isSubmitting = true; Models.LogMessage exceptionMsg = null; try { if (!_reachability.IsConnected()) { return; } IEnumerable <Models.GatewayQueueItem> queuedItems = await _queueItemRepository.GetAllInQueueOrderAsync(); if (queuedItems != null) { foreach (var queuedItem in queuedItems) { var submitted = true; await this.ServiceCallAsync(queuedItem.JsonSerializedRequestContent); await _queueItemRepository.DeleteAsync(queuedItem); //TODO: should we attempt remaining items if one fails or bail out at this point? if (!submitted) { break; } } } } catch (Exception ex) { exceptionMsg = _loggingService.GetExceptionLogMessage(ex); } finally { _isSubmitting = false; _timer.Reset(); } if (exceptionMsg != null) { await _loggingService.LogEventAsync(exceptionMsg); } if (_submitAgainOnCompletion) { _submitAgainOnCompletion = false; await SubmitQueueAsync(); } }
public Task LogEventAsync(Models.LogMessage exceptionLogMessage) { return(this.InsertLogMessage(exceptionLogMessage)); }