예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="relativeURL"></param>
        /// <param name="pComplexity"></param>
        /// <returns></returns>
        private T CallWS <T>(string relativeURL, RequestComplexity pComplexity) where T : class
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;
            try
            {
                if (_Client.GetCookieContainer().Count > 0)
                {
                    _Client.RemoveAuthenticationHeaders(CurrentApiKey);
                }
                var          jsonString = _Client.DownloadString(requestUrl, pComplexity);
                var          serializer = new DataContractJsonSerializer(typeof(T));
                MemoryStream ms         = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));
                try
                {
                    T res = serializer.ReadObject(ms) as T;
                    return(res);
                }
                finally
                {
                    ms.Close();
                }
            }
            catch (WebException e)
            {
                LogHelper.Instance.LogError(e.Message);
                return(null);
            }
        }
예제 #2
0
        private string CallWSJsonOnly(string relativeURL, RequestComplexity pComplexity)
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;

            var jsonString = _Client.DownloadString(requestUrl, pComplexity);

            return(jsonString);
        }
예제 #3
0
 /// <summary>
 /// Download Csv String
 /// </summary>
 /// <param name="pUrl"></param>
 /// <param name="pComplexity"></param>
 /// <returns></returns>
 public string DownloadCsvString(string pUrl, RequestComplexity pComplexity)
 {
     try
     {
         return(DownloadContent(pUrl, "text/csv", pComplexity));
     }
     catch (WebException webEx)
     {
         // AIP < 8 sends CSV data as application/vnd.ms-excel
         return(DownloadContent(pUrl, "application/vnd.ms-excel", pComplexity));
     }
 }
예제 #4
0
 /// <summary>
 /// Download Csv String
 /// </summary>
 /// <param name="pUrl"></param>
 /// <param name="pComplexity"></param>
 /// <returns></returns>
 public string DownloadCsvString(string pUrl, RequestComplexity pComplexity)
 {
     try
     {
         return(DownloadContent(pUrl, "text/csv", pComplexity));
     }
     catch (WebException webEx)
     {
         // AIP < 8 sends CSV data as application/vnd.ms-excel
         LogHelper.Instance.LogInfo(webEx.Message);
         return(DownloadContent(pUrl, "application/vnd.ms-excel", pComplexity));
     }
 }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="relativeURL"></param>
        /// <param name="pComplexity"></param>
        /// <param name="count">Max items to load from CSV</param>
        /// <param name="PropNames">Mapping between CSV columns and T members (optional)</param>
        /// <returns></returns>
        private IEnumerable <T> CallCsvWS <T>(string relativeURL, RequestComplexity pComplexity, int count, params string[] PropNames) where T : new()
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;

            var csvString = _Client.DownloadCsvString(requestUrl, pComplexity);

            var serializer = new CsvSerializer <T>();

            return(serializer.ReadObjects(csvString, count, PropNames));
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pEntity"></param>
        /// <param name="pComplexity"></param>
        /// <returns></returns>
        private T CallWS <T>(string relativeURL, RequestComplexity pComplexity) where T : class
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;

            var jsonString = _Client.DownloadString(requestUrl, pComplexity);

            var          serializer = new DataContractJsonSerializer(typeof(T));
            MemoryStream ms         = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));

            return(serializer.ReadObject(ms) as T);
        }
예제 #7
0
        private string DownloadContent(string pUrl, string mimeType, RequestComplexity pComplexity)
        {
            string result;

            try
            {
                Headers.Add(HttpRequestHeader.Accept, mimeType);
                var culture = Thread.CurrentThread.CurrentCulture;
                if (culture.Name.Equals("zh-CN"))
                {
                    Headers.Add(HttpRequestHeader.AcceptLanguage, "zh");
                }
                else
                {
                    Headers.Add(HttpRequestHeader.AcceptLanguage, "en");
                }

                Encoding = Encoding.UTF8;

                RequestComplexity previousComplexity = _currentComplexity;
                _currentComplexity = pComplexity;

                var requestWatch = new Stopwatch();
                requestWatch.Start();
                result = DownloadString(pUrl);
                requestWatch.Stop();

                _currentComplexity = previousComplexity;

                LogHelper.Instance.LogDebugFormat
                    ("Request URL '{0}' - Time elapsed : {1} "
                    , pUrl
                    , requestWatch.Elapsed.ToString()
                    );
            }
            catch (Exception ex)
            {
                LogHelper.Instance.LogErrorFormat
                    ("Request URL '{0}' - Error execution :  {1}"
                    , pUrl
                    , ex.Message
                    );

                throw;
            }

            return(result);
        }
