示例#1
0
        public M3Response GetDataAsync(string program, string transaction, string queryParam, List <string> outputs, 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 && outputs.Count > 0)
            {
                requestUri += $";returncols={string.Join(",", outputs)}";
            }
            requestUri += $" {RestClientUtil.GetInputParametersFromJson(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(responseMessage, outputs, outputAllFields, metadata);

            return(responseDto);
        }