Exemplo n.º 1
0
        public DataTable testBulkRowData(SqlBaseItemXml basemodel, string tablename)
        {
            DataTable bulkdata   = DBConfig.GetTableStruct(basemodel, tablename);
            Random    random     = new Random();
            long      rowmin     = 0;
            long      rowcurrent = 0;
            long      rowmax     = 0;
            int       rownum     = 10000;

            long rowidrrr = DBConfig.GetRowId(basemodel.Number);

            DBConfig.UpdateRowId(basemodel.Number, rownum);
            rowmin     = rowidrrr + 1;
            rowmax     = rowmin + rownum;
            rowcurrent = rowmin;
            for (int i = 0; i < rownum; i++)
            {
                DataRow newRow;
                newRow = bulkdata.NewRow();
                #region
                newRow["id"]    = rowcurrent++;
                newRow["num1"]  = rowcurrent / 100000;
                newRow["num2"]  = random.Next(10000);
                newRow["num3"]  = random.NextDouble();
                newRow["str11"] = tablename + i;
                #endregion
                bulkdata.Rows.Add(newRow);
            }
            return(bulkdata);
        }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
0
        public bool SqlBaseClear(SqlBaseItemXml basemodel)
        {
            bool revalue    = false;
            var  serverlist = DBConfig.GetServerItemXmlConfigList(basemodel);

            if (serverlist != null)
            {
                foreach (var serveritem in serverlist)
                {
                    string connstr      = DBProxyAction.GetConnStr(basemodel, serveritem);
                    var    databaselist = DBConfig.GetDatabaseItemXmlConfigList(basemodel, serveritem.Number);
                    if (databaselist != null)
                    {
                        foreach (var databaseitem in databaselist)
                        {
                            DBProxy.GetDBAccess(serveritem.DBType).DatabaseDrop(connstr, databaseitem.DatabaseName);
                        }
                    }
                }
                ManagerConfig servermanagerconfig = new ManagerConfig();
                //servermanagerconfig.InitServerXml(basemodel);
                servermanagerconfig.InitDatabaseXml(basemodel);
                servermanagerconfig.InitTableXml(basemodel);
                servermanagerconfig.InitFieldXml(basemodel);
            }
            return(revalue);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public bool GetServer(SqlBaseItemXml basemodel)
        {
            var templist = DBConfig.GetServerXmlConfig(basemodel).SqlServerList.Where(m => m.IsUse == true && m.IsWrite == true).ToList();

            foreach (SqlServerItemXml item in templist)
            {
                long currentStorageSize = 0;
                currentserver        = item.ServerName;
                currentservernumber  = item.Number;
                currentconnstrserver = DBProxyAction.GetConnStr(basemodel, item);
                try
                {
                    currentStorageSize = DBProxy.GetDBAccess(item.DBType).DatabaseStorageSizeAll(currentconnstrserver, basemodel.DatabasePrev);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("error:" + ex.Message);
                    new ManagerConfig().ServerChangeIsUse(item);
                    return(false);
                }
                if ((item.StorageSize - item.RetainStorageSize) > currentStorageSize)
                {
                    if (GetDatabase(basemodel, item))
                    {
                        return(isposition);
                    }
                }
                else
                {
                    new ManagerConfig().ServerChangeIsWrite(item);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public bool GetTable(SqlBaseItemXml basemodel, SqlServerItemXml item, SqlDatabaseItemXml item2)
        {
            var tablelist  = DBConfig.GetTableItemXmlConfigList(basemodel, item2.Number);
            var tablelist2 = tablelist.Where(m => m.IsUse == true && m.IsWrite == true).ToList();

            foreach (var tableobjectitem2 in tablelist2)
            {
                var temp3      = DBProxy.GetDBAccess(item.DBType).TableStorageSize(currentconnstrdatabase, tableobjectitem2.TableName);
                var temp3count = DBProxy.GetDBAccess(item.DBType).TableCount(currentconnstrdatabase, tableobjectitem2.TableName);
                if (tableobjectitem2.StorageSize > temp3 && tableobjectitem2.RowNum > temp3count)
                {
                    currenttable       = tableobjectitem2.TableName;
                    currenttablenumber = tableobjectitem2.Number;
                    isposition         = true;
                    return(isposition);
                }
                else
                {
                    new ManagerConfig().TableChangeIsWrite(tableobjectitem2);
                }
            }
            if (item2.TableNum > tablelist.Count() && item2.IsCreate)
            {
                var temptable = DBWrite.AddTable(currentconnstrdatabase, item, item2);
                currenttable       = temptable.TableName;
                currenttablenumber = temptable.Number;
                isposition         = true;
                return(isposition);
            }
            return(isposition);
        }
Exemplo n.º 7
0
        public List <MatchServerList> GetMatchServer(SqlBaseItemXml basemodel, ConditionFieldModel conditionfield)
        {
            int matchnum = 0;
            List <MatchServerList> ServerList = new List <MatchServerList>();
            List <SqlFieldItemXml> fieldlist  = new List <SqlFieldItemXml>();

            if (conditionfield != null && conditionfield.List != null && conditionfield.List.Count > 0)
            {
                List <SqlFieldItemXml> templist = new List <SqlFieldItemXml>();
                foreach (var condition in conditionfield.List)
                {
                    long valuemin = condition.ValueMin;
                    long valuemax = condition.ValueMax;
                    if (matchnum < 1)
                    {
                        var tempfieldlist = DBConfig.GetFieldXmlConfig(basemodel).SqlFieldList.Where(m => m.FieldName == condition.FieldName).ToList();
                        foreach (var item in tempfieldlist)
                        {
                            if (GetMatchValid(item, condition.ValueMin, condition.ValueMax))
                            {
                                ServerList.Add(GetMatchObject(item));
                            }
                        }
                    }
                    else
                    {
                        int conditionvalidnum = 0;
                        foreach (var serverlist in ServerList.ToList())
                        {
                            var tempfield = DBConfig.GetFieldXmlConfig(basemodel).SqlFieldList.Where(m => m.TableNumber == serverlist.TableNumber && m.FieldName == condition.FieldName).ToList();
                            if (tempfield != null)
                            {
                                foreach (var itemfield in tempfield)
                                {
                                    if (GetMatchValid(itemfield, condition.ValueMin, condition.ValueMax))
                                    {
                                        conditionvalidnum++;
                                        break;
                                    }
                                }
                            }
                            if (conditionvalidnum < 1)
                            {
                                ServerList.Remove(serverlist);
                            }
                        }
                    }

                    matchnum++;
                }
            }

            return(ServerList);
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
0
        public static SqlTableItemXml AddTable(string currentconnstr, SqlServerItemXml item, SqlDatabaseItemXml item2)
        {
            var             basemodel      = DBConfig.GetBaseXmlConfig(item.BaseNumber);
            SqlTableItemXml tabletempmodel = new SqlTableItemXml();

            tabletempmodel.BaseNumber     = item.BaseNumber;
            tabletempmodel.ServerNumber   = item.Number;
            tabletempmodel.DataBaseNumber = item2.Number;
            tabletempmodel.Number         = DBConfig.GetTableNumber;
            tabletempmodel.TableName      = basemodel.TablePrev + tabletempmodel.Number;
            tabletempmodel.IsWrite        = true;
            tabletempmodel.IsUse          = true;
            tabletempmodel.RowNum         = basemodel.DefaultTableRowNum;
            tabletempmodel.StorageSize    = (item2.StorageSize - item2.StorageSize / 5) / item2.TableNum;
            DBConfig.TableAdd(basemodel, tabletempmodel);
            DBProxy.GetDBHelper(item.DBType).ExecuteSql(currentconnstr, DBConfig.GetTableSql(basemodel, tabletempmodel.TableName));
            return(tabletempmodel);
        }
Exemplo n.º 10
0
        public static SqlDatabaseItemXml AddDatabase(string currentconnstrserver, SqlServerItemXml item)
        {
            var basemodel = DBConfig.GetBaseXmlConfig(item.BaseNumber);
            SqlDatabaseItemXml databasetempmodel = new SqlDatabaseItemXml();

            databasetempmodel.BaseNumber       = item.BaseNumber;
            databasetempmodel.ServerNumber     = item.Number;
            databasetempmodel.Number           = DBConfig.GetDatabaseNumber;
            databasetempmodel.DatabaseName     = basemodel.DatabasePrev + databasetempmodel.Number;
            databasetempmodel.StorageSize      = ((item.StorageSize - item.StorageSize / 5) - item.RetainStorageSize) / 10;
            databasetempmodel.TableNum         = basemodel.DefaultTableNum;
            databasetempmodel.IsWrite          = true;
            databasetempmodel.IsUse            = true;
            databasetempmodel.IsCreate         = true;
            databasetempmodel.StorageDirectory = item.StorageDirectory;
            DBConfig.DatabaseAdd(basemodel, databasetempmodel);

            DBProxy.GetDBAccess(item.DBType).DatabaseCreate(currentconnstrserver, databasetempmodel.DatabaseName, databasetempmodel.StorageDirectory);
            return(databasetempmodel);
        }
Exemplo n.º 11
0
 public static void AddBulkRow(SqlBaseItemXml basemodel, SqlServerItemXml servermodel, string connstr, DataTable bulkdata, long databasenumber, long tablenumber, List <string> fieldtotal)
 {
     if (fieldtotal != null && fieldtotal.Count > 0)
     {
         var fieldlist = DBConfig.GetFieldXmlConfig(basemodel);
         foreach (var fieldname in fieldtotal)
         {
             string currentfieldname = fieldname;
             long   rowmin           = CommonHelper.ToLong(bulkdata.Compute("min(" + currentfieldname + ")", ""));
             long   rowmax           = CommonHelper.ToLong(bulkdata.Compute("max(" + currentfieldname + ")", ""));
             var    fileldobjecttemp = fieldlist.SqlFieldList.Where(m => m.FieldName == currentfieldname && m.TableNumber == tablenumber).FirstOrDefault();
             if (fileldobjecttemp != null)
             {
                 DBConfig.FieldRemove(basemodel, fileldobjecttemp);
                 if (fileldobjecttemp.ValueMin > rowmin)
                 {
                     fileldobjecttemp.ValueMin = rowmin;
                 }
                 if (fileldobjecttemp.ValueMax < rowmax)
                 {
                     fileldobjecttemp.ValueMax = rowmax;
                 }
                 DBConfig.FieldAdd(basemodel, fileldobjecttemp);
             }
             else
             {
                 SqlFieldItemXml fileldmodel = new SqlFieldItemXml();
                 fileldmodel.BaseNumber     = servermodel.BaseNumber;
                 fileldmodel.ServerNumber   = servermodel.Number;
                 fileldmodel.DatabaseNumber = databasenumber;
                 fileldmodel.TableNumber    = tablenumber;
                 fileldmodel.Number         = DBConfig.GetFieldNumber;
                 fileldmodel.FieldName      = currentfieldname;
                 fileldmodel.ValueMin       = rowmin;
                 fileldmodel.ValueMax       = rowmax;
                 DBConfig.FieldAdd(basemodel, fileldmodel);
             }
         }
     }
     DBProxy.GetDBHelper(servermodel.DBType).WriteBlockDataToDB(connstr, bulkdata);
 }
Exemplo n.º 12
0
        public bool GetDatabase(SqlBaseItemXml basemodel, SqlServerItemXml item)
        {
            var databaselist  = DBConfig.GetDatabaseItemXmlConfigList(basemodel, item.Number);
            var databaselist2 = databaselist.Where(m => m.IsUse == true && m.IsWrite == true).ToList();

            foreach (var item2 in databaselist2)
            {
                currentdatabase        = item2.DatabaseName;
                currentdatabasenumber  = item2.Number;
                currentconnstrdatabase = DBProxyAction.GetConnStr(basemodel, item, item2);
                var temp2      = DBProxy.GetDBAccess(item.DBType).DatabaseStorageSize(currentconnstrdatabase, item2.DatabaseName);
                var temp2count = DBConfig.GetTableXmlConfig(basemodel).SqlTableList.Where(m => m.DataBaseNumber == item2.Number).Count();
                if (item2.StorageSize > temp2 && item2.TableNum >= temp2count && GetTable(basemodel, item, item2))
                {
                    return(isposition);
                }
                else
                {
                    new ManagerConfig().DatabaseChangeIsWrite(item2);
                }
            }
            if (item.DatabaseNum > databaselist.Count() && item.IsCreate)
            {
                var tempdata = DBWrite.AddDatabase(currentconnstrserver, item);
                currentdatabase        = tempdata.DatabaseName;
                currentdatabasenumber  = tempdata.Number;
                currentconnstrdatabase = DBProxyAction.GetConnStr(basemodel, item, tempdata);
                var temptable = DBWrite.AddTable(currentconnstrdatabase, item, tempdata);
                currenttable       = temptable.TableName;
                currenttablenumber = temptable.Number;
                isposition         = true;
                return(isposition);
            }
            else
            {
                new ManagerConfig().ServerChangeIsWrite(item);
            }

            return(isposition);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
 public static SqlFieldItemXml GetFieldItemXmlConfig(SqlBaseItemXml basemodel, long Number, bool IsDelete = false)
 {
     return(DBConfig.GetFieldXmlConfig(basemodel).SqlFieldList.Where(m => m.IsDelete == IsDelete && m.Number == Number).FirstOrDefault());
 }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
 public static SqlServerItemXml GetServerItemXmlConfig(SqlBaseItemXml basemodel, long Number, bool IsUse = true)
 {
     return(DBConfig.GetServerXmlConfig(basemodel).SqlServerList.Where(m => m.IsUse == IsUse && m.Number == Number).FirstOrDefault());
 }
Exemplo n.º 17
0
 public static List <SqlFieldItemXml> GetFieldItemXmlConfigList(SqlBaseItemXml basemodel, long TableNumber, bool IsDelete = false)
 {
     return(DBConfig.GetFieldXmlConfig(basemodel).SqlFieldList.Where(m => m.IsDelete == IsDelete && m.TableNumber == TableNumber).ToList());
 }
Exemplo n.º 18
0
 public static List <SqlTableItemXml> GetTableItemXmlConfigList(SqlBaseItemXml basemodel, long DatabaseNumber, bool IsUse = true)
 {
     return(DBConfig.GetTableXmlConfig(basemodel).SqlTableList.Where(m => m.IsUse == IsUse && m.DataBaseNumber == DatabaseNumber).ToList());
 }
Exemplo n.º 19
0
 public static List <SqlDatabaseItemXml> GetDatabaseItemXmlConfigList(SqlBaseItemXml basemodel, long ServerNumber, bool IsUse = true)
 {
     return(DBConfig.GetDatabaseXmlConfig(basemodel).SqlDatabaseList.Where(m => m.IsUse == IsUse && m.ServerNumber == ServerNumber).ToList());
 }
Exemplo n.º 20
0
 public static List <SqlServerItemXml> GetServerItemXmlConfigList(SqlBaseItemXml basemodel, bool IsUse = true)
 {
     return(DBConfig.GetServerXmlConfig(basemodel).SqlServerList.Where(m => m.IsUse == IsUse).ToList());
 }