예제 #8
0
        private string CallStringWS(string relativeURL, RequestComplexity pComplexity)
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;

            try
            {
                return(_Client.DownloadPlainText(requestUrl, pComplexity));
            }
            catch (WebException e)
            {
                LogHelper.Instance.LogError(e.Message);
                return(null);
            }
        }
예제 #9
0
        private string CallWSJsonOnly(string relativeURL, RequestComplexity pComplexity)
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;
            var jsonString = string.Empty;

            try
            {
                jsonString = _Client.DownloadString(requestUrl, pComplexity);
            }
            catch (WebException e)
            {
                LogHelper.Instance.LogError(e.Message);
            }

            return(jsonString);
        }
예제 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pComplexity"></param>
        /// <returns></returns>
        private int GetRequestTimeOut(RequestComplexity pComplexity)
        {
            switch (pComplexity)
            {
            case RequestComplexity.Long:
            {
                return(Settings.Default.TimoutLong);
            }

            case RequestComplexity.Soft:
            {
                return(Settings.Default.TimeoutQuick);
            }

            case RequestComplexity.Standard:
            default:
            {
                return(Settings.Default.TimeoutStandard);
            }
            }
        }
예제 #11
0
        private string CallStringWS(string relativeURL, RequestComplexity pComplexity)
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;

            try
            {
                if (_Client.GetCookieContainer().Count > 0)
                {
                    _Client.RemoveAuthenticationHeaders(CurrentApiKey);
                }
                return(_Client.DownloadPlainText(requestUrl, pComplexity));
            }
            catch (WebException e)
            {
                LogHelper.Instance.LogError(e.Message);
                return(null);
            }
        }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pComplexity"></param>
        /// <returns></returns>
        private static int GetRequestTimeOut(RequestComplexity pComplexity)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (pComplexity)
            {
            case RequestComplexity.Long:
            {
                return(Settings.Default.TimoutLong);
            }

            case RequestComplexity.Soft:
            {
                return(Settings.Default.TimeoutQuick);
            }

            //case RequestComplexity.Standard:
            default:
            {
                return(Settings.Default.TimeoutStandard);
            }
            }
        }
예제 #13
0
        private string DownloadContent(string pUrl, string mimeType, RequestComplexity pComplexity)
        {
            string result = string.Empty;

            try
            {
                base.Headers.Add(System.Net.HttpRequestHeader.Accept, mimeType);
                base.Encoding = Encoding.UTF8;

                RequestComplexity previousComplexity = this._CurrentComplexity;
                this._CurrentComplexity = pComplexity;

                var requestWatch = new Stopwatch();
                requestWatch.Start();
                result = base.DownloadString(pUrl);
                requestWatch.Stop();

                this._CurrentComplexity = previousComplexity;

                LogHelper.Instance.LogDebugFormat
                    ("Request URL '{0}' - Time elapsed : {1} "
                    , pUrl
                    , requestWatch.Elapsed.ToString()
                    );
            }
            catch (Exception ex)
            {
                LogHelper.Instance.LogErrorFormat
                    ("Request URL '{0}' - Error execution :  {1}"
                    , pUrl
                    , ex.Message
                    );

                throw ex;
            }

            return(result);
        }
예제 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="relativeURL"></param>
        /// <param name="pComplexity"></param>
        /// <param name="count">Max items to load from CSV</param>
        /// <param name="PropNames">Mapping between CSV columns and T members (optional)</param>
        /// <returns></returns>
        private IEnumerable <T> CallCsvWS <T>(string relativeURL, RequestComplexity pComplexity, int count, params string[] PropNames) where T : new()
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;

            try
            {
                if (_Client.GetCookieContainer().Count > 0)
                {
                    _Client.RemoveAuthenticationHeaders(CurrentApiKey);
                }
                var csvString  = _Client.DownloadCsvString(requestUrl, pComplexity);
                var serializer = new CsvSerializer <T>();
                return(serializer.ReadObjects(csvString, count, PropNames));
            }
            catch (WebException e)
            {
                LogHelper.Instance.LogError(e.Message);
                return(null);
            }
        }
