示例#1
0
        /// <summary>
        /// Send a <see cref="HttpMethod"/> <b>PATCH</b> <paramref name="json"/> request as an asynchronous operation.
        /// </summary>
        /// <param name="urlSuffix">The url suffix for the operation.</param>
        /// <param name="patchOption">The <see cref="WebApiPatchOption"/>.</param>
        /// <param name="json">The json value.</param>
        /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param>
        /// <param name="args">The operation arguments to be substituted within the <paramref name="urlSuffix"/>.</param>
        /// <param name="memberName">The method or property name of the caller to the method.</param>
        /// <param name="filePath">The full path of the source file that contains the caller.</param>
        /// <param name="lineNumber">The line number in the source file at which the method is called.</param>
        /// <returns>The <see cref="WebApiAgentResult{TResult}"/>.</returns>
        public async Task <WebApiAgentResult> PatchAsync(string urlSuffix, WebApiPatchOption patchOption, JToken json, WebApiRequestOptions?requestOptions = null, WebApiArg[]?args = null, [CallerMemberName] string?memberName = null, [CallerFilePath] string?filePath = null, [CallerLineNumber] int lineNumber = 0)
        {
            if (json == null)
            {
                throw new ArgumentNullException(nameof(json));
            }

            if (patchOption == WebApiPatchOption.NotSpecified)
            {
                throw new ArgumentException("A valid patch option must be specified.", nameof(patchOption));
            }

            var uri = CreateFullUri(urlSuffix, args, requestOptions);

            if (args != null && args.Any(x => x.ArgType == WebApiArgType.FromBody))
            {
                throw new ArgumentException("No arguments can be marked as IsFromBody for a PATCH.", nameof(args));
            }

            return(await WebApiServiceAgentInvoker.Default.InvokeAsync(this, async() =>
            {
                var content = new StringContent(json.ToString());
                content.Headers.ContentType = MediaTypeHeaderValue.Parse(patchOption == WebApiPatchOption.JsonPatch ? "application/json-patch+json" : "application/merge-patch+json");
                var result = new WebApiAgentResult(await Client.SendAsync(CreateRequestMessage(new HttpMethod("PATCH"), uri, content, requestOptions)).ConfigureAwait(false));
                result.Content = await result.Response.Content.ReadAsStringAsync().ConfigureAwait(false);
                return VerifyResult(result);
            }, json, memberName, filePath, lineNumber).ConfigureAwait(false));
        }
示例#2
0
        public Task <WebApiAgentResult <Person> > PatchWithEfAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions?requestOptions = null)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(PatchAsync <Person>("api/v1/persons/ef/{id}", patchOption, value, requestOptions: requestOptions,
                                       args: new WebApiArg[] { new WebApiArg <Guid>("id", id) }));
        }
示例#3
0
        public Task <WebApiAgentResult <PersonDetail> > PatchDetailAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions?requestOptions = null)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            return(base.PatchAsync <PersonDetail>("api/v1/persons/{id}/detail", patchOption, value, requestOptions: requestOptions,
                                                  args: new WebApiArg[] { new WebApiArg <Guid>("id", id) }));
        }
示例#4
0
        public Task <WebApiAgentResult <Robot> > PatchAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions?requestOptions = null)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(base.PatchAsync <Robot>("api/v1/robots/{id}", patchOption, value, requestOptions: requestOptions,
                                           args: new WebApiArg[] { new WebApiArg <Guid>("id", id) }));
        }
示例#5
0
 /// <summary>
 /// Patches the <see cref="Robot"/> object.
 /// </summary>
 /// <param name="patchOption">The <see cref="WebApiPatchOption"/>.</param>
 /// <param name="value">The JSON patch value.</param>
 /// <param name="id">The <see cref="Robot"/> identifier.</param>
 /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param>
 /// <returns>A <see cref="WebApiAgentResult"/>.</returns>
 public Task <WebApiAgentResult <Robot> > PatchAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions requestOptions = null)
 {
     return(RobotServiceAgent.PatchAsync(patchOption, value, id, requestOptions));
 }
示例#6
0
 /// <summary>
 /// Patches the <see cref="Person"/> object.
 /// </summary>
 /// <param name="patchOption">The <see cref="WebApiPatchOption"/>.</param>
 /// <param name="value">The JSON patch value.</param>
 /// <param name="id">The <see cref="Person"/> identifier.</param>
 /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param>
 /// <returns>A <see cref="WebApiAgentResult"/>.</returns>
 public Task <WebApiAgentResult <PersonDetail> > PatchDetailAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions requestOptions = null)
 {
     return(PersonServiceAgent.PatchDetailAsync(patchOption, value, id, requestOptions));
 }
