Beispiel #1
0
        public async Task <HttpResult> PostLogMessageAsync(DeviceLogMessage deviceMessage)
        {
            var response = await _httpService.PostAsJsonAsync <DeviceLogMessage, HttpStatusCode>(deviceMessage, _gatewayLogMessageUrl);

            return(response);
        }
Beispiel #2
0
        public async Task UploadLoggedEventsAsync()
        {
            if (_isSubmitting)
            {
                return;
            }

            _isSubmitting = true;

            try
            {
                var events = await _loggedRepository.GetAllAsync();

                if (events != null && events.Count() > 0)
                {
                    events = events.OrderBy(e => e.LogDateTime);
                }

                if (events != null && events.Any())
                {
                    if (!_reachability.IsConnected())
                    {
                        return;
                    }

                    var deviceIdentifier = _deviceInfo.GetDeviceIdentifier();

                    foreach (var e in events)
                    {
                        int messageLength = e.Message.Length;
                        var deviceMessage = new DeviceLogMessage
                        {
                            Message          = e.Message.Substring(0, Math.Min(messageLength, MAX_MESSAGE_LENGTH)),
                            LogDateTime      = e.LogDateTime,
                            DeviceIdentifier = deviceIdentifier
                        };

                        var isException = false;

                        try
                        {
                            var response = await _gatewayService.PostLogMessageAsync(deviceMessage);

                            isException = !response.Succeeded;
                        }
                        catch
                        {
                            isException = true;
                        }

                        if (isException)
                        {
                            await this.HandleLoggingFailureAsync(e, events.ToList());
                        }

                        await _loggedRepository.DeleteAsync(e);
                    }
                }
            }
            finally
            {
                _isSubmitting = false;
            }
        }