Exemple #1
0
        static ZonesSimple Row2ZoneSimple(DataRow dr)
        {
            ZonesSimple z = new ZonesSimple();

            z.userid  = Convert.ToInt32(dr[2]);
            z.domain  = dr[1].ToString().ToLower() + ".";
            z.rrcol   = Utility.StringHelper.CalculateMD5Hash(z.domain).Substring(0, 1).ToLower();
            z.level   = Convert.ToInt32(dr[3]);
            z.nsstate = Convert.ToInt32(dr[4]);
            return(z);
        }
Exemple #2
0
        static ZonesSimple Row2ZoneSimple(zones tz)
        {
            ZonesSimple z = new ZonesSimple();

            z.userid  = Convert.ToInt32(tz.userid);
            z.domain  = tz.zone.ToLower() + ".";
            z.rrcol   = Utility.StringHelper.CalculateMD5Hash(z.domain).Substring(0, 1).ToLower();
            z.level   = Convert.ToInt32(tz.level);
            z.nsstate = tz.nsstate;
            return(z);
        }
Exemple #3
0
        static void DeleteBind()
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();//开始计时
            DataTable    dt        = MySQLHelper.Query("SELECT z.id,z.zone,z.userid,CASE when d.maxfensheng<1 then 0 else 1 end as level,z.nsstate,z.active,z.forcestop,z.rzone from zones as z left join domainlevel as d on z.DomainLevel=d.levelvalue where z.zone<>z.rzone").Tables[0];
            List <zones> zonesList = DtToList <zones> .ConvertToModel(dt);

            Console.WriteLine("GetDataTabel from mysql count={1} Use Time={0};", watch.ElapsedMilliseconds, dt.Rows.Count);
            List <ZonesSimple>[] ala = new List <ZonesSimple>[16] {
                new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>(), new List <ZonesSimple>()
            };
            var client = DriverConfiguration.Client;
            var db     = client.GetDatabase(DriverConfiguration.DatabaseNamespace.DatabaseName);

            foreach (zones z in zonesList)
            {
                ZonesSimple zs = Zones2ZonesSimple(z);
                ala[Int32.Parse(zs.rrcol, System.Globalization.NumberStyles.HexNumber)].Add(zs);
            }
            string del = "";

            try
            {
                for (int i = 0; i < 16; i++)
                {
                    string rrcol = i.ToString("x");
                    IMongoCollection <AuthoritiesSimple> collection = db.GetCollection <AuthoritiesSimple>(rrcol);
                    Console.WriteLine(rrcol + "  " + ala[i].Count);
                    List <string> domainList = new List <string>();
                    int           count      = 0;
                    foreach (ZonesSimple zs in ala[i])
                    {
                        domainList.Add(zs.domain);
                        count++;
                        if (domainList.Count == 100 || count == ala[i].Count)
                        {
                            DeleteResult result = collection.DeleteMany(Builders <AuthoritiesSimple> .Filter.In("domain", domainList));
                            domainList.Clear();
                            Console.WriteLine(count);
                        }
                    }
                    Console.WriteLine("deal " + rrcol);
                }
            }
            catch (Exception ex) {
                string messget = ex.Message;
            }
            Console.WriteLine("end deal ");
        }
Exemple #4
0
        static ZonesSimple Row2ZoneSimple(zones tz)
        {
            ZonesSimple z = new ZonesSimple();

            z.domain = tz.zone.ToLower() + ".";
            string md5 = Utility.StringHelper.CalculateMD5Hash(z.domain).ToLower();

            z.id         = md5;
            z.userid     = Convert.ToInt32(tz.userid);
            z.rrcol      = md5.Substring(0, 1).ToLower();
            z.level      = Convert.ToInt32(tz.level);
            z.nsstate    = tz.nsstate;
            z.is_stop    = tz.active == "Y" ? "N" : "Y";
            z.force_stop = tz.forcestop;
            return(z);
        }
