コード例 #1
0
        public M3Response GetDataAsync <T>(string program, string transaction, object queryParam, bool outputAllFields = false, int maxrecs = 0, bool metadata = false, bool excludempty = false)
        {
            M3Response responseDto = new M3Response();

            HttpClient request    = RestClientFactory.CreateBasicAuthRestClient(m3RestConfiguration);
            string     requestUri = $"{program}/{transaction};metadata={metadata};maxrecs={maxrecs};excludempty={excludempty}";

            if (!outputAllFields)
            {
                requestUri += $";returncols={RestClientUtil.GetOutputParameters(typeof(T))}";
            }
            requestUri += $" {RestClientUtil.GetInputParameters(queryParam)}";

            HttpResponseMessage response = request.GetAsync(requestUri).Result;

            if (response.IsSuccessStatusCode == false)
            {
                responseDto.Success = false;
                responseDto.Message = "M3 call failed.";
                return(responseDto);
            }

            var content = response.Content.ReadAsStringAsync().Result;
            var m3Error = this.GetM3ErrorMessage(content);

            if (!String.IsNullOrEmpty(m3Error))
            {
                responseDto.Success = false;
                responseDto.Message = m3Error;
                return(responseDto);
            }

            dynamic responseMessage = JObject.Parse(content);

            responseDto.Data = this.GetValueListFromM3ResultByMultipleSelectors <T>(responseMessage, RestClientUtil.GetProperties(typeof(T)), metadata);

            return(responseDto);
        }