internal Task <ListedResponse <T> > AccessJsonParameteredApiArrayAsync <T>(string url, object parameters, string[] jsonMap, CancellationToken cancellationToken, string jsonPath = "")
 {
     return(this.AccessJsonParameteredApiArrayAsyncImpl <T>(url, InternalUtils.ResolveObject(parameters), jsonMap, cancellationToken, jsonPath));
 }
Beispiel #2
0
 internal void AccessApiNoResponse(string url, Expression <Func <string, object> >[] parameters)
 {
     this.AccessApiNoResponseImpl(url, InternalUtils.ExpressionsToDictionary(parameters));
 }
Beispiel #3
0
 internal void AccessApiNoResponseImpl(string url, IEnumerable <KeyValuePair <string, object> > parameters)
 {
     this.SendRequestImpl(MethodType.Post, InternalUtils.GetUrl(url), parameters).Close();
 }
Beispiel #4
0
 internal ListedResponse <T> AccessApiArray <T>(MethodType type, string url, Expression <Func <string, object> >[] parameters, string jsonPath = "")
 {
     return(this.AccessApiArrayImpl <T>(type, url, InternalUtils.ExpressionsToDictionary(parameters), jsonPath));
 }
Beispiel #5
0
 internal DictionaryResponse <TKey, TValue> AccessApiDictionary <TKey, TValue>(MethodType type, string url, Expression <Func <string, object> >[] parameters, string jsonPath = "")
 {
     return(this.AccessApiDictionaryImpl <TKey, TValue>(type, url, InternalUtils.ExpressionsToDictionary(parameters), jsonPath));
 }
Beispiel #6
0
 internal ListedResponse <T> AccessJsonParameteredApiArray <T>(string url, object parameters, string[] jsonMap, string jsonPath = "")
 {
     return(this.AccessJsonParameteredApiArrayImpl <T>(url, InternalUtils.ResolveObject(parameters), jsonMap, jsonPath));
 }