Exemple #5
0
        public static ZonesSimple Zones2ZonesSimple(zones theZone)
        {
            ZonesSimple zs = new ZonesSimple();

            string md5 = StringHelper.CalculateMD5Hash(theZone.zone + ".").ToLower();

            zs.id = md5;
            if (theZone.zone != theZone.rzone)
            {
                md5 = StringHelper.CalculateMD5Hash(theZone.rzone + ".").ToLower();
            }
            zs.userid      = Convert.ToInt32(theZone.userid);
            zs.domain      = theZone.zone + ".";
            zs.rrcol       = md5.Substring(0, 1);
            zs.level       = Convert.ToInt32(theZone.level);
            zs.nsstate     = theZone.nsstate;
            zs.is_stop     = theZone.active == "Y" ? "N" : "Y";
            zs.force_stop  = theZone.forcestop;
            zs.rdomain     = theZone.rzone + ".";
            zs.loadonstart = 0;
            return(zs);
        }
Exemple #6
0
        static void CheckZonesCount()
        {
            DataTable dtid = MySQLHelper.Query("select min(id),max(id) from zones").Tables[0];
            long      min  = Convert.ToInt32(dtid.Rows[0][0]);
            long      max  = Convert.ToInt32(dtid.Rows[0][1]);

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();//开始计时
            long index = 3282504;

            do
            {
                DataTable    dt = MySQLHelper.Query("SELECT z.id,z.zone,z.userid,0 as level,z.nsstate from zones as z where z.id between " + (index - 1000) + " and " + index + "").Tables[0];
                List <zones> zl = DtToList <zones> .ConvertToModel(dt);

                var client = DriverConfiguration.Client;
                var db     = client.GetDatabase(DriverConfiguration.DatabaseNamespace.DatabaseName);

                IMongoCollection <ZonesSimple> collection = db.GetCollection <ZonesSimple>("zones");
                foreach (zones z in zl)
                {
                    ZonesSimple zs      = Row2ZoneSimple(z);
                    var         builder = Builders <ZonesSimple> .Filter;
                    long        c       = collection.Find <ZonesSimple>(builder.And(builder.Eq("domain", zs.domain))).Count();
                    if (c > 1)
                    {
                        Console.WriteLine(zs.domain + "   count=" + c);
                    }
                }
                index = index - 1001;

                Console.WriteLine("min={0};max={1};index={2}; Use time={3};", min, max, index, watch.ElapsedMilliseconds);
                Console.WriteLine("==============================================");
            } while (index < max);
            Console.WriteLine("End min={0};max={1};index={2};use time {3}", min, max, index, watch.ElapsedMilliseconds);
            watch.Stop();//停止计时
        }
