コード例 #1
0
 public void testAddRow(SqlBaseItemXml basemodel)
 {
     try
     {
         ManagerConfig servicemanagerconfig = new ManagerConfig();
         int           writenum             = 0;
         for (int i = 0; i < 100000000; i++)
         {
             DBPosition position = new DBPosition();
             var        getbool  = position.GetPosition(basemodel);
             servicemanagerconfig.SaveConfigServer(basemodel);
             servicemanagerconfig.SaveConfigDatabase(basemodel);
             servicemanagerconfig.SaveConfigTable(basemodel);
             if (getbool)
             {
                 var serveritem = DBConfig.GetServerItemXmlConfig(basemodel, position.currentservernumber);
                 DBWrite.AddBulkRow(basemodel, serveritem, position.currentconnstrdatabase, testBulkRowData(basemodel, position.currenttable), position.currentdatabasenumber, position.currenttablenumber, basemodel.FieldIndexList);
                 servicemanagerconfig.SaveConfigField(basemodel);
                 Console.WriteLine("" + (++writenum));
             }
             else
             {
                 Console.WriteLine("请配置更多服务器后写入");
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #2
0
        public long GetCount(SqlBaseItemXml basemodel, ConditionFieldModel condition, ref long sqlnum)
        {
            sqlnum = 0;
            long      rownum     = 0;
            DataTable dt         = new DataTable();
            DBRule    serverrule = new DBRule();
            List <MatchServerList> serverlist = serverrule.GetMatchServer(basemodel, condition);

            if (serverlist != null && serverlist.Count > 0)
            {
                List <TaskDataParam> taskdataparam = new List <TaskDataParam>();
                foreach (var item in serverlist)
                {
                    var servermodel = DBConfig.GetServerItemXmlConfig(basemodel, item.ServerNumber);
                    if (servermodel != null)
                    {
                        TaskDataParam tempparam = new TaskDataParam();
                        tempparam.servername = servermodel.ServerName;
                        tempparam.dbtype     = servermodel.DBType;
                        tempparam.connstr    = DBProxyAction.GetConnStr(basemodel, servermodel);
                        tempparam.sqlstr     = DBProxyAction.GetSqlCount(servermodel, item, condition);
                        taskdataparam.Add(tempparam);
                    }
                }
                DBTask servicetask = new DBTask();
                Console.WriteLine("满足条件的数据库表:" + taskdataparam.Count);
                rownum = servicetask.SyncTaskManagerSum(taskdataparam, 50, false);
                sqlnum = servicetask.runnumcurrent;
            }
            return(rownum);
        }
コード例 #3
0
        public bool Update(SqlBaseItemXml basemodel, long rowid, Dictionary <string, object> updatefieldlist)
        {
            var fieldmodel = DBConfig.GetFieldXmlConfig(basemodel).SqlFieldList.Where(m => m.FieldName == basemodel.PrimarykeyName && m.ValueMin <= rowid && m.ValueMax >= rowid).FirstOrDefault();

            if (fieldmodel == null)
            {
                return(false);
            }
            var servermodel   = DBConfig.GetServerItemXmlConfig(basemodel, fieldmodel.ServerNumber);
            var databasemodel = DBConfig.GetDatabaseItemXmlConfig(basemodel, fieldmodel.DatabaseNumber);
            var tablemodel    = DBConfig.GetTableItemXmlConfig(basemodel, fieldmodel.TableNumber);

            return(DBProxyAction.Update(basemodel, rowid, servermodel, databasemodel, tablemodel, updatefieldlist));
        }
コード例 #4
0
        public bool Delete(SqlBaseItemXml basemodel, long rowid)
        {
            bool revalue    = false;
            bool changexml  = false;
            var  fieldmodel = DBConfig.GetFieldXmlConfig(basemodel).SqlFieldList.Where(m => m.FieldName == basemodel.PrimarykeyName && m.ValueMin <= rowid && m.ValueMax >= rowid).FirstOrDefault();

            if (fieldmodel == null)
            {
                return(false);
            }
            var servermodel   = DBConfig.GetServerItemXmlConfig(basemodel, fieldmodel.ServerNumber);
            var databasemodel = DBConfig.GetDatabaseItemXmlConfig(basemodel, fieldmodel.DatabaseNumber);
            var tablemodel    = DBConfig.GetTableItemXmlConfig(basemodel, fieldmodel.TableNumber);

            revalue = DBProxyAction.Delete(basemodel, rowid, servermodel, databasemodel, tablemodel, fieldmodel);
            if (revalue)
            {
                if (fieldmodel.ValueMin == rowid)
                {
                    DBConfig.FieldRemove(basemodel, fieldmodel);
                    fieldmodel.ValueMin = rowid + 1;
                    DBConfig.FieldAdd(basemodel, fieldmodel);
                    changexml = true;
                }
                else if (fieldmodel.ValueMax == rowid)
                {
                    DBConfig.FieldRemove(basemodel, fieldmodel);
                    fieldmodel.ValueMax = rowid - 1;
                    DBConfig.FieldAdd(basemodel, fieldmodel);
                    changexml = true;
                }
            }
            if (changexml)
            {
                new ManagerConfig().SaveConfigField(basemodel);
            }
            return(revalue);
        }
コード例 #5
0
        public DataTable GetList(SqlBaseItemXml basemodel, ConditionFieldModel condition, ref long sqlnum)
        {
            sqlnum = 0;
            long      getmaxnum               = 500;
            long      getrowcount             = 0;
            DataTable dt                      = new DataTable();
            DBRule    serverrule              = new DBRule();
            List <MatchServerList> serverlist = serverrule.GetMatchServer(basemodel, condition);

            if (serverlist != null && serverlist.Count > 0)
            {
                List <TaskDataParam> taskdataparam = new List <TaskDataParam>();
                foreach (var item in serverlist)
                {
                    var servermodel = DBConfig.GetServerItemXmlConfig(basemodel, item.ServerNumber);
                    if (servermodel != null)
                    {
                        TaskDataParam tempparam = new TaskDataParam();
                        tempparam.servername = servermodel.ServerName;
                        tempparam.dbtype     = servermodel.DBType;
                        tempparam.connstr    = DBProxyAction.GetConnStr(basemodel, servermodel);
                        tempparam.sqlstr     = DBProxyAction.GetSqlList(servermodel, item, condition, getmaxnum);
                        taskdataparam.Add(tempparam);
                    }
                }
                Console.WriteLine("满足条件的数据库表:" + taskdataparam.Count);
                foreach (var itemparam in taskdataparam)
                {
                    Console.WriteLine("访问服务器:" + itemparam.servername);
                    var dttemp = DBProxy.GetDBHelper(itemparam.dbtype).GetDataDable(itemparam.connstr, itemparam.sqlstr);
                    sqlnum++;
                    if (dttemp != null && dttemp.Rows.Count > 0)
                    {
                        var dttempcount = dttemp.Rows.Count;
                        if (getrowcount > 0)
                        {
                            foreach (DataRow dtrow in dttemp.Rows)
                            {
                                if (getrowcount >= getmaxnum)
                                {
                                    return(dt);
                                }
                                getrowcount++;
                                DataRow r = dt.NewRow();
                                r.ItemArray = dtrow.ItemArray;
                                dt.Rows.Add(r);
                            }
                        }
                        else
                        {
                            getrowcount = dttemp.Rows.Count;
                            dt          = dttemp;
                        }
                    }
                    if (getrowcount >= getmaxnum)
                    {
                        return(dt);
                    }
                }
            }
            return(dt);
        }