コード例 #1
0
 public bool AddHostDomain(HostDomain domain, bool isenable)
 {
     try
     {
         string[] newline = new string[1] { string.Format("{0}{1}\t\t{2}\t\t{3}", isenable ? "" : "#", domain.Ip, domain.DomainName, domain.Remark) };
         _helper.WriteToFile(newline, true);
         return true;
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }
コード例 #2
0
        public void ChangeDomainSiteType(HostDomain domain, SiteType newSiteType)
        {
            try
            {
                if (domain.SiteType == newSiteType) return;

                string newIp = EnvironmentMnager.GetIpAdress(newSiteType, domain.Target);
                _helper.ChangeIp(domain.Ip, newIp, domain.DomainName, true);
            }
            catch (Exception ex)
            {
                _loger.WriteLine(ex.ToString());
                throw;
            }
        }
コード例 #3
0
        public List<HostDomain> GetDomanList(Recognizer rec)
        {
            try
            {
                List<HostDomain> resultList = new List<HostDomain>();
                IEnumerable<string> lines = _helper.GetAllLines();
                Regex reg = new Regex(@"(^[\s#]*)([\d\.]+)\s*([\w\d\.-]+)\s*(#[^#\r\n%]*)?(\s*#%([^%]*)%)?\s*$", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                foreach (string line in lines)
                {
                    Match match = reg.Match(line.Trim());
                    if (match.Success)
                    {
                        HostDomain domain = new HostDomain();
                        domain.IsDisabled = !string.IsNullOrEmpty(match.Groups[1].Value);
                        domain.Ip = match.Groups[2].Value;
                        domain.DomainName = match.Groups[3].Value;
                        domain.Remark = match.Groups[4].Value.Trim();

                        string targetStr = match.Groups[6].Value.Trim();
                        TargetType type = TargetType.Other;
                        if (Enum.TryParse(targetStr, out type))
                            domain.Target = type;
                        else
                            domain.Target = TargetType.Other;
                        domain.SiteType = rec.GetSiteType(domain.DomainName);
                        resultList.Add(domain);
                    }
                }
                return resultList;
            }
            catch (Exception ex)
            {
                _loger.WriteLine(ex.ToString());
                throw;
            }
        }
コード例 #4
0
 public bool SaveHostDomain(string oldDomain, HostDomain newDomain, bool isenable, HostRemark remark, bool isWriteToFile)
 {
     try
     {
         _helper.ChangeLineByDomain(oldDomain, newDomain.Ip, remark, isenable, isWriteToFile);
         return true;
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }