public virtual object Clone()
        {
            ApiResultBuildOption option = new ApiResultBuildOption();

            option.JsonSerializerSettings = this.JsonSerializerSettings;
            option.SetModelStatus         = this.SetModelStatus;
            return(option);
        }
Esempio n. 2
0
        protected ApiResultBuildOption <T> BuildResultOption <T>(ApiResultBuildOption <T> resultOption) where T : class, new()
        {
            var option = resultOption?.Clone() as ApiResultBuildOption <T>;

            if (option == null)
            {
                option = ApiResultBuildOption <T> .Create(this.DefaultResultBuildOption);
            }
            else if (this.DefaultRequestBuildOption != null)
            {
            }

            return(option);
        }
Esempio n. 3
0
        public async Task <ApiResponse <T> > GetAsync <T>(ApiRequest request, string controllerUrl, ApiResultBuildOption <T> resultOption = null) where T : class, new()
        {
            var response = new ApiResponse <T>();

            try
            {
                var task = this.GetAsync(request.GetUrl(controllerUrl));

                var message = task.Result;
                if (resultOption == null && this.DefaultResultBuildOption != null)
                {
                    resultOption = ApiResultBuildOption <T> .Create(this.DefaultResultBuildOption);
                }
                await response.DeserializeMessageAsync(message, resultOption);
            }
            catch { response.Data = null; }

            return(response);
        }
Esempio n. 4
0
        public async Task <ApiResponse <T> > PostByUrlAsync <T>(string url, ApiResultBuildOption <T> resultOption = null) where T : class, new()
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage();

            requestMessage.RequestUri = new Uri(url);
            requestMessage.Method     = HttpMethod.Post;
            var response = new ApiResponse <T>();

            try
            {
                var task = this.SendAsync(requestMessage);
                task.Wait();
                var message = task.Result;
                if (resultOption == null && this.DefaultResultBuildOption != null)
                {
                    resultOption = ApiResultBuildOption <T> .Create(this.DefaultResultBuildOption);
                }
                await response.DeserializeMessageAsync(message, resultOption);
            }
            catch { response.Data = null; }

            return(response);
        }
Esempio n. 5
0
 public async Task <ApiResponse <T> > GetAsync <T>(ApiRequest request, ApiResultBuildOption <T> resultOption = null) where T : class, new()
 {
     return(await GetAsync <T>(request, null, resultOption));
 }
Esempio n. 6
0
        public async Task <ApiResponse <T> > PostByModelAsync <T>(object model, string controllerUrl, string url = null, ApiRequestBuildOption requestOption = null, ApiResultBuildOption <T> resultOption = null) where T : class, new()
        {
            var reqOption = this.BuildRequestOption(requestOption);

            if (reqOption.DefaultLocationType == ApiSerializeLocationType.Auto)
            {
                reqOption.DefaultLocationType = ApiSerializeLocationType.FromForm;
            }
            var resOption = this.BuildResultOption(resultOption);
            var request   = ApiRequest.FromModel(model, url, reqOption);

            request.ApiUrl = ApiRequest.CombineUrl(controllerUrl, request.ApiUrl);
            var response = await this.PostAsync <T>(request, resOption);

            response.SetModelStatus();
            return(response);
        }
Esempio n. 7
0
 public async Task <ApiResponse <T> > PostByModelAsync <T>(object model, string url = null, ApiRequestBuildOption requestOption = null, ApiResultBuildOption <T> resultOption = null) where T : class, new()
 {
     return(await PostByModelAsync(model, null, url, requestOption, resultOption));
 }