Exemple #1
0
        public void CreateSpare()
        {
            CloudXNSRecord record = new CloudXNSRecord();

            record.DomainID = _domainID;

            List <CloudXNSRecord>            list = _api.RecordController.GetList(_domainID);
            Dictionary <int, CloudXNSRecord> _dic = new Dictionary <int, CloudXNSRecord>();

            foreach (CloudXNSRecord r in list)
            {
                _dic.Add(r.RecordID, r);
                Console.WriteLine("{0}.{1}", r, _domainName);
                Console.WriteLine(" ID:{0}\tType:{1}  \tValue:{2}", r.RecordID, r.RecordType, r.Value);
                Console.WriteLine();
            }

            int recordID = -1;

            while (!_dic.ContainsKey(recordID))
            {
                recordID = GetIntInput("请输入要新增备用记录的解析记录ID:");
            }
            record.RecordID = recordID;
            record.HostID   = _dic[recordID].HostID;

            string value = GetStringInput("请输入备记录值:");

            record.Value = value;

            Console.WriteLine(_api.RecordController.CreateSpare(record));
            Console.ReadLine();
        }
Exemple #2
0
        /// <summary>
        /// 处理创建、更新解析记录时参数的输入
        /// </summary>
        /// <returns></returns>
        private CloudXNSRecord InputRecordInfor()
        {
            CloudXNSRecord record = new CloudXNSRecord();

            record.DomainID = _domainID;
            #region Host
            string host = GetStringInput("请输入主机记录名称(如www,@):");
            if (string.IsNullOrEmpty(host))
            {
                host = "@";
            }
            record.Host = host;
            #endregion
            #region Type
            Console.WriteLine("请输入记录类型:");
            List <string> types = _api.InformationController.GetRecordTypes();
            Console.WriteLine(string.Join(",", types));
            string type = Console.ReadLine();
            if (string.IsNullOrEmpty(type))
            {
                type = "A";
            }
            record.RecordType = type;
            #endregion
            #region Value
            record.Value = GetStringInput("请输入记录值:");
            #endregion
            #region MX
            type = type.ToLower();
            if (type == "mx" || type == "ax" || type == "cnamex")
            {
                int mx = GetIntInput("请输入MX优先级:");
                record.MX = mx.ToString();
            }
            #endregion
            #region LineID
            Console.WriteLine("输入y查询线路ID(全网默认为1),直接输入请按任意键:");
            if (Console.ReadKey().KeyChar == 'y')
            {
                List <CloudXNSLine> list = _api.InformationController.GetLineList();
                if (list != null)
                {
                    int level = 0;
                    InformationTest.CloudXNSLineProcessor(list, ref level);
                }
                Console.ReadLine();
            }
            int lineID = GetIntInput("请输入线路ID:");
            record.LineID = lineID;
            #endregion
            #region TTL
            int ttl = GetIntInput("请输入TTL(60-3600):");
            if (ttl < 60 || ttl > 3600)
            {
                ttl = 600;
            }
            record.TTL = ttl;
            #endregion
            return(record);
        }
Exemple #3
0
        public void Update()
        {
            int            recordID = InputSelectedRecord("请输入要更新的解析记录ID:");
            CloudXNSRecord record   = InputRecordInfor();

            record.RecordID = recordID;
            Console.WriteLine(_api.RecordController.Update(record));
            Console.ReadLine();
        }
        /// <summary>
        /// 在指定域名下新建一条备用解析记录
        /// </summary>
        /// <param name="record">解析记录实体,须填参数为DomainID、HostID、RecordID、Value</param>
        /// <returns>API响应状态</returns>
        public APIResponse CreateSpare(CloudXNSRecord record)
        {
            JsonSerializerSettings jsonSS = new JsonSerializerSettings();

            jsonSS.ContractResolver = new DynamicContractResolver(new string[] { "domain_id", "host_id", "record_id", "value" });
            string      data     = JsonConvert.SerializeObject(record, jsonSS);
            string      result   = _httpUtility.PostAPIRequest("POST", "record/spare", data);
            APIResponse response = JsonConvert.DeserializeObject <APIResponse>(result);

            return(response);
        }
        /// <summary>
        /// 更新指定解析记录
        /// </summary>
        /// <param name="record">解析记录实体,必填参数为DomainID(必)、Host、Value(必)、MX、TTL、Type、LineID、SpareValue</param>
        /// <returns>返回解析实体有效值有记录ID、完整域名、值</returns>
        public CloudXNSRecord Update(CloudXNSRecord record)
        {
            JsonSerializerSettings jsonSS = new JsonSerializerSettings();

            jsonSS.ContractResolver = new DynamicContractResolver(new string[] { "domain_id", "host", "value",
                                                                                 "type", "mx", "ttl", "line_id" });
            string      data     = JsonConvert.SerializeObject(record, jsonSS);
            string      result   = _httpUtility.PostAPIRequest("PUT", string.Format("record/{0}", record.RecordID), data);
            APIResponse response = JsonConvert.DeserializeObject <APIResponse>(result);

            if (response.Code == 1)
            {
                JObject        jobject        = (JObject)JsonConvert.DeserializeObject(result);
                string         responseData   = jobject["data"].ToString();
                CloudXNSRecord responseRecord = JsonConvert.DeserializeObject <CloudXNSRecord>(data);
                return(responseRecord);
            }
            else
            {
                throw new APIResponseException(response);
            }
        }