Beispiel #7
0
 /// <summary>
 /// Sends a request to the specified url with the specified parameters.
 /// </summary>
 /// <param name="type">The type of HTTP request.</param>
 /// <param name="url">The URL.</param>
 /// <param name="parameters">The parameters.</param>
 /// <returns>A stream.</returns>
 public HttpWebResponse SendRequest(MethodType type, string url, object parameters)
 {
     return(this.SendRequestImpl(type, url, InternalUtils.ResolveObject(parameters), this.ConnectionOptions));
 }
 internal Task <ListedResponse <T> > AccessApiArrayAsync <T>(MethodType type, string url, object parameters, CancellationToken cancellationToken, string jsonPath = "")
 {
     return(this.AccessApiArrayAsyncImpl <T>(type, url, InternalUtils.ResolveObject(parameters), cancellationToken, jsonPath));
 }
 internal Task <DictionaryResponse <TKey, TValue> > AccessApiDictionaryAsync <TKey, TValue>(MethodType type, string url, Expression <Func <string, object> >[] parameters, string jsonPath = "")
 {
     return(this.AccessApiDictionaryAsyncImpl <TKey, TValue>(type, url, InternalUtils.ExpressionsToDictionary(parameters), CancellationToken.None, jsonPath));
 }
 /// <summary>
 /// Sends a request to the specified url with the specified parameters as an asynchronous operation.
 /// </summary>
 /// <param name="type">The type of HTTP request.</param>
 /// <param name="url">The URL.</param>
 /// <param name="parameters">The parameters.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>
 /// <para>The task object representing the asynchronous operation.</para>
 /// <para>The Result property on the task object returns a <see cref="AsyncResponse"/>.</para>
 /// </returns>
 public Task <AsyncResponse> SendRequestAsync(MethodType type, string url, object parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(this.SendRequestAsyncImpl(type, url, InternalUtils.ResolveObject(parameters), this.ConnectionOptions, cancellationToken));
 }
        private Task <AsyncResponse> SendRequestAsyncImpl(MethodType type, string url, IEnumerable <KeyValuePair <string, object> > parameters, ConnectionOptions options, CancellationToken cancellationToken, IProgress <UploadProgressInfo> progress = null)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                var tcs = new TaskCompletionSource <AsyncResponse>();
                tcs.SetCanceled();
                return(tcs.Task);
            }

            var prmArray = InternalUtils.FormatParameters(parameters);
            var uri      = CreateUri(type, url, prmArray);

            Task <AsyncResponse> task;

            switch (type)
            {
            case MethodType.Get:
                task = Request.HttpGetAsync(
                    uri,
                    CreateAuthorizationHeader(type, uri, null),
                    options,
                    cancellationToken
                    );
                break;

            case MethodType.Post:
                task = ContainsBinaryData(prmArray)
                        ? Request.HttpPostWithMultipartFormDataAsync(
                    uri,
                    prmArray,
                    CreateAuthorizationHeader(type, uri, null),
                    options,
                    cancellationToken,
                    progress
                    )
                        : Request.HttpPostAsync(
                    uri,
                    prmArray,
                    CreateAuthorizationHeader(type, uri, prmArray),
                    options,
                    cancellationToken,
                    progress
                    );
                break;

            case MethodType.Put:
                task = Request.HttpPutAsync(
                    uri,
                    prmArray,
                    CreateAuthorizationHeader(type, uri, prmArray),
                    options,
                    cancellationToken,
                    progress
                    );
                break;

            case MethodType.Delete:
                task = Request.HttpDeleteAsync(
                    uri,
                    CreateAuthorizationHeader(type, uri, null),
                    options,
                    cancellationToken
                    );
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type));
            }

            return(task.ResponseCallback(cancellationToken));
        }
 /// <summary>
 /// Sends a request to the specified url with the specified parameters as an asynchronous operation.
 /// </summary>
 /// <param name="type">The type of HTTP request.</param>
 /// <param name="url">The URL.</param>
 /// <param name="parameters">The parameters.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>
 /// <para>The task object representing the asynchronous operation.</para>
 /// <para>The Result property on the task object returns a <see cref="AsyncResponse"/>.</para>
 /// </returns>
 public Task <AsyncResponse> SendRequestAsync(MethodType type, string url, CancellationToken cancellationToken = default(CancellationToken), params Expression <Func <string, object> >[] parameters)
 {
     return(this.SendRequestAsyncImpl(type, url, InternalUtils.ExpressionsToDictionary(parameters), this.ConnectionOptions, cancellationToken));
 }
 internal Task <AsyncResponse> SendJsonRequestAsync(string fullUrl, IEnumerable <KeyValuePair <string, object> > parameters, string[] jsonMap, CancellationToken cancellationToken)
 {
     return(this.PostContentAsync(fullUrl, JsonContentType, InternalUtils.MapDictToJson(parameters, jsonMap), cancellationToken));
 }
 internal Task <ListedResponse <T> > AccessJsonParameteredApiArrayAsyncImpl <T>(string url, IEnumerable <KeyValuePair <string, object> > parameters, string[] jsonMap, CancellationToken cancellationToken, string jsonPath)
 {
     return(this.SendJsonRequestAsync(InternalUtils.GetUrl(this.ConnectionOptions, url), parameters, jsonMap, cancellationToken)
            .ReadResponse(s => new ListedResponse <T>(CoreBase.ConvertArray <T>(s, jsonPath)), cancellationToken));
 }
Beispiel #15
0
 internal T AccessJsonParameteredApiImpl <T>(string url, IEnumerable <KeyValuePair <string, object> > parameters, string[] jsonMap, string jsonPath)
 {
     using (var response = this.SendJsonRequest(InternalUtils.GetUrl(this.ConnectionOptions, url), parameters, jsonMap))
         return(InternalUtils.ReadResponse <T>(response, jsonPath));
 }
 internal Task <DictionaryResponse <TKey, TValue> > AccessApiDictionaryAsync <TKey, TValue>(MethodType type, string url, object parameters, CancellationToken cancellationToken, string jsonPath = "")
 {
     return(this.AccessApiDictionaryAsyncImpl <TKey, TValue>(type, url, InternalUtils.ResolveObject(parameters), cancellationToken, jsonPath));
 }
Beispiel #17
0
 internal ListedResponse <T> AccessJsonParameteredApiArray <T>(string url, Expression <Func <string, object> >[] parameters, string[] jsonMap, string jsonPath = "")
 {
     return(this.AccessJsonParameteredApiArrayImpl <T>(url, InternalUtils.ExpressionsToDictionary(parameters), jsonMap, jsonPath));
 }
 internal Task <DictionaryResponse <TKey, TValue> > AccessApiDictionaryAsyncImpl <TKey, TValue>(MethodType type, string url, IEnumerable <KeyValuePair <string, object> > parameters, CancellationToken cancellationToken, string jsonPath)
 {
     return(this.SendRequestAsyncImpl(type, InternalUtils.GetUrl(this.ConnectionOptions, url), parameters, cancellationToken)
            .ReadResponse(s => new DictionaryResponse <TKey, TValue>(CoreBase.Convert <Dictionary <TKey, TValue> >(s, jsonPath)), cancellationToken));
 }
