private JToken ReadJsonData(Endpoint endpoint, PipelineContext pipelineContext, string api)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            var endpointSettings = endpoint.GetPlugin <JsonServiceEndpointSettings>();

            JToken result = null;

            try
            {
                using (var client = new JsonRequestService().GetHttpClient(endpointSettings))
                {
                    var response = client.GetAsync(api).Result;
                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.OK:
                        result = response.Content.ReadAsAsync <JToken>().Result;
                        break;

                    default:
                        logger.Warn($"Error accessing json service: {(int)response.StatusCode}-{response.ReasonPhrase} (url={client.BaseAddress.AbsolutePath}, api={api}, scheme={endpointSettings.Scheme}, parameter={endpointSettings.Parameter})");
                        pipelineContext.CriticalError = true;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal("Error accessing json service. (exception={0}, host={1}, protocol={2}, api={3})",
                             ex.GetBaseException().Message, endpointSettings.Host, endpointSettings.Protocol, api);
                pipelineContext.CriticalError = true;
            }
            return(result);
        }
Esempio n. 2
0
        private JObject ReadJsonData(Endpoint endpoint, PipelineContext pipelineContext, string api, string identifier)
        {
            var logger           = pipelineContext.PipelineBatchContext.Logger;
            var endpointSettings = endpoint.GetPlugin <JsonServiceEndpointSettings>();

            JObject jObject = null;

            try
            {
                using (var client = new JsonRequestService().GetHttpClient(endpointSettings))
                {
                    var response = client.GetAsync(api.Replace("{0}", identifier)).Result;
                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.OK:
                        jObject = response.Content.ReadAsAsync <JObject>().Result;
                        logger.Debug($"Object loaded (Identifier={identifier})");
                        break;

                    case HttpStatusCode.NotFound:
                        logger.Info($"Object not found (Identifier={identifier})");
                        break;

                    default:
                        logger.Warn($"Error reading object information: {(int)response.StatusCode}-{response.ReasonPhrase} (Identifier={identifier})");
                        pipelineContext.CriticalError = true;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal("Error accessing json service. (exception={0}, host={1}, protocol={2}, api={3})", ex.GetBaseException().Message, endpointSettings.Host, endpointSettings.Protocol, api);
                pipelineContext.CriticalError = true;
            }
            return(jObject);
        }