Exemple #7
0
        static void RefreshNewColumn()
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();//开始计时

            List <ZonesSimple> dl = new List <ZonesSimple>();

            List <AuthoritiesSimple>[] ala = new List <AuthoritiesSimple>[16] {
                new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>()
            };
            List <DnsRecordsSimple>[] dla = new List <DnsRecordsSimple>[16] {
                new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>()
            };

            var client = DriverConfiguration.Client;
            var db     = client.GetDatabase(DriverConfiguration.DatabaseNamespace.DatabaseName);
            IMongoCollection <ZonesSimple> cz = db.GetCollection <ZonesSimple>("zones");

            DataTable dt = MySQLHelper.Query("SELECT z.id,z.zone,z.userid,CASE when d.maxfensheng<1 then 0 else 1 end as level,z.nsstate,z.active,z.forcestop from zones as z left join domainlevel as d on z.DomainLevel=d.levelvalue where z.userid<>348672 and (z.Active='N' or z.ForceStop='Y' ) ").Tables[0];

            DataTable dta = MySQLHelper.Query("select a.id,a.zone,host,data,type,ttl,mbox,serial,refresh,retry,expire,minimum ,t.userid,a.zoneid from authorities as a left join zones as t on a.ZoneID=t.id where t.userid<>348672 and (t.Active='N' or t.ForceStop='Y')").Tables[0];

            DataTable dtd = MySQLHelper.Query("select d.id,d.zoneid,d.zone,d.host,d.type,d.data,d.ttl,d.view,d.mx_priority,d.userid,d.active from dnsrecords as d left join zones as t on d.ZoneID=t.id where t.userid<>348672 and (t.Active='N' or t.ForceStop='Y')").Tables[0];

            Console.WriteLine("zones total count  " + dt.Rows.Count);
            Console.WriteLine("authorities total count  " + dta.Rows.Count);
            Console.WriteLine("dnsrecords total count  " + dtd.Rows.Count);

            List <zones> zonesList = DtToList <zones> .ConvertToModel(dt);

            int            deleteCount = 0;
            IList <string> zoneArry    = new List <string>();

            foreach (zones z in zonesList)
            {
                zoneArry.Add(z.zone + ".");

                ZonesSimple zs = Row2ZoneSimple(z);
                dl.Add(zs);
                if ((deleteCount > 0 && deleteCount % 200 == 0) || deleteCount == zonesList.Count)
                {
                    cz.DeleteMany(Builders <ZonesSimple> .Filter.In("domain", zoneArry));
                    string rrcol = StringHelper.CalculateMD5Hash(z.zone + ".").Substring(0, 1);
                    IMongoCollection <DnsRecordsSimple> cd = db.GetCollection <DnsRecordsSimple>(rrcol);
                    cd.DeleteMany(Builders <DnsRecordsSimple> .Filter.In("domain", zoneArry));

                    Console.WriteLine("delete count  " + deleteCount + " use time " + watch.ElapsedMilliseconds);

                    if (dl.Count > 0)
                    {
                        cz.InsertMany(dl);
                        Console.WriteLine("insert zones use time  " + watch.ElapsedMilliseconds);
                    }
                    zoneArry.Clear();
                    dl.Clear();
                }

                deleteCount++;
            }
            Console.WriteLine("delete complete use time " + watch.ElapsedMilliseconds);


            List <authorities> aList = DtToList <authorities> .ConvertToModel(dta);

            List <authorities> drl    = new List <authorities>();
            string             domain = "";

            for (int idx = 0; idx < aList.Count;)
            {
                domain = aList[idx].zone.ToString().ToLower() + ".";
                string collectionname = StringHelper.CalculateMD5Hash(domain).ToLower().Substring(0, 1);
                drl.Add(aList[idx]);
                while (idx < (aList.Count - 1) && aList[idx].zone == aList[idx + 1].zone)
                {
                    drl.Add(aList[idx + 1]);
                    idx++;
                }
                if (drl.Count > 1)
                {
                    foreach (AuthoritiesSimple a in Row2Authorities(drl))
                    {
                        ala[Int32.Parse(collectionname, System.Globalization.NumberStyles.HexNumber)].Add(a);
                    }
                }

                drl.Clear();
                domain = "";
                idx++;
            }
            List <dnsrecords> rList = DtToList <dnsrecords> .ConvertToModel(dtd);

            List <dnsrecords> unList = new List <dnsrecords>();

            foreach (dnsrecords dr in rList)
            {
                if (CheckRecordHost(dr.host, dr.type) && CheckRecordData(dr.data, dr.type, dr.view, dr.host))
                {
                    DnsRecordsSimple d = Row2DnsRecords(dr);
                    string           collectionname = StringHelper.CalculateMD5Hash(d.domain).ToLower().Substring(0, 1);
                    int idx = Int32.Parse(collectionname, System.Globalization.NumberStyles.HexNumber);
                    dla[idx].Add(d);
                }
                else
                {
                    unList.Add(dr);
                }
            }

            Console.WriteLine("start insert use time " + watch.ElapsedMilliseconds);


            for (int i = 0; i < 16; i++)
            {
                IMongoCollection <DnsRecordsSimple> collection = db.GetCollection <DnsRecordsSimple>(i.ToString("x"));
                if (ala[i].Count > 0)
                {
                    collection.InsertMany(ala[i]);
                }
                if (dla[i].Count > 0)
                {
                    collection.InsertMany(dla[i]);
                }
            }
            if (unList.Count > 0)
            {
                Console.WriteLine("uninsert dnsrecords " + unList.Count);
            }
            Console.WriteLine("mission complete   use time " + watch.ElapsedMilliseconds);
        }
