Ejemplo n.º 1
0
        protected async Task <IEnumerable <SynchronizeClientsResponse> > Write(string endpoint, params LoadAction[] actions)
        {
            _errors = new List <ErrorResponse>();
            var results    = new List <SynchronizeClientsResponse>();
            var htsClients = await _loader.Load(null, actions);

            foreach (var htsClient in htsClients)
            {
                SynchronizeClientsResponse result = null;

                try
                {
                    var msg = JsonConvert.SerializeObject(htsClient);
                    _messages.Add(msg);

                    var response = await _httpClient.PostAsJsonAsync(endpoint, htsClient);

                    if (response.IsSuccessStatusCode)
                    {
                        result = await response.Content.ReadAsJsonAsync <SynchronizeClientsResponse>();

                        results.Add(result);
                        _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, SyncStatus.SentSuccess);
                    }
                    else
                    {
                        try
                        {
                            result = await response.Content.ReadAsJsonAsync <SynchronizeClientsResponse>();
                        }
                        catch
                        {
                        }

                        Log.Debug(new string('_', 50));
                        Log.Debug(msg);
                        Log.Debug(new string('-', 50));

                        if (null != result)
                        {
                            _errors = result?.Errors;
                            throw new Exception($"Error processing request: {result?.ErrorMessage}");
                        }
                        else
                        {
                            response.EnsureSuccessStatusCode();
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e, $"error posting to endpint [{endpoint}] for {typeof(T).Name}");
                    _errors.Add(new ErrorResponse($"{endpoint} || {e.Message}"));
                    _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, SyncStatus.SentFail, e.Message);
                }
            }
            return(results);
        }
Ejemplo n.º 2
0
        public void should_Get_By_Code()
        {
            var clientStage = _context.ClientStages.AsNoTracking().First();

            _clientStageRepository.UpdateSyncStatus(clientStage.ClientId, SyncStatus.SentSuccess, "OK");

            var updatedClientStage = _context.ClientStages.FirstOrDefault(x => x.ClientId == clientStage.ClientId);

            Assert.NotNull(updatedClientStage);
            Assert.AreEqual(SyncStatus.SentSuccess, updatedClientStage.SyncStatus);
            Assert.AreEqual("OK", updatedClientStage.SyncStatusInfo);
            Console.WriteLine($"{updatedClientStage} | {updatedClientStage.SyncStatus}, {updatedClientStage.SyncStatusInfo}");
        }
Ejemplo n.º 3
0
 public Task Resend(IEnumerable <Guid> clientIds)
 {
     return(_clientStageRepository.UpdateSyncStatus(clientIds, SyncStatus.Staged));
 }