Exemplo n.º 1
0
        private void Init(object obj)
        {
            int[] para = obj == null ? new int[] { 1, 1 } : (int[])obj;
            using (XXF.Db.DbConn dbconn = XXF.Db.DbConn.CreateConn(XXF.Db.DbType.SQLSERVER, "192.168.17.236", "cert_test_main", "sa", "Xx~!@#"))
            {
                dbconn.Open();
                string sql_count = "select count(1) from tb_customer";
                int    allcount  = 40000;// (int)dbconn.ExecuteScalar(sql_count, null);

                int threadsizecount = (int)Math.Ceiling(allcount / (double)para[1]);

                int pagesize = 1000;

                int start = (para[0]) * threadsizecount;
                int end   = (para[0] + 1) * threadsizecount;

                for (int i = start; i < end; i = i + pagesize)
                {
                    string    sql = "select top " + pagesize + " * from (select row_number() over(order by f_id) as Rownum,* from tb_customer ) A where A.Rownum between " + (i + 1) + " and " + (end) + "";
                    DataTable tb  = dbconn.SqlToDataTable(sql, null);
                    foreach (DataRow dr in tb.Rows)
                    {
                        count_me[para[0]]++;
                        string pwd = dr["f_dlmm"].ToString();
                        try
                        {
                            pwd = XXF.Db.LibCrypto.DeDES(pwd);
                        }
                        catch (Exception ex)
                        {
                        }
                        var token = sp.Login(dr["f_yhzh"].ToString(), pwd);
                        if (token != null)
                        {
                            lock (tokens)
                                tokens.Add(token);
                            Console.WriteLine(token.token);
                        }
                        else
                        {
                            Console.WriteLine("error");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Init(object obj)
        {
            int[] para = obj == null ? new int[] { 1, 1 } : (int[])obj;
            using (XXF.Db.DbConn dbconn = XXF.Db.DbConn.CreateConn(XXF.Db.DbType.SQLSERVER, "192.168.17.236", "cert_test_main", "sa", "Xx~!@#"))
                using (XXF.Db.DbConn qxdbconn = XXF.Db.DbConn.CreateConn(XXF.Db.DbType.SQLSERVER, "192.168.17.236", "dyd_new_qx", "sa", "Xx~!@#"))
                {
                    dbconn.Open();
                    qxdbconn.Open();
                    int allcount = 1200000;// (int)dbconn.ExecuteScalar(sql_count, null);

                    int threadsizecount = (int)Math.Ceiling(allcount / (double)para[1]);

                    int pagesize = 200;

                    int start = (para[0]) * threadsizecount;
                    int end   = (para[0] + 1) * threadsizecount;

                    StringBuilder sb = new StringBuilder();
                    for (int i = start; i < end; i = i + pagesize)
                    {
                        sb.Clear();
                        string    sql = "select top " + pagesize + " * from (select row_number() over(order by f_id) as Rownum,* from tb_customer ) A where A.Rownum between " + (i + 1) + " and " + (end) + "";
                        DataTable tb  = dbconn.SqlToDataTable(sql, null);
                        foreach (DataRow dr in tb.Rows)
                        {
                            count_me[para[0]]++;
                            string pwd   = dr["f_dlmm"].ToString();
                            string yhzh  = dr["f_yhzh"].ToString();
                            string id    = dr["f_id"].ToString();
                            string yhxm  = dr["f_yhxm"].ToString();
                            string token = Guid.NewGuid().ToString().Replace("-", "");
                            sb.AppendFormat("insert into usertoken (token,userid,id,username,appid,createtime,expires) " +
                                            "  values('{0}','{1}','{2}','{3}','Customer','2015-07-01','2015-08-31');\r\n", token, yhzh, id, yhxm);
                        }
                        qxdbconn.ExecuteSql(sb.ToString(), null);
                    }
                }
        }
Exemplo n.º 3
0
        private void PrepareTokens(int allcount)
        {
            Console.WriteLine("正在准备内存token...");
            Thread mainthrad = new Thread(() =>
            {
                using (XXF.Db.DbConn qxdbconn = XXF.Db.DbConn.CreateConn(XXF.Db.DbType.SQLSERVER, "192.168.17.236", "dyd_new_qx", "sa", "Xx~!@#"))
                {
                    qxdbconn.Open();


                    // int allcount = 999000;// (int)dbconn.ExecuteScalar(sql_count, null);

                    int pagesize = 200000;

                    StringBuilder sb = new StringBuilder();
                    int i            = 0;
                    while (true)
                    {
                        sb.Clear();
                        string sql   = "select  * from (select row_number() over(order by token) as Rownum,* from usertoken ) A where A.Rownum between " + (i + 1) + " and " + (i + pagesize) + "";
                        DataTable tb = qxdbconn.SqlToDataTable(sql, null);
                        foreach (DataRow dr in tb.Rows)
                        {
                            sp.Add(new CertSdk.Token()
                            {
                                appid      = dr["appid"].ToString(),
                                createtime = XXF.Db.LibConvert.ObjToDateTime(dr["createtime"]),
                                expires    = XXF.Db.LibConvert.ObjToDateTime(dr["expires"]),
                                id         = dr["id"].ToString(),
                                token      = dr["token"].ToString(),
                                userid     = dr["userid"].ToString(),
                                username   = dr["username"].ToString()
                            });
                            _PrepareTokens_count++;
                            if (_PrepareTokens_count >= allcount)
                            {
                                break;
                            }
                        }
                        if (_PrepareTokens_count >= allcount)
                        {
                            break;
                        }
                    }
                }
            });
            Thread m = new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(3000);
                    Console.WriteLine("当前准备token总数={0}", _PrepareTokens_count);
                    if (mainthrad.ThreadState == System.Threading.ThreadState.Stopped)
                    {
                        return;
                    }
                }
            });

            mainthrad.Start();
            m.Start();
            m.Join();

            Console.WriteLine("准备内存token完成!");
        }
Exemplo n.º 4
0
        private void GetTestUsers(int count)
        {
            Console.WriteLine("正在准备登录用户...");
            Thread maint = new Thread(() =>
            {
                using (XXF.Db.DbConn qxdbconn = XXF.Db.DbConn.CreateConn(XXF.Db.DbType.SQLSERVER, "192.168.17.236", "cert_test_main", "sa", "Xx~!@#"))
                {
                    qxdbconn.Open();
                    int allcount = (int)qxdbconn.ExecuteScalar("select count(1) from testuser", null);
                    if (allcount >= count)
                    {
                        string sql   = "select top " + count + " * from testuser";
                        DataTable tb = qxdbconn.SqlToDataTable(sql, null);
                        foreach (DataRow dr in tb.Rows)
                        {
                            willtestusers.Add(dr["f_yhzh"].ToString());
                            _GetTestUsers_count++;
                        }
                        return;
                    }
                }

                int pagesize = 50;
                using (XXF.Db.DbConn qxdbconn = XXF.Db.DbConn.CreateConn(XXF.Db.DbType.SQLSERVER, "192.168.17.236", "cert_test_main", "sa", "Xx~!@#"))
                {
                    qxdbconn.Open();
                    int allcount = (int)qxdbconn.ExecuteScalar("select count(1) from tb_customer", null);
                    for (int i = 0; i < count; i = i + pagesize)
                    {
                        Random r        = new Random();
                        int start_index = r.Next(1, allcount - pagesize);
                        string sql      = "select top " + pagesize + " A.f_yhzh from (select row_number() over(order by f_id) as Rownum,f_yhzh from tb_customer ) A where A.Rownum >=" + start_index + "";
                        DataTable tb    = qxdbconn.SqlToDataTable(sql, null);
                        foreach (DataRow dr in tb.Rows)
                        {
                            willtestusers.Add(dr["f_yhzh"].ToString());
                            _GetTestUsers_count++;
                        }
                    }
                }
                WriteTestUserToDB();
            });
            Thread m = new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(3000);
                    Console.WriteLine("当前准备测试用户总数={0}", _GetTestUsers_count);
                    if (maint.ThreadState == System.Threading.ThreadState.Stopped)
                    {
                        return;
                    }
                }
            });

            maint.Start();
            m.Start();
            m.Join();

            Console.WriteLine("准备登录用户完成!");
        }