Example #1
0
        public static void GetDataObject(Action <System.Net.WebClient> action,
                                         Uri uri,
                                         IWebClientCaller caller,
                                         IDictionary <string, string> queryParameters = null,
                                         IDictionary <string, string> headers         = null)
        {
            NameValueCollection queryParams;

            if (queryParameters != null)
            {
                queryParams = new NameValueCollection(queryParameters.Count);
                queryParameters.ForEach(kvp => queryParams.Add(kvp.Key, kvp.Value));
            }
            else
            {
                queryParams = new NameValueCollection();
            }

            var headerParams = new WebHeaderCollection();

            if (headers != null)
            {
                headers.ForEach(kvp => headerParams.Add(kvp.Key, kvp.Value));
            }

            using (var client = new WebClientTimeouted(caller))
            {
                client.Headers     = headerParams;
                client.QueryString = queryParams;
                action(client);
            }
        }
Example #2
0
 public static JSONDynamicObject GetJsonAsDynamic(string uri, IWebClientCaller caller,
                                                  HTTPRequestMethod method = HTTPRequestMethod.GET,
                                                  IDictionary <string, string> queryParameters = null,
                                                  IDictionary <string, string> bodyParameters  = null,
                                                  IDictionary <string, string> headers         = null)
 {
     return(GetJsonAsDynamic(new Uri(uri), caller, method, queryParameters, bodyParameters, headers));
 }
Example #3
0
 public static void GetFile(string file,
                            Uri uri,
                            IWebClientCaller caller,
                            IDictionary <string, string> queryParameters = null,
                            IDictionary <string, string> headers         = null)
 {
     GetDataObject((c) => { c.DownloadFile(uri, file); }, uri, caller, queryParameters, headers);
 }
Example #4
0
 public static JSONDataMap GetValueMap(string uri, IWebClientCaller caller,
                                       HTTPRequestMethod method = HTTPRequestMethod.GET,
                                       IDictionary <string, string> queryParameters = null,
                                       IDictionary <string, string> bodyParameters  = null,
                                       IDictionary <string, string> headers         = null)
 {
     return(GetValueMap(new Uri(uri), caller, method, queryParameters, bodyParameters, headers));
 }
Example #5
0
 public static XDocument GetXML(string uri, IWebClientCaller caller,
                                HTTPRequestMethod method = HTTPRequestMethod.GET,
                                IDictionary <string, string> queryParameters = null,
                                IDictionary <string, string> bodyParameters  = null,
                                IDictionary <string, string> headers         = null)
 {
     return(GetXML(new Uri(uri), caller, method, queryParameters, bodyParameters, headers));
 }
Example #6
0
 public BaseClient(IWebClientCaller caller, string host, string subscriptionId, AzureOAuth2Token token)
 {
     Caller         = caller;
     Host           = new Uri(host);
     Token          = token;
     SubscriptionId = subscriptionId;
     LogLevel       = DEFAULT_LOG_LEVEL;
 }
Example #7
0
        public static XDocument GetXML(Uri uri, IWebClientCaller caller,
                                       HTTPRequestMethod method = HTTPRequestMethod.GET,
                                       IDictionary <string, string> queryParameters = null,
                                       IDictionary <string, string> bodyParameters  = null,
                                       IDictionary <string, string> headers         = null)
        {
            string responseStr = GetString(uri, caller, method, queryParameters: queryParameters, bodyParameters: bodyParameters, headers: headers);

            return(string.IsNullOrWhiteSpace(responseStr) ? null : XDocument.Parse(responseStr));
        }
Example #8
0
        public static JSONDataMap GetJson(Uri uri, IWebClientCaller caller,
                                          HTTPRequestMethod method = HTTPRequestMethod.GET,
                                          IDictionary <string, string> queryParameters = null,
                                          IDictionary <string, string> bodyParameters  = null,
                                          IDictionary <string, string> headers         = null)
        {
            string responseStr = GetString(uri, caller, method, queryParameters: queryParameters, bodyParameters: bodyParameters, headers: headers);

            return(string.IsNullOrWhiteSpace(responseStr) ? null : responseStr.JSONToDataObject() as JSONDataMap);
        }
Example #9
0
        public static JSONDataMap GetValueMap(Uri uri, IWebClientCaller caller,
                                              HTTPRequestMethod method = HTTPRequestMethod.GET,
                                              IDictionary <string, string> queryParameters = null,
                                              IDictionary <string, string> bodyParameters  = null,
                                              IDictionary <string, string> headers         = null)
        {
            string responseStr = GetString(uri, caller, method, queryParameters: queryParameters, bodyParameters: bodyParameters, headers: headers);
            var    dict        = JSONDataMap.FromURLEncodedString(responseStr);

            return(dict);
        }
Example #10
0
            public RequestParams(IWebClientCaller caller)
            {
                Caller = caller;

                Method          = HTTPRequestMethod.GET;
                ContentType     = Web.ContentType.FORM_URL_ENCODED;
                QueryParameters = null;
                BodyParameters  = null;
                Body            = null;
                Headers         = null;
                AcceptType      = null;
                UserName        = null;
                Password        = null;
            }
