コード例 #1
0
ファイル: ISiteAgent.cs プロジェクト: haositongxue/avia
        /// <summary>
        /// 添加域名
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domain">根域名</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomain(int siteId, string domain, string[] subName, CDNProviderType provider)
        {
            domain = WebAgent.GetTopDomain(domain);
            if (string.IsNullOrEmpty(domain))
            {
                return(this.FaildMessage("域名错误"));
            }
            if (this.ReadDB.Exists <SiteDomain>(t => t.Domain == domain))
            {
                return(this.FaildMessage("域名已被添加"));
            }
            foreach (string name in subName)
            {
                if (!Regex.IsMatch(name, @"^@$|^\*$|^\w+$"))
                {
                    return(this.FaildMessage($"子域名{name}不符合规范"));
                }
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadCommitted))
            {
                SiteDomain siteDomain = new SiteDomain()
                {
                    SiteID = siteId,
                    Domain = domain
                };
                siteDomain.AddIdentity(db);

                foreach (string name in subName.Distinct())
                {
                    // 添加域名记录
                    DomainRecord record = new DomainRecord()
                    {
                        CDNType  = provider,
                        CName    = this.CreateRecordCName(name, domain),
                        DomainID = siteDomain.ID,
                        Status   = DomainRecord.RecordStatus.Wait,
                        SubName  = name
                    };
                    record.AddIdentity(db);

                    // 添加CDN记录
                    DomainCDN cdn = new DomainCDN()
                    {
                        RecordID = record.ID,
                        Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                        CName    = string.Empty,
                        CDNType  = provider,
                        Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                    };
                    cdn.Add(db);
                }
                db.Commit();
            }

            return(true);
        }
コード例 #2
0
ファイル: ISiteAgent.cs プロジェクト: haositongxue/avia
        /// <summary>
        /// 添加域名记录
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domainId">根域名ID</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomainRecord(int siteId, int domainId, string subName, CDNProviderType provider)
        {
            if (string.IsNullOrEmpty(subName) || !Regex.IsMatch(subName, @"^@$|^\*$|^\w+$"))
            {
                return(this.FaildMessage($"子域名{subName}不符合规范"));
            }
            SiteDomain domain = this.GetDomainInfo(siteId, domainId);

            if (domain == null)
            {
                return(this.FaildMessage("域名ID错误"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <DomainRecord>(t => t.DomainID == domainId && t.SubName == subName))
                {
                    return(this.FaildMessage("子域名记录已经存在"));
                }

                DomainRecord record = new DomainRecord()
                {
                    CDNType  = provider,
                    CName    = this.CreateRecordCName(subName, domain.Domain),
                    DomainID = domainId,
                    Status   = DomainRecord.RecordStatus.Wait,
                    SubName  = subName
                };
                record.AddIdentity(db);

                // 添加CDN记录
                DomainCDN cdn = new DomainCDN()
                {
                    RecordID = record.ID,
                    Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                    CName    = string.Empty,
                    CDNType  = provider,
                    Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                };
                cdn.Add(db);

                db.Commit();
            }
            return(true);
        }