コード例 #1
0
ファイル: SyncReport.cs プロジェクト: snowdream1985/livehapi
 private SyncReport(Guid clientId, string endpoint, SyncStatus status, SynchronizeClientsResponse response,
                    string message, Exception exception, string exceptionInfo) : this(clientId, endpoint, status, response)
 {
     Message       = message;
     Exception     = exception;
     ExceptionInfo = exceptionInfo;
 }
コード例 #2
0
ファイル: SyncReport.cs プロジェクト: snowdream1985/livehapi
 private SyncReport(Guid clientId, string endpoint, SyncStatus status,
                    SynchronizeClientsResponse response) : this()
 {
     Response = response;
     Status   = status;
     ClientId = clientId;
     Endpoint = endpoint;
 }
コード例 #3
0
ファイル: ClientWriter.cs プロジェクト: moshonk/livehapi
        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);
        }
コード例 #4
0
        private async Task <SyncReport> SendMessage <T>(string endpoint, Guid clientId, T message)
        {
            SyncReport report = null;
            SynchronizeClientsResponse result = null;
            string jsonMessage = string.Empty;

            if (null == message)
            {
                return(null);
            }

            try
            {
                var response = await _restClient.Client.PostAsJsonAsync(endpoint, message);

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

                    _results.Add(result);
                    report = SyncReport.GenerateSuccess(clientId, endpoint, result);
                }
                else
                {
                    jsonMessage = JsonConvert.SerializeObject(message, Formatting.Indented);

                    try
                    {
                        result = await response.Content.ReadAsJsonAsync <SynchronizeClientsResponse>();
                    }
                    catch
                    {
                        Log.Error(new string('+', 40));
                        Log.Error(new string('+', 40));
                        Log.Error($"Unkown server Error!");
                        var error = await response.Content.ReadAsStringAsync();

                        Log.Error(error);
                        Log.Error(new string('+', 40));
                        Log.Error(new string('+', 40));
                    }

                    Log.Debug(new string('_', 50));
                    Log.Error($"{endpoint}");
                    Log.Error($"\n{jsonMessage}\n");
                    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 {nameof(IndexClientMessage)}");
                _errors.Add(new ErrorResponse($"{endpoint} || {e.Message}"));
                report = SyncReport.GenerateFail(clientId, endpoint, result, jsonMessage, e, e.Message);
            }

            return(report);
        }
コード例 #5
0
ファイル: SyncReport.cs プロジェクト: snowdream1985/livehapi
 public static SyncReport GenerateFail(Guid clientId, string endpoint, SynchronizeClientsResponse response,
                                       string message, Exception exception, string exceptionInfo)
 {
     return(new SyncReport(clientId, endpoint, SyncStatus.SentFail, response, message, exception, exceptionInfo));
 }
コード例 #6
0
ファイル: SyncReport.cs プロジェクト: snowdream1985/livehapi
 public static SyncReport GenerateSuccess(Guid clientId, string endpoint, SynchronizeClientsResponse response)
 {
     return(new SyncReport(clientId, endpoint, SyncStatus.SentSuccess, response));
 }