Example #11
0
        public static byte[] GetData(Uri uri,
                                     IWebClientCaller caller, out string contentType,
                                     IDictionary <string, string> queryParameters = null,
                                     IDictionary <string, string> headers         = null)
        {
            byte[] data             = null;
            string localContentType = string.Empty;

            GetDataObject((c) => {
                data             = c.DownloadData(uri);
                localContentType = c.ResponseHeaders[HttpResponseHeader.ContentType];
            }, uri, caller, queryParameters, headers);
            contentType = localContentType;
            return(data);
        }
Example #12
0
        public static string GetString(Uri uri,
                                       IWebClientCaller caller,
                                       HTTPRequestMethod method = HTTPRequestMethod.GET,
                                       IDictionary <string, string> queryParameters = null,
                                       IDictionary <string, string> bodyParameters  = null,
                                       string body = null,
                                       IDictionary <string, string> headers = null)
        {
            RequestParams request = new RequestParams()
            {
                Uri             = uri,
                Caller          = caller,
                Method          = method,
                QueryParameters = queryParameters,
                BodyParameters  = bodyParameters,
                Body            = body,
                Headers         = headers
            };

            return(GetString(request));
        }
Example #13
0
 public static JSONDynamicObject GetJsonAsDynamic(string uri, IWebClientCaller caller, 
   HTTPRequestMethod method = HTTPRequestMethod.GET,
   IDictionary<string, string> queryParameters = null,
   IDictionary<string, string> bodyParameters = null,
   IDictionary<string, string> headers = null)
 {
   return GetJsonAsDynamic(new Uri(uri), caller, method, queryParameters, bodyParameters, headers);
 }
Example #14
0
 public static JSONDataMap GetJson(string uri, IWebClientCaller caller, string body, IDictionary <string, string> headers = null)
 {
     return(GetJson(new Uri(uri), caller, body, headers));
 }
Example #15
0
 public WebClientTimeouted(IWebClientCaller caller)
 {
     WebSettings.RequireInitializedSettings();
     m_Caller = caller;
 }
Example #16
0
      public static XDocument GetXML(Uri uri, IWebClientCaller caller, IDictionary<string, string> queryParameters, string body)
      {
        string responseStr = GetString(uri, caller, HTTPRequestMethod.POST, body: body, queryParameters: queryParameters);

        return string.IsNullOrWhiteSpace(responseStr) ? null : XDocument.Parse(responseStr);
      }
Example #17
0
      public static XDocument GetXML(Uri uri, IWebClientCaller caller, 
        HTTPRequestMethod method = HTTPRequestMethod.GET,
        IDictionary<string, string> queryParameters = null,
        IDictionary<string, string> bodyParameters = null,
        IDictionary<string, string> headers = null)
      {
        string responseStr = GetString(uri, caller, method, queryParameters: queryParameters, bodyParameters: bodyParameters, headers: headers);

        return string.IsNullOrWhiteSpace(responseStr) ? null : XDocument.Parse(responseStr);
      }
Example #18
0
 public static JSONDataMap GetValueMap(Uri uri, IWebClientCaller caller, 
   HTTPRequestMethod method = HTTPRequestMethod.GET,
   IDictionary<string, string> queryParameters = null,
   IDictionary<string, string> bodyParameters = null,
   IDictionary<string, string> headers = null)
 {
   string responseStr = GetString(uri, caller, method, queryParameters: queryParameters, bodyParameters: bodyParameters, headers: headers);
   var dict = Utils.ParseQueryString(responseStr);
   return dict;
 }
Example #19
0
      public static JSONDataMap GetJson(Uri uri, IWebClientCaller caller, string body, IDictionary<string, string> headers = null)
      {
        string responseStr = GetString(uri, caller, HTTPRequestMethod.POST, body: body, headers: headers);

        return string.IsNullOrWhiteSpace(responseStr) ? null : responseStr.JSONToDataObject() as JSONDataMap;
      }
Example #20
0
 public static XDocument GetXML(string uri, IWebClientCaller caller, IDictionary <string, string> queryParameters, string body)
 {
     return(GetXML(new Uri(uri), caller, queryParameters, body));
 }
Example #21
0
        public static XDocument GetXML(Uri uri, IWebClientCaller caller, IDictionary <string, string> queryParameters, string body)
        {
            string responseStr = GetString(uri, caller, HTTPRequestMethod.POST, body: body, queryParameters: queryParameters);

            return(string.IsNullOrWhiteSpace(responseStr) ? null : XDocument.Parse(responseStr));
        }
Example #22
0
 public NetworkClient(IWebClientCaller caller, string host, string subscriptionId, AzureOAuth2Token token)
     : base(caller, host, subscriptionId, token)
 {
 }
Example #23
0
 public static JSONDynamicObject GetJsonAsDynamic(string uri, IWebClientCaller caller, string body, IDictionary <string, string> headers = null)
 {
     return(GetJsonAsDynamic(new Uri(uri), caller, body, headers));
 }
Example #24
0
 public static JSONDynamicObject GetJsonAsDynamic(string uri, IWebClientCaller caller, string body, IDictionary<string, string> headers = null)
 {
   return GetJsonAsDynamic(new Uri(uri), caller, body, headers);
 }
