Exemple #1
0
        private static void ParseDomain(dynamic test, AvailableResult result)
        {
            var status = (string)test.value.@string;

            DomainStatus domainStatus;

            switch (status)
            {
            case "unavailable":
                domainStatus = DomainStatus.Unavailable;
                break;

            case "available":
                domainStatus = DomainStatus.Available;
                break;

            default:
                domainStatus = DomainStatus.Invalid;
                break;
            }

            string domainName = test.name;

            result.Domains.Add(domainName, domainStatus);
        }
Exemple #2
0
        public async Task <AvailableResult> AvailableAsync(AvailableInput input)
        {
            var requestTemplate = @"
<methodCall>
   <methodName>domain.available</methodName>
   <params>
      <param>
 <value><string>§model.ApiKey§</string></value>
 </param>
 <param>
<array>
   <data>
        §model.Data.Domains:{it|<value><string>§it§</string></value>}§
      </data>
   </array>
</param>
      </params>
   </methodCall>";

            var model = new ModelBase <AvailableInput>();

            model.ApiKey = _domainConfig.ApiKey;
            model.Data   = input;
            var request  = TemplateRenderer.Render(requestTemplate, model);
            var response = await SendRequestAsync(request);

            while (response.Contains("pending"))
            {
                await Task.Delay(700);

                response = await SendRequestAsync(request);
            }

            dynamic res = JArray.Parse("[" + response + "]");

            var result = new AvailableResult();

            result.Domains = new Dictionary <string, DomainStatus>();
            //{"?xml":{"@version":"1.0"},
            //"methodResponse":{"params":
            //{ "param":{"value":{"struct":{"member":{"name":"google.fr","value":{"string":"unavailable"}}}}}}}}

            var methodResponse = res.Last;
            var data           = [email protected];

            {
                var member = [email protected];

                if (member is JArray)
                {
                    foreach (var m in member)
                    {
                        ParseDomain(m, result);
                    }
                }
                else
                {
                    ParseDomain(member, result);
                }
            }

            return(result);
        }