示例#7
0
 public Task <WebApiAgentResult <Employee> > PatchAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions?requestOptions = null) =>
 PatchAsync <Employee>("api/employees/{id}", patchOption, Beef.Check.NotNull(value, nameof(value)), requestOptions: requestOptions,
                       args: new WebApiArg[] { new WebApiArg <Guid>("id", id) });
示例#8
0
 public Task <WebApiAgentResult <PerformanceReview> > PatchAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions?requestOptions = null) =>
 PatchAsync <PerformanceReview>("api/v1/reviews/{id}", patchOption, Beef.Check.NotNull(value, nameof(value)), requestOptions: requestOptions,
                                args: new WebApiArg[] { new WebApiArg <Guid>("id", id) });
示例#9
0
 public Task <WebApiAgentResult <Person> > PatchAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions?requestOptions = null)
 => PersonServiceAgent.PatchAsync(patchOption, value, id, requestOptions);
示例#10
0
 public Task <WebApiAgentResult <PersonDetail> > PatchDetailAsync(WebApiPatchOption patchOption, JToken value, Guid id, WebApiRequestOptions?requestOptions = null) =>
 PatchAsync <PersonDetail>("api/v1/persons/{id}/detail", patchOption, Beef.Check.NotNull(value, nameof(value)), requestOptions: requestOptions,
                           args: new WebApiArg[] { new WebApiArg <Guid>("id", id) });
示例#11
0
        /// <summary>
        /// Send a <see cref="HttpMethod"/> <b>PATCH</b> <paramref name="json"/> request as an asynchronous operation with an expected response.
        /// </summary>
        /// <typeparam name="TResult">The result <see cref="Type"/>.</typeparam>
        /// <param name="urlSuffix">The url suffix for the operation.</param>
        /// <param name="patchOption">The <see cref="WebApiPatchOption"/>.</param>
        /// <param name="json">The json value.</param>
        /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param>
        /// <param name="args">The operation arguments to be substituted within the <paramref name="urlSuffix"/>.</param>
        /// <returns>The <see cref="WebApiAgentResult{TResult}"/>.</returns>
        public async Task <WebApiAgentResult <TResult> > PatchAsync <TResult>(string?urlSuffix, WebApiPatchOption patchOption, JToken json, WebApiRequestOptions?requestOptions = null, WebApiArg[]?args = null)
        {
            if (json == null)
            {
                throw new ArgumentNullException(nameof(json));
            }

            var uri = CreateFullUri(urlSuffix, args, requestOptions);

            if (args != null && args.Any(x => x.ArgType == WebApiArgType.FromBody))
            {
                throw new ArgumentException("No arguments can be marked as IsFromBody for a PATCH.", nameof(args));
            }

            return(await WebApiAgentInvoker.Current.InvokeAsync(this, async() =>
            {
                var content = new StringContent(json.ToString());
                content.Headers.ContentType = MediaTypeHeaderValue.Parse(patchOption == WebApiPatchOption.JsonPatch ? "application/json-patch+json" : "application/merge-patch+json");
                var result = new WebApiAgentResult(await Args.HttpClient.SendAsync(await CreateRequestMessageAsync(new HttpMethod("PATCH"), uri, content, requestOptions).ConfigureAwait(false)).ConfigureAwait(false));
                result.Content = await result.Response.Content.ReadAsStringAsync().ConfigureAwait(false);
                return new WebApiAgentResult <TResult>(VerifyResult(result));
            }, json).ConfigureAwait(false));
        }
示例#12
0
 public Task <WebApiAgentResult <PostalInfo> > PatchPostCodesAsync(WebApiPatchOption patchOption, JToken value, string?country, string?state, string?city, WebApiRequestOptions?requestOptions = null) =>
 PatchAsync <PostalInfo>("api/v1/postal/{country}/{state}/{city}", patchOption, Beef.Check.NotNull(value, nameof(value)), requestOptions: requestOptions,
                         args: new WebApiArg[] { new WebApiArg <string?>("country", country), new WebApiArg <string?>("state", state), new WebApiArg <string?>("city", city) });