Beispiel #19
0
 internal HttpWebResponse SendJsonRequest(string fullUrl, IEnumerable <KeyValuePair <string, object> > parameters, string[] jsonMap)
 {
     return(this.PostContent(fullUrl, JsonContentType, InternalUtils.MapDictToJson(parameters, jsonMap)));
 }
 internal Task AccessApiNoResponseAsync(MethodType type, string url, Expression <Func <string, object> >[] parameters)
 {
     return(this.AccessApiNoResponseAsyncImpl(type, url, InternalUtils.ExpressionsToDictionary(parameters), CancellationToken.None));
 }
Beispiel #21
0
 internal T AccessApi <T, TV>(MethodType type, string url, TV parameters, string jsonPath = "")
 {
     return(this.AccessApiImpl <T>(type, url, InternalUtils.ResolveObject(parameters), jsonPath));
 }
Beispiel #22
0
 internal T AccessApiImpl <T>(MethodType type, string url, IEnumerable <KeyValuePair <string, object> > parameters, string jsonPath)
 {
     using (var response = this.SendRequestImpl(type, InternalUtils.GetUrl(this.ConnectionOptions, url), parameters))
         return(InternalUtils.ReadResponse <T>(response, jsonPath));
 }
Beispiel #23
0
 internal ListedResponse <T> AccessApiArray <T, TV>(MethodType type, string url, TV parameters, string jsonPath = "")
 {
     return(this.AccessApiArrayImpl <T>(type, url, InternalUtils.ResolveObject(parameters), jsonPath));
 }
Beispiel #24
0
 internal void AccessApiNoResponse(MethodType type, string url, object parameters)
 {
     this.AccessApiNoResponseImpl(type, url, InternalUtils.ResolveObject(parameters));
 }
Beispiel #25
0
 internal DictionaryResponse <TKey, TValue> AccessApiDictionary <TKey, TValue, TV>(MethodType type, string url, TV parameters, string jsonPath = "")
 {
     return(this.AccessApiDictionaryImpl <TKey, TValue>(type, url, InternalUtils.ResolveObject(parameters), jsonPath));
 }
Beispiel #26
0
 internal void AccessApiNoResponseImpl(MethodType type, string url, IEnumerable <KeyValuePair <string, object> > parameters)
 {
     this.SendRequestImpl(type, InternalUtils.GetUrl(this.ConnectionOptions, url), parameters).Close();
 }
Beispiel #27
0
 internal void AccessApiNoResponse <TV>(string url, TV parameters)
 {
     this.AccessApiNoResponseImpl(url, InternalUtils.ResolveObject(parameters));
 }
Beispiel #28
0
 internal T AccessJsonParameteredApi <T>(string url, object parameters, string[] jsonMap, string jsonPath = "")
 {
     return(this.AccessJsonParameteredApiImpl <T>(url, InternalUtils.ResolveObject(parameters), jsonMap, jsonPath));
 }
Beispiel #29
0
 /// <summary>
 /// Sends a request to the specified url with the specified parameters.
 /// </summary>
 /// <param name="type">The type of HTTP request.</param>
 /// <param name="url">The URL.</param>
 /// <param name="parameters">The parameters.</param>
 /// <returns>A stream.</returns>
 public HttpWebResponse SendRequest(MethodType type, string url, params Expression <Func <string, object> >[] parameters)
 {
     return(this.SendRequestImpl(type, url, InternalUtils.ExpressionsToDictionary(parameters), this.ConnectionOptions));
 }
 internal Task <ListedResponse <T> > AccessJsonParameteredApiArrayAsync <T>(string url, Expression <Func <string, object> >[] parameters, string[] jsonMap, string jsonPath = "")
 {
     return(this.AccessJsonParameteredApiArrayAsyncImpl <T>(url, InternalUtils.ExpressionsToDictionary(parameters), jsonMap, CancellationToken.None, jsonPath));
 }