Esempio n. 1
0
        private async Task CreateDNSRecord(DNSType Type, string Name, string Value, DNSTTL TTL)
        {
            if (dnsRecords == null)
            {
                GetDNSRecord();
            }

            if (dnsRecords.Exists(r => r.Name == Name))
            {
                throw new ArgumentException("A entry with the same name and type already exists.");
            }

            Dictionary <string, string> content = GetDNSRequestParameters(Type, Name, Value, TTL);

            var createResult = new HttpRequestMessage(HttpMethod.Post, new Uri(context.baseUrl + "/domain/dnseditor/add-record-async"))
            {
                Content = new FormUrlEncodedContent(content)
            };

            context.ChangeDomain(this);
            var response = await context.client.SendAsync(createResult);

            EvaluateDNSModifyResponse(response, DNSModificationType.Create);
        }
Esempio n. 2
0
 public Task CreateTXTRecord(string Name, string Value, DNSTTL TTL)
 {
     return(CreateDNSRecord(DNSType.TXT, Name, Value, TTL));
 }
Esempio n. 3
0
 public Task CreateCNAMERecord(string Name, string Value, DNSTTL TTL)
 {
     return(CreateDNSRecord(DNSType.CNAME, Name, Value, TTL));
 }
Esempio n. 4
0
        /// <summary>
        /// Returns the parameter including validation to submit as FormUrlEncodedContent to my.cyon.ch.
        /// Used in create und update method.
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Name"></param>
        /// <param name="Value"></param>
        /// <param name="TTL"></param>
        /// <returns></returns>
        private Dictionary <string, string> GetDNSRequestParameters(DNSType Type, string Name, string Value, DNSTTL TTL)
        {
            Dictionary <string, string> content = new Dictionary <string, string>();

            if (Type == DNSType.CNAME)
            {
                string name = Name.EndsWith(this.Name) ? Name.Substring(0, Name.IndexOf(this.Name)) : Name;
                content.Add("zonePrefix", name);
                content.Add("zone", this.Name);
            }
            else
            {
                if (Name.EndsWith("."))
                {
                    content.Add("zone", Name);
                }
                else
                {
                    content.Add("zone", Name + ".");
                }
            }

            content.Add("ttl", ((int)TTL).ToString());
            content.Add("type", Type.ToString().ToUpper());

            if (Type == DNSType.AAAA)
            {
                content.Add("value", WebUtility.UrlEncode(Value));
            }
            else
            {
                content.Add("value", Value);
            }

            return(content);
        }