Exemple #8
0
        static void ReMoMain()
        {
            List <TempZoneID> temp4 = DtToList <TempZoneID> .ConvertToModel(MySQLHelper.Query("select id as zoneid from Temp where type=4").Tables[0]);

            DataTable dtid = MySQLHelper.Query("select min(id),max(id) from zones").Tables[0];
            long      min  = Convert.ToInt32(dtid.Rows[0][0]);
            long      max  = Convert.ToInt32(dtid.Rows[0][1]);

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();//开始计时
            long index = max;

            do
            {
                DataTable    dt        = MySQLHelper.Query("SELECT z.id,z.zone,z.userid,CASE when d.maxfensheng<1 then 0 else 1 end as level,z.nsstate from zones as z left join domainlevel as d on z.DomainLevel=d.levelvalue where z.userid<>348672 and z.Active='Y' and z.ForceStop='N' and z.id between " + (index - 1000) + " and " + index + "").Tables[0];
                List <zones> zonesList = DtToList <zones> .ConvertToModel(dt);

                List <zones> zl = new List <zones>();
                foreach (zones z in zonesList)
                {
                    if (temp4.FindAll(tz => tz.zoneid == z.id).Count == 0)
                    {
                        zl.Add(z);
                    }
                }
                Console.WriteLine("Data Filter;Use time={0};", watch.ElapsedMilliseconds);

                List <ZonesSimple>         zslist = new List <ZonesSimple>();
                List <AuthoritiesSimple>[] ala    = new List <AuthoritiesSimple>[16] {
                    new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>(), new List <AuthoritiesSimple>()
                };
                List <DnsRecordsSimple>[] dla = new List <DnsRecordsSimple>[16] {
                    new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>(), new List <DnsRecordsSimple>()
                };

                foreach (zones z in zl)
                {
                    ZonesSimple zs = Row2ZoneSimple(z);
                    zslist.Add(zs);

                    string rrcol = StringHelper.CalculateMD5Hash(zs.domain).ToLower().Substring(0, 1);
                    //
                    DataSet ds = MySQLHelper.Query("select id,zone,host,data,type,ttl,mbox,serial,refresh,retry,expire,minimum ," + z.userid + " as userid from authorities where zoneid=" + z.id + " order by type;" +
                                                   "select id,zoneid,zone,host,type,data,ttl,view,mx_priority,userid from dnsrecords where active='Y'and type<>'PTR' and  zoneid= " + z.id + ";");

                    DataTable adt = ds.Tables[0];
                    DataTable rdt = ds.Tables[1];
                    //
                    List <authorities>       alist  = new List <authorities>();
                    List <AuthoritiesSimple> aslist = new List <AuthoritiesSimple>();
                    if (adt.Rows.Count > 0)
                    {
                        aslist = Row2Authorities(DtToList <authorities> .ConvertToModel(adt));
                    }
                    else
                    {
                        break;
                    }
                    //
                    List <dnsrecords> dlist = DtToList <dnsrecords> .ConvertToModel(rdt);

                    List <DnsRecordsSimple> dslist    = new List <DnsRecordsSimple>();
                    List <dnsrecords>       wrongList = new List <dnsrecords>();
                    foreach (dnsrecords d in dlist)
                    {
                        if (CheckRecordData(d.data, d.type, d.view, d.host) && CheckRecordHost(d.host, d.type))
                        {
                            dslist.Add(Row2DnsRecords(d));
                        }
                        else
                        {
                            //记录违法的records
                            wrongList.Add(d);
                        }
                    }
                }


                index = index - 1001;
                Console.WriteLine("Mongo Insert Success; Use time={0};", watch.ElapsedMilliseconds);
                DnsUpdateInsert(zl);

                Console.WriteLine("UpdateQueue Insert Success; Use time={0};", watch.ElapsedMilliseconds);

                Console.WriteLine("min={0};max={1};index={2};", min, max, index);
                Console.WriteLine("==============================================");
            } while (index < max);
            Console.WriteLine("End min={0};max={1};index={2};use time {3}", min, max, index, watch.ElapsedMilliseconds);
            watch.Stop();//停止计时
        }