Пример #1
0
        public override DomainRecordActionResult DeleteDomainRecord(DeleteDomainRecordParam param)
        {
            var request = new DeleteDomainRecordRequest()
            {
                RecordId = param.RecordId,
            };

            try
            {
                var response = client.GetAcsResponse(request);
                if (response == null || response.HttpResponse.Content == null || response.HttpResponse.Content.Length == 0)
                {
                    throw new Exception($"Delete subdomain record info failed. record id is {param.RecordId}");
                }
                string result    = Encoding.UTF8.GetString(response.HttpResponse.Content);
                var    resultObj = new JsonSerializer().Deserialize <DomainRecordActionResult>(new JsonTextReader(new StringReader(result)));
                if (resultObj != null)
                {
                    resultObj.Status = true;
                }
                return(resultObj);
            }
            catch (ServerException e)
            {
                throw new Exception($"Aliyun server error. {e.Message}");
            }
            catch (ClientException e)
            {
                throw new Exception($"Reuqest client error. errcode is {e.ErrorCode}, {e.Message}");
            }
        }
Пример #2
0
        ///// <summary>
        ///// 删除所有指定类型的记录。
        ///// </summary>
        ///// <param name="domain">域名</param>
        ///// <param name="rr">主机记录</param>
        ///// <param name="type">解析记录类型</param>
        ///// <returns>是否删除成功。</returns>
        //private bool DeleteRecordsByType(string domain, string rr, string type)
        //{
        //    try
        //    {
        //        var client = GetNewClient();
        //        DeleteSubDomainRecordsRequest request = new DeleteSubDomainRecordsRequest
        //        {
        //            DomainName = domain,
        //            RR = rr,
        //            Type = type,
        //        };
        //        var response = client.GetAcsResponse(request);
        //        if (response.HttpResponse.isSuccess())
        //        {
        //            Log.Print($"成功清理{ type }记录{ rr }.{ domain }。");
        //            return true;
        //        }
        //        else
        //        {
        //            Log.Print($"清理{ type }记录{ rr }.{ domain }失败。");
        //            return false;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        Log.Print($"删除{ type }记录{ rr }.{ domain }记录时出现异常:{ e }");
        //        return false;
        //    }
        //}

        /// <summary>
        /// 删除所有记录。
        /// </summary>
        /// <param name="records">记录</param>
        /// <returns>是否成功删除</returns>
        private bool DeleteRecords(IEnumerable <Record> records)
        {
            foreach (var rd in records)
            {
                try
                {
                    var client = GetNewClient();
                    DeleteDomainRecordRequest request = new DeleteDomainRecordRequest
                    {
                        RecordId = rd.RecordId
                    };
                    var response = client.GetAcsResponse(request);
                    if (response.HttpResponse.isSuccess())
                    {
                        Log.Print($"成功清理{ rd.Type }记录{ rd.RR }.{ rd.DomainName }({ rd.Line })记录{ rd.RecordId }。");
                    }
                    else
                    {
                        Log.Print($"清理{ rd.Type }记录{ rd.RR }.{ rd.DomainName }({ rd.Line })记录{ rd.RecordId }失败。");
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Log.Print($"删除{ rd.Type }记录{ rd.RR }.{ rd.DomainName }({ rd.Line })记录{ rd.RecordId }时出现异常:{ e }");
                    return(false);
                }
            }

            return(true);
        }