예제 #15
0
 /// <summary>
 /// Download String
 /// </summary>
 /// <param name="pUrl"></param>
 /// <param name="pComplexity"></param>
 /// <returns></returns>
 public string DownloadString(string pUrl, RequestComplexity pComplexity)
 {
     return DownloadContent(pUrl, "application/json", pComplexity);
 }
예제 #16
0
 /// <summary>
 /// Download String by URI
 /// </summary>
 /// <param name="pUri"></param>
 /// <param name="pComplexity"></param>
 /// <returns></returns>
 public string DownloadCsvString(Uri pUri, RequestComplexity pComplexity)
 {
     return(DownloadCsvString(pUri.ToString(), pComplexity));
 }
예제 #17
0
 public string DownloadPlainText(string pUrl, RequestComplexity pComplexity)
 {
     return(DownloadContent(pUrl, "text/plain", pComplexity));
 }
예제 #18
0
 /// <summary>
 /// Download String
 /// </summary>
 /// <param name="pUrl"></param>
 /// <param name="pComplexity"></param>
 /// <returns></returns>
 public string DownloadString(string pUrl, RequestComplexity pComplexity)
 {
     return(DownloadContent(pUrl, "application/json", pComplexity));
 }
예제 #19
0
 /// <summary>
 /// Download Csv String
 /// </summary>
 /// <param name="pUrl"></param>
 /// <param name="pComplexity"></param>
 /// <returns></returns>
 public string DownloadCsvString(string pUrl, RequestComplexity pComplexity)
 {
     try
     {
         return DownloadContent(pUrl, "text/csv", pComplexity);
     }
     catch (WebException webEx)
     {
         // AIP < 8 sends CSV data as application/vnd.ms-excel
         return DownloadContent(pUrl, "application/vnd.ms-excel", pComplexity);
     }
 }
예제 #20
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pComplexity"></param>
 /// <returns></returns>
 private int GetRequestTimeOut(RequestComplexity pComplexity)
 {
     switch (pComplexity)
     {
         case RequestComplexity.Long:
             {
                 return Settings.Default.TimoutLong;
             }
         case RequestComplexity.Soft:
             {
                 return Settings.Default.TimeoutQuick;
             }
         case RequestComplexity.Standard:
         default:
             {
                 return Settings.Default.TimeoutStandard;
             }
     }
 }
예제 #21
0
        private string DownloadContent(string pUrl, string mimeType, RequestComplexity pComplexity)
        {
            string result = string.Empty;

            try
            {
                base.Headers.Add(System.Net.HttpRequestHeader.Accept, mimeType);
                base.Encoding = Encoding.UTF8;

                RequestComplexity previousComplexity = this._CurrentComplexity;
                this._CurrentComplexity = pComplexity;

                var requestWatch = new Stopwatch();
                requestWatch.Start();
                result = base.DownloadString(pUrl);
                requestWatch.Stop();

                this._CurrentComplexity = previousComplexity;

                LogHelper.Instance.LogDebugFormat
                        ("Request URL '{0}' - Time elapsed : {1} "
                        , pUrl
                        , requestWatch.Elapsed.ToString()
                        );

            }
            catch(Exception ex)
            {
                 LogHelper.Instance.LogErrorFormat
                        ("Request URL '{0}' - Error execution :  {1}"
                        , pUrl
                        , ex.Message
                        );

                 throw ex;
            }

            return result;
        }
예제 #22
0
 /// <summary>
 /// Download String by URI
 /// </summary>
 /// <param name="pUri"></param>
 /// <param name="pComplexity"></param>
 /// <returns></returns>
 public string DownloadString(Uri pUri, RequestComplexity pComplexity)
 {
     return DownloadString(pUri.ToString(), pComplexity);
 }