public int TableUseCheckServer(object model) { int changetablenum = 0; var item = model as SqlServerItemXml; var basemodel = DBConfig.GetBaseXmlConfig(item.BaseNumber); if (item != null) { ManagerConfig serverconfig = new ManagerConfig(); var databaselist = DBConfig.GetDatabaseItemXmlConfigList(basemodel, item.Number); string connstr = DBProxyAction.GetConnStr(basemodel, item); foreach (var item2 in databaselist) { var tablelist = DBConfig.GetTableItemXmlConfigList(basemodel, item2.Number); foreach (var item3 in tablelist) { var restatus = DBProxy.GetDBAccess(item.DBType).TableExists(connstr, item2.DatabaseName, item3.TableName); if (item3.IsUse != restatus) { changetablenum++; serverconfig.TableChangeIsUse(item3, restatus); } Console.WriteLine("检查数据表连接,服务器:" + item.ServerName + ",数据库:" + item2.DatabaseName + ",表:" + item3.TableName + ",status:" + restatus); } } } Console.WriteLine("服务器:" + item.ServerName + ",涉及表总数:" + changetablenum); return(1); }
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); }
public void DatabaseUseCheckAll(SqlBaseItemXml basemodel) { var serverlist = DBConfig.GetServerItemXmlConfigList(basemodel); int servernum = serverlist.Count; int databasenum = 0; ManagerConfig serverconfig = new ManagerConfig(); foreach (var item in serverlist) { var databaselist = DBConfig.GetDatabaseItemXmlConfigList(basemodel, item.Number); string connstr = DBProxyAction.GetConnStr(basemodel, item); foreach (var item2 in databaselist) { var restatus = DBProxy.GetDBAccess(item.DBType).DatabaseExists(connstr, item2.DatabaseName); if (item2.IsUse != restatus) { databasenum++; serverconfig.DatabaseChangeIsUse(item2, restatus); } Console.WriteLine("检查数据库连接,服务器:" + item.ServerName + ",数据库:" + item2.DatabaseName + ",status:" + restatus); } } new ManagerConfig().SaveConfig(basemodel); Console.WriteLine("测试连接执行完成,操作服务器:" + servernum + ",操作数据库:" + databasenum); }
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); }
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); }
public int ServerCacheClearItem(object model) { var item = model as SqlServerItemXml; var basemodel = DBConfig.GetBaseXmlConfig(item.BaseNumber); string connstr = DBProxyAction.GetConnStr(basemodel, item); Console.WriteLine("操作服务器开始:" + item.ServerName); DBProxy.GetDBAccess(item.DBType).ServerCacheClear(connstr); Console.WriteLine("操作服务器完成:" + item.ServerName); return(1); }
public int ServerConnectionCheckItem(object model) { var item = model as SqlServerItemXml; var basemodel = DBConfig.GetBaseXmlConfig(item.BaseNumber); bool connectionstatus = SocketHelper.TestConnection(item.ServerName, item.ServerPort, basemodel.SocketMillisecondsTimeout); if (connectionstatus) { string connstr = DBProxyAction.GetConnStr(basemodel, item); connectionstatus = DBProxy.GetDBHelper(item.DBType).ConnectionIsUse(connstr); } new ManagerConfig().ServerChangeIsUse(item, connectionstatus); Console.WriteLine("服务器:" + item.ServerName + ",isuse:" + connectionstatus); return(1); }
public int DetachTask(object model) { var item = model as SqlServerItemXml; int revalue = 0; var basemodel = DBConfig.GetBaseXmlConfig(item.BaseNumber); var databaselist = DBConfig.GetDatabaseItemXmlConfigList(basemodel, item.Number); foreach (var item2 in databaselist) { string connstr = DBProxyAction.GetConnStr(basemodel, item); DBProxy.GetDBAccess(item.DBType).DatabaseSPDetach(connstr, item2.DatabaseName); revalue++; Console.WriteLine("分离服务器:" + item.ServerName + ",数据库:" + item2.DatabaseName); } return(revalue); }
public int TableDelIndexServer(object model) { int changetablenum = 0; int changetableindexnum = 0; var item = model as SqlServerItemXml; var basemodel = DBConfig.GetBaseXmlConfig(item.BaseNumber); if (item != null) { var databaselist = DBConfig.GetDatabaseItemXmlConfigList(basemodel, item.Number); foreach (var item2 in databaselist) { var tablelist = DBConfig.GetTableItemXmlConfigList(basemodel, item2.Number); DBProxyAction.GetConnStr(basemodel, item, item2); string conndatabasestr = DBProxyAction.GetConnStr(basemodel, item, item2); foreach (var item3 in tablelist) { int validnum = 0; foreach (var itemfield in basemodel.FieldIndexList) { string indexname = basemodel.IndexPrev + item3.TableName + itemfield; if (!DBProxy.GetDBAccess(item.DBType).TableIndexExists(conndatabasestr, item2.DatabaseName, item3.TableName, indexname)) { validnum++; changetableindexnum++; DBProxy.GetDBAccess(item.DBType).TableIndexDel(conndatabasestr, item3.TableName, indexname); Console.WriteLine("删除索引服务器:" + item.ServerName + ",数据库:" + item2.DatabaseName + ",表:" + item3.TableName); } } if (validnum > 0) { changetablenum++; } } } } Console.WriteLine("服务器:" + item.ServerName + ",涉及表总数:" + changetablenum + ",添加索引总数:" + changetableindexnum); return(1); }
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); }
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); }