Esempio n. 1
0
        public static IONAPIFile LoadIONAPI(string aPath)
        {
            IONAPIFile result = null;

            //string fileContents = File.ReadAllText(aPath);

            using (StreamReader sr = new StreamReader(aPath))
            {
                string fileContents = sr.ReadToEnd();

                if (null != fileContents && fileContents.Length > 0)
                {
                    try
                    {
                        result = JsonConvert.DeserializeObject <IONAPIFile>(fileContents);
                    }
                    catch (Exception)
                    {
                    }
                }
                sr.Close();
            }



            return(result);
        }
Esempio n. 2
0
        public string PostIMS(IONAPIFile aCredentials, IMS aIMS)
        {
            string result    = null;
            string separator = "";
            string baseAPI   = "IONSERVICES/api/ion/messaging/service/v2/message";

            string request = aCredentials.getIONAPIUrl() + separator + baseAPI;    //Uri.EscapeDataString(apiCall + query);

            result = callService(aCredentials, new Uri(request), JsonConvert.SerializeObject(aIMS));

            return(result);
        }
Esempio n. 3
0
        private string callServiceInternal(IONAPIFile aCredentials, Uri aUri, string aBody, bool aSendChunked = false)
        {
            string result = null;

            using (HttpClient client = new HttpClient {
                BaseAddress = new Uri(aUri.Scheme + "://" + aUri.Host)
            })
            {
                if (null == gHttpClient)
                {
                    gHttpClient = new HttpClient
                    {
                        BaseAddress = new Uri(aUri.Scheme + "://" + aUri.Host)
                    };
                    //client = gHttpClient;
                }
                string token = aCredentials.GetToken();

                if (false == string.IsNullOrEmpty(token))
                {
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);

                    HttpRequestMessage request = new HttpRequestMessage()
                    {
                        Method     = HttpMethod.Get,
                        RequestUri = aUri,
                        Headers    =
                        {
                            { HttpRequestHeader.Accept.ToString(), "application/json" }
                        }
                    };

                    request.Headers.TransferEncodingChunked = aSendChunked;

                    if (false == string.IsNullOrEmpty(aBody))
                    {
                        request.Method  = HttpMethod.Post;
                        request.Content = new StringContent(aBody, Encoding.UTF8, "application/json");
                    }

                    HttpResponseMessage response = client.SendAsync(request).Result;

                    if (null != response)
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            result = response.Content.ReadAsStringAsync().Result;
                        }
                        else
                        {
                            StatusCode   = response.StatusCode.ToString();
                            ErrorMessage = response.StatusCode.ToString() + " " + response.ReasonPhrase;
                        }
                    }
                    response.Dispose();
                    response = null;
                }
                client.Dispose();
            }

            return(result);
        }
Esempio n. 4
0
 protected string callService(IONAPIFile aCredentials, Uri aUri)
 {
     return(callServiceInternal(aCredentials, aUri, null));
 }
Esempio n. 5
0
 public string callService(IONAPIFile aCredentials, Uri aUri, string aBody, bool aSendChunked = true)
 {
     return(callServiceInternal(aCredentials, aUri, aBody));
 }