/// <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); } }
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); }
/// <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)); } }
/// <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)); } }
/// <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)); }
/// <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); }
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); }
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); } }
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); }
/// <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); } } }
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); } }
/// <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); } } }
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); }
/// <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); } }
/// <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); }
/// <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)); }
public string DownloadPlainText(string pUrl, RequestComplexity pComplexity) { return(DownloadContent(pUrl, "text/plain", pComplexity)); }
/// <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)); }
/// <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); } }
/// <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; } } }
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; }
/// <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); }