Пример #1
0
        private async Task <Tuple <bool, string> > SendHttpRequestForSingleValue()
        {
            string result = string.Empty;
            bool   ok     = true;

            if (this.SelectedValueType == typeof(decimal).Name || this.SelectedValueType == typeof(int).Name)
            {
                HttpData <NumberDto[]> dDto = await this.HttpApiClient.GetDataAsync <NumberDto>(this.SelectedLibrary, this.SelectedMethod, this.PrepareParameters());

                ok = dDto.IsSuccessStatusCode;
                if (dDto.CheckHttpData())
                {
                    decimal number = dDto.Content[0].Result;
                    result = (this.SelectedValueType == typeof(int).Name) ? number.ToString("F0") : number.ToString("F9");
                }
            }
            else if (this.SelectedValueType == typeof(DateTime).Name)
            {
                HttpData <DateTimeDto[]> dtDto = await this.HttpApiClient.GetDataAsync <DateTimeDto>(this.SelectedLibrary, this.SelectedMethod, this.PrepareParameters());

                ok = dtDto.IsSuccessStatusCode;
                if (dtDto.CheckHttpData())
                {
                    result = dtDto.Content[0].ToString();
                }
            }
            else if (this.SelectedValueType == typeof(IdNameModel).Name)
            {
                HttpData <IdNameModel[]> tDto = await this.HttpApiClient.GetDataAsync <IdNameModel>(this.SelectedLibrary, this.SelectedMethod, this.PrepareParameters());

                ok = tDto.IsSuccessStatusCode;
                if (tDto.CheckHttpData())
                {
                    result = string.Join($" {Environment.NewLine}", tDto.Content.Select(m => m.ToString()));
                }
            }
            else if (this.SelectedValueType == typeof(object).Name)
            {
                HttpData <object[]> tDto = await this.HttpApiClient.GetDataAsync <object>(this.SelectedLibrary, this.SelectedMethod, this.PrepareParameters());

                ok = tDto.IsSuccessStatusCode;
                if (tDto.CheckHttpData())
                {
                    // Data item type is Newtonsoft.Json.Linq.JObject
                    result = string.Join($" {Environment.NewLine}", tDto.Content.Select(m => m.ToString()));
                }
            }
            else if (this.SelectedValueType == "test-anonymous")
            {
                //var user = new { Id = 0, Name = string.Empty, DateOfJoining = DateTime.MinValue, Rank = 0M, IsPower = false };
                var user = new
                {
                    IdUser      = -1,
                    UserName    = "",
                    IdProf      = -1,
                    Pr_Name     = "",
                    IdStation   = -1,
                    IsPower     = -1,
                    IsPassPol   = -1,
                    IsPassExp   = -1,
                    IsPassChn   = -1,
                    Email       = "",
                    DateChn     = DateTime.MinValue,
                    IsMainEmail = -1,
                    ValidTo     = default(DateTime?)
                };
                var oDto = await this.HttpApiClient.GetDataAsync(this.SelectedLibrary, this.SelectedMethod, this.PrepareParameters(), user);

                ok = oDto.IsSuccessStatusCode;
                if (oDto.CheckHttpData())
                {
                    result = string.Join($" {Environment.NewLine}", oDto.Content.Select(m => m.ToString()));
                }
            }
            else if (this.SelectedValueType == "test-dynamic")
            {
                PropMold[] props = new PropMold[]
                {
                    PropMold.Make <int>("Id"),
                    PropMold.Make <string>("Name"),
                    PropMold.Make <DateTime>("DateOfJoining"),
                    PropMold.Make <decimal>("Rank"),
                    PropMold.Make <bool>("IsPower"),
                };

                var expandoData = await this.HttpApiClient.GetDynamicDataAsync(this.SelectedLibrary, this.SelectedMethod, this.PrepareParameters(), props);

                ok = expandoData.IsSuccessStatusCode;
                if (expandoData.CheckHttpExpando())
                {
                    var dynamicList = expandoData.Content.Select(i => new { Id = i.id, Name = i.name, DateOfJoining = ((DateTime)i.dateOfJoining).ToString("dd.MM.yyyy"), Rank = i.rank, IsPower = i.isPower });
                    result = string.Join($" {Environment.NewLine}", dynamicList);
                }
            }
            else
            {
                HttpData <StringDto[]> sDto = await this.HttpApiClient.GetDataAsync <StringDto>(this.SelectedLibrary, this.SelectedMethod, this.PrepareParameters());

                ok = sDto.IsSuccessStatusCode;
                if (sDto.CheckHttpData())
                {
                    result = sDto.Content[0].ToString();
                }
            }

            return(Tuple.Create(ok, result));
        }