Exemplo n.º 1
0
 public void ChangeDomainName(HostDNS host, string newDomainName)
 {
     try
     {
         if (host == null || host.Remark == null)
         {
             throw new ArgumentException("Invald domain argument.");
         }
         _helper.ChangeDomain(host.IP, host.DomainName, newDomainName, true);
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 2
0
 public bool AddHostDomain(HostDNS domain, bool isenable)
 {
     try
     {
         string remark = "";
         if (domain.Remark != null)
             remark = JSONHelper.JsonSerializer<HostRemark>(domain.Remark);
         string[] newline = new string[1] { string.Format("{0}{1}\t\t{2}\t\t{3}", isenable ? "" : "#", domain.IP, domain.DomainName, "#" + remark) };
         _helper.WriteToFile(newline, true);
         return true;
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 3
0
 public void ChangeComment(HostDNS host, string newcomment)
 {
     try
     {
         if (host == null || host.Remark == null)
         {
             throw new ArgumentException("Invald domain argument.");
         }
         HostRemark remark = new HostRemark() { SiteType = host.Remark.SiteType, Target = host.Remark.Target, Comment = newcomment };
         _helper.ChangeRemark(host.IP, host.DomainName, new HostRemark(), true);
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 4
0
 public bool SaveHostDomain(string oldDomain, HostDNS host, bool isWriteToFile)
 {
     try
     {
         _helper.ChangeLineByDomain(oldDomain, host.IP, host.Remark, !host.IsDisabled, isWriteToFile);
         return true;
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 5
0
        public List<HostDNS> GetDomanList(Recognizer rec)
        {
            try
            {
                List<HostDNS> resultList = new List<HostDNS>();
                IEnumerable<string> lines = _helper.GetAllLines();
                Regex reg = new Regex(@"(^[#\s]*)((\d{1,3}\.){3}\d{1,3})\s*([\d\w\.-]+)[^\S\n]*(#[^\n]*)?$", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                foreach (string line in lines)
                {
                    Match match = reg.Match(line.Trim());
                    if (match.Success)
                    {
                        HostDNS domain = new HostDNS();
                        domain.IsDisabled = !string.IsNullOrEmpty(match.Groups[1].Value.Trim());
                        domain.IP = match.Groups[2].Value;
                        domain.DomainName = match.Groups[4].Value;
                        string remarkStr = match.Groups[5].Value;

                        if (string.IsNullOrWhiteSpace(domain.IP) || string.IsNullOrWhiteSpace(domain.DomainName)) continue;
                        if (string.IsNullOrWhiteSpace(remarkStr.Trim('#')))
                        {
                            HostRemark remark = new HostRemark() { SiteType = rec.GetSiteType(domain.DomainName,domain.IP), Target = TargetType.Other, Comment = "" };
                            domain.Remark = remark;
                        }
                        else
                        {
                            try
                            {
                                domain.Remark = JSONHelper.JsonDeserialize<HostRemark>(remarkStr.Trim('#'));
                            }
                            catch (Exception e)
                            {
                                HostRemark newmark = new HostRemark() { SiteType = rec.GetSiteType(domain.DomainName,domain.IP), Target = TargetType.Other, Comment = remarkStr.Trim('#') };
                                domain.Remark = newmark;
                            }
                        }

                        resultList.Add(domain);
                    }
                }
                return resultList;
            }
            catch (Exception ex)
            {
                _loger.WriteLine(ex.ToString());
                throw;
            }
        }
Exemplo n.º 6
0
 public void EnableHost(HostDNS host)
 {
     try
     {
         if (host == null)
         {
             throw new ArgumentException("The host can not be null.");
         }
         else if (!host.IsDisabled)
         {
             return;
         }
         _helper.EnableByIpAndDomain(host.IP, host.DomainName, true);
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 7
0
 public bool DeleteHostLine(HostDNS host, bool iswritetofile)
 {
     try
     {
         _helper.DeleteLine(host.IP, host.DomainName, host.IsDisabled, iswritetofile);
         return true;
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 8
0
 public void ChangeTargetType(HostDNS host, TargetType newTargetType)
 {
     try
     {
         if (host == null || host.Remark == null)
         {
             throw new ArgumentException("Invald domain argument.");
         }
         else if (host.Remark.Target == newTargetType)
         {
             return;
         }
         else
         {
             HostRemark newRemark = new HostRemark() { SiteType = host.Remark.SiteType, Target = newTargetType, Comment = host.Remark.Comment };
             string newIp = EnvironmentMnager.GetIpAdress(host.Remark.SiteType, newTargetType);
             if (!string.IsNullOrEmpty(newIp))
             {
                 _helper.ChangeIpAndRemark(host.DomainName, host.IP, newIp, newRemark, true);
                 DNSManager.FulshDNS();
             }
             else
             {
                 _helper.ChangeRemark(host.IP, host.DomainName, newRemark, true);
             }
         }
     }
     catch (Exception ex)
     {
         _loger.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 9
0
        public void ChangeRemark(HostDNS domain, HostRemark newRemark, bool isWriteToFile)
        {
            try
            {
                if (newRemark.SiteType != domain.Remark.SiteType || newRemark.Target != domain.Remark.Target)//siteType or targetType has changed
                {
                    string newIp = EnvironmentMnager.GetIpAdress(newRemark.SiteType, newRemark.Target);
                    if (String.IsNullOrWhiteSpace(newIp))
                    {
                        _helper.ChangeRemark(domain.IP, domain.DomainName, newRemark, true);

                    }
                    else
                    {
                        _helper.ChangeIpAndRemark(domain.DomainName, domain.IP, newIp, newRemark, true);
                    }
                }
                else//only comment is changed
                {
                    _helper.ChangeRemark(domain.IP, domain.DomainName, newRemark, true);
                }
            }
            catch (Exception ex)
            {
                _loger.WriteLine(ex.ToString());
                throw;
            }
        }
Exemplo n.º 10
0
        private HostDNS GetCurrentBoundHost(int rowindex)
        {
            if (rowindex < 0 || rowindex > dgvDomain.Rows.Count)
            {
                rowindex = dgvDomain.CurrentCell.RowIndex;
            }
            HostDNS dns = new HostDNS();
            var currentcell = dgvDomain.CurrentCellAddress;
            var a = dgvDomain.Rows[rowindex].DataBoundItem as DataRowView;

            dns.DomainName = a["Domain"] as string;
            dns.IP = a["IP"] as string;

            dns.Remark = new HostRemark();
            SiteType type = (SiteType)a["SiteType"];
            dns.Remark.SiteType = type;
            dns.Remark.Comment = a["Remark"] as string;

            if (((Image)a["QA1"]).Tag.ToString() == ENABLE)
            {
                dns.Remark.Target = TargetType.QA1;
            }
            else if (((Image)a["QA2"]).Tag.ToString() == ENABLE)
            {
                dns.Remark.Target = TargetType.QA2;
            }
            else if (((Image)a["QA3"]).Tag.ToString() == ENABLE)
            {
                dns.Remark.Target = TargetType.QA3;
            }
            else if (((Image)a["LOC"]).Tag.ToString() == ENABLE)
            {
                dns.Remark.Target = TargetType.LOCAL;
            }
            else
            {
                dns.Remark.Target = TargetType.DEFAULT;
            }
            dns.IsDisabled = (bool)a["IsDisabled"];
            return dns;
        }