예제 #1
0
        private static string genralRequest(string EndpointTO, string ARGS, string transactionIDCancell = "")
        {
            if (EndPoints.debugMode)
            {
                CentralLog.LogInfo($"ENDPOINTS :: CALL {EndpointTO} with [{ARGS}]");
            }

            string url = EndpointTO;

            string parametros = "/" + ARGS;

            const string authHeaders  = "";
            const string postDataSend = "";

            if (EndPoints.debugMode)
            {
                CentralLog.LogInfo("ENDPOINTS :: JSON");
                CentralLog.LogInfo(postDataSend);
            }

            string returnStrng = "";

            try {
                string returnStr = RequestAPI.GetT(url, parametros, authHeaders);

                if (EndPoints.debugMode)
                {
                    CentralLog.LogInfo("ENDPOINT :: Return from API");
                    CentralLog.LogInfo(returnStr);
                }
                if (returnStr.Length > 0)
                {
                    var now = JsonParse.parseSWAPJSON(returnStr);


                    returnStrng = returnStr;
                }
            } catch (Exception e) {
                Dictionary <string, string> myResp = new Dictionary <string, string> ()
                {
                    { "status", "500" },
                    { "message", e.Message },
                    { "erroMessage", "imposibilitado de acessar API, tente novamente" },
                    { "erro", e.ToString(  ) }
                };

                returnStrng = JsonParse.genJson(myResp, new List <string>());

                CentralLog.LogError(e, ":: ENDPOINTS ERROR :: >> CANOT ACCESS TOKEN ::");
            }

            return(returnStrng);
        }
예제 #2
0
        public static string GetT(string url, string parametros, string authHeaders)
        {
            string responseFromServer = "";

            try
            {
                string urlPram = HttpUtility.UrlDecode(url + parametros);

                WebRequest request = WebRequest.Create(urlPram);

                request.Method = MethodFor;

                request.Timeout = LimitTimeout;


                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            responseFromServer = reader.ReadToEnd();
                        }
            }
            catch (WebException e) {
                Dictionary <string, string> ErroResponse = new Dictionary <string, string> ()
                {
                    { "message", e.Message },
                    { "Status", e.Status.ToString(  ) },
                    { "stack", new StreamReader(e.Response.GetResponseStream()).ReadToEnd() },
                    { "erro", e.ToString(  ) }
                };

                responseFromServer = JsonParse.genJson(ErroResponse, new List <string>()
                {
                });
                CentralLog.LogError(e, ":: ERROR >> CANOT ACCESS URL ::");
            }
            catch (Exception e)
            {
                Dictionary <string, string> ErroResponse = new Dictionary <string, string> ()
                {
                    { "message", e.Message },
                    { "Status", "5001" },
                    { "Erro", e.ToString(  ) }
                };

                responseFromServer = JsonParse.genJson(ErroResponse, new List <string>()
                {
                });
                CentralLog.LogError(e, ":: ERROR >> CANOT ACCESS URL ::");
            }

            return(responseFromServer);
        }
예제 #3
0
        //public static List<MensagemTable> parseJSON ( string json )
        //{
        //    return JsonConvert.DeserializeObject <List <MensagemTable>>(json,
        //        new JsonSerializerSettings() { DateFormatString = "yyyy-MM-ddThh:mm:ssZ" });
        //}

        public static dynamic parseSWAPJSON(string json)
        {
            try
            {
                return(JObject.Parse(json));
                //JsonConvert.DeserializeObject<List<JObject>>(json); //,
                //  new JsonSerializerSettings() { DateFormatString = "yyyy-MM-ddThh:mm:ssZ" });
            }
            catch (Exception e)
            {
                CentralLog.LogError(e, "Error in Parse JSON");
                return(new List <JObject> {
                });
            }
        }