Example #25
0
 public WebClientTimeouted(IWebClientCaller caller)
 {
   WebSettings.RequireInitializedSettings();
   m_Caller = caller;
 }
Example #26
0
      public static JSONDataMap GetJson(Uri uri, IWebClientCaller caller, 
        HTTPRequestMethod method = HTTPRequestMethod.GET,
        IDictionary<string, string> queryParameters = null,
        IDictionary<string, string> bodyParameters = null,
        IDictionary<string, string> headers = null)
      {
        string responseStr = GetString(uri, caller, method, queryParameters: queryParameters, bodyParameters: bodyParameters, headers: headers);

        return string.IsNullOrWhiteSpace(responseStr) ? null : responseStr.JSONToDataObject() as JSONDataMap;
      }
Example #27
0
 public WebClientTimeouted(IWebClientCaller caller)
 {
     m_Caller = caller;
 }
Example #28
0
 public static JSONDataMap GetJson(string uri, IWebClientCaller caller, string body, IDictionary<string, string> headers = null)
 {
   return GetJson(new Uri(uri), caller, body, headers);
 }
Example #29
0
      public static string GetString(Uri uri, 
        IWebClientCaller caller,
        HTTPRequestMethod method = HTTPRequestMethod.GET,
        IDictionary<string, string> queryParameters = null,
        IDictionary<string, string> bodyParameters = null,
        string body = null,
        IDictionary<string, string> headers = null)
      {
        RequestParams request = new RequestParams()
        {
          Uri = uri,
          Caller = caller,
          Method = method,
          QueryParameters = queryParameters,
          BodyParameters = bodyParameters,
          Body = body,
          Headers = headers
        };

        return GetString(request);
      }
Example #30
0
 public static JSONDataMap GetValueMap(string uri, IWebClientCaller caller, 
   HTTPRequestMethod method = HTTPRequestMethod.GET,
   IDictionary<string, string> queryParameters = null,
   IDictionary<string, string> bodyParameters = null,
   IDictionary<string, string> headers = null)
 {
   return GetValueMap(new Uri(uri), caller, method, queryParameters, bodyParameters, headers);
 }
Example #31
0
 public static byte[] GetData(Uri uri,
                              IWebClientCaller caller, out string contentType,
                              IDictionary<string, string> queryParameters = null,
                              IDictionary<string, string> headers = null)
 {
   byte[] data = null;
   string localContentType = string.Empty;
   GetDataObject((c) => { 
     data = c.DownloadData(uri);
     localContentType = c.ResponseHeaders[HttpResponseHeader.ContentType];
   }, uri, caller, queryParameters, headers);
   contentType = localContentType;
   return data;
 }
Example #32
0
 public static XDocument GetXML(string uri, IWebClientCaller caller, 
   HTTPRequestMethod method = HTTPRequestMethod.GET,
   IDictionary<string, string> queryParameters = null,
   IDictionary<string, string> bodyParameters = null,
   IDictionary<string, string> headers = null)
 {
   return GetXML(new Uri(uri), caller, method, queryParameters, bodyParameters, headers);
 }
Example #33
0
 public static void GetFile(string file,
                            Uri uri,
                            IWebClientCaller caller,
                            IDictionary<string, string> queryParameters = null,
                            IDictionary<string, string> headers = null)
 {
   GetDataObject((c) => { c.DownloadFile(uri, file); }, uri, caller, queryParameters, headers);
 }
Example #34
0
 public static XDocument GetXML(string uri, IWebClientCaller caller, IDictionary<string, string> queryParameters, string body)
 {
   return GetXML(new Uri(uri), caller, queryParameters, body);
 }
Example #35
0
      public static void GetDataObject(Action<System.Net.WebClient> action,
                                       Uri uri,
                                       IWebClientCaller caller,
                                       IDictionary<string, string> queryParameters = null,
                                       IDictionary<string, string> headers = null)
      {
        NameValueCollection queryParams;
        if (queryParameters != null)
        {
          queryParams = new NameValueCollection(queryParameters.Count);
          queryParameters.ForEach(kvp => queryParams.Add(kvp.Key, kvp.Value));
        }
        else
        {
          queryParams = new NameValueCollection();
        }

        var headerParams = new WebHeaderCollection();
        if (headers != null)
          headers.ForEach(kvp => headerParams.Add(kvp.Key, kvp.Value));

        using (var client = new WebClientTimeouted(caller))
        {
          client.Headers = headerParams;
          client.QueryString = queryParams;
          action(client);
        }
      }
Example #36
0
 public ComputeClient(IWebClientCaller caller, string subscriptionId, AzureOAuth2Token token)
 {
 }
Example #37
0
        public static JSONDataMap GetJson(Uri uri, IWebClientCaller caller, string body, IDictionary <string, string> headers = null)
        {
            string responseStr = GetString(uri, caller, HTTPRequestMethod.POST, body: body, headers: headers);

            return(string.IsNullOrWhiteSpace(responseStr) ? null : responseStr.JSONToDataObject() as JSONDataMap);
        }