示例#1
0
        /// <summary>
        /// 生成随机域名
        /// </summary>
        /// <param name="domain"></param>
        /// <returns></returns>
        private string CreateRoundDomain(string domain, AdDomainInfo addomain)
        {
            string gid = Guid.NewGuid().ToString();

            if (!string.IsNullOrEmpty(addomain.TwoDomain))
            {
                gid = addomain.TwoDomain;
            }
            else
            {
                gid = gid.Substring(0, gid.IndexOf("-"));
            }
            return(string.Format("{0}.{1}", gid, domain));
        }
示例#2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var adids  = txtAds.Text.Split(',');
            var domain = txtDomain.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None);

            AdDomainInfo info = new AdDomainInfo();

            info.Domains   = domain.ToList <string>();
            info.AdId      = int.Parse(adids[0]);
            info.TwoDomain = txtTwoDomain.Text;

            AdDomainBLL bll = new AdDomainBLL();

            bll.CreatedAdDomain(info);
        }
示例#3
0
        /// <summary>
        /// 生成广告域名文件夹
        /// </summary>
        /// <param name="addomain"></param>
        public void CreatedAdDomain(AdDomainInfo addomain)
        {
            var info = AdPageInfoBLL.Instance.GetSingle(new AdPageInfoPara()
            {
                Id = addomain.AdId
            });
            var articleList = ArticleInfoBLL.Instance.GetModels(new ArticleInfoPara());

            StringBuilder sbdomain = new StringBuilder();
            List <string> domains  = new List <string>();

            if (info != null)
            {
                //分别获取HTML和CSS文件内容
                string indexpath = HttpContext.Current.Server.MapPath(string.Format("{0}{1}", m_template, m_html_index));
                string stylepath = HttpContext.Current.Server.MapPath(string.Format("{0}{1}", m_template, m_html_style));
                string html      = "";
                string style     = "";
                using (StreamReader reader = new StreamReader(indexpath))
                {
                    html = reader.ReadToEnd();
                }
                using (StreamReader reader = new StreamReader(stylepath))
                {
                    style = reader.ReadToEnd();
                }

                foreach (var item in addomain.Domains)
                {
                    if (string.IsNullOrEmpty(item))
                    {
                        continue;
                    }

                    string domain = CreateRoundDomain(item, addomain);
                    sbdomain.AppendLine(domain + ",");
                    domains.Add(domain);
                    string dir = string.Format("{0}{1}", m_diction, domain);
                    dir = HttpContext.Current.Server.MapPath(dir);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    ArticleInfoVO ainfo = articleList[m_random.Next(articleList.Count - 1)];


                    //写入域名相关的文件夹
                    string nhtmlpath  = Path.Combine(dir, "index.html");
                    string nstylename = Guid.NewGuid().ToString();
                    nstylename = nstylename.Substring(0, 4);
                    string nstylepath = Path.Combine(dir, string.Format("{0}.css", nstylename));

                    var result = ReplaceHtml(html, style, info, ainfo, nstylename);

                    using (StreamWriter write = new StreamWriter(nhtmlpath))
                    {
                        write.Write(result.Item1);
                        write.Flush();
                        write.Close();
                    }
                    using (StreamWriter write = new StreamWriter(nstylepath))
                    {
                        write.Write(result.Item2);
                        write.Flush();
                        write.Close();
                    }
                }
            }

            info.DomainList = sbdomain.ToString();
            AdPageInfoBLL.Instance.Edit(info);
            var arinfo = articleList[m_random.Next(articleList.Count - 1)];

            CreateMiddPage(domains, arinfo, info);
        }