public IICCodeTable <K, V> GetCodeTable <K, V>(string tableName, Action <IICCodeTable <K, V> > onUpdate) where V : IICCodeTableItem { if (IICConfigurationManager.Loader == null) { throw new InvalidOperationException("No loader yet, You *MUST* call ServiceSettings.InitService() at First"); } try { IICConfigTableBuffer buffer = IICConfigurationManager.Loader.LoadConfigTable(tableName); if (buffer == null) { throw new ConfigurationNotFoundException(IICConfigType.Table, tableName); } IICCodeTable <K, V> table = new IICCodeTable <K, V>(buffer); table.RunAfterLoad(); if (onUpdate != null) { onUpdate(table); } return(table); } catch (Exception ex) { throw new ConfigurationFailedException(IICConfigType.Table, tableName, ex); } }
public static IICConfigTableBuffer LoadConfigTableFromDatabase(string tableName) { Database hadb = DatabaseManager.GetDatabase("im_gcdb"); string[] parameters = { "@TableName" }; string loadParam; string databaseName; DateTime version; using (DataReader reader = hadb.SpExecuteReader("USP_CenterLoadConfigTable", parameters, tableName)) { if (!reader.Read()) { throw new ConfigurationNotFoundException(IICConfigType.Table, tableName); } databaseName = (string)reader["DatabaseName"]; loadParam = (string)reader["LoadParam"]; version = (DateTime)reader["Version"]; } string[] parameters2 = { "@TableName" }; Database db = DatabaseManager.GetDatabase(databaseName); DataTable table = db.SpExecuteTable("USP_LoadConfigTable", parameters2, loadParam); IICConfigTableBuffer buffer = new IICConfigTableBuffer(); buffer.TableName = tableName; buffer.Version = version; int columnCount = table.Columns.Count; buffer.ColumnNames = new string[columnCount]; for (int i = 0; i < columnCount; i++) { buffer.ColumnNames[i] = table.Columns[i].ColumnName; } buffer.Rows = new List <RpcClass <string[]> >(); foreach (DataRow dataRow in table.Rows) { string[] row = new string[columnCount]; for (int i = 0; i < columnCount; i++) { row[i] = dataRow[table.Columns[i]].ToString(); } buffer.Rows.Add(new RpcClass <string[]>(row)); } return(buffer); }
public static IICConfigTableBuffer LoadConfigTableFromDatabase(string tableName) { Database hadb = DatabaseManager.GetDatabase("IICHADB"); string[] parameters = { "@TableName" }; string loadParam; string databaseName; DateTime version; using (DataReader reader = hadb.SpExecuteReader("USP_CenterLoadConfigTable", parameters, tableName)) { if (!reader.Read()) { throw new ConfigurationNotFoundException(IICConfigType.Table, tableName); } databaseName = (string)reader["DatabaseName"]; loadParam = (string)reader["LoadParam"]; version = (DateTime)reader["Version"]; } string[] parameters2 = { "@TableName" }; Database db = DatabaseManager.GetDatabase(databaseName); DataTable table = db.SpExecuteTable("USP_LoadConfigTable", parameters2, loadParam); IICConfigTableBuffer buffer = new IICConfigTableBuffer(); buffer.TableName = tableName; buffer.Version = version; int columnCount = table.Columns.Count; buffer.ColumnNames = new string[columnCount]; for (int i = 0; i < columnCount; i++) { buffer.ColumnNames[i] = table.Columns[i].ColumnName; } buffer.Rows = new List<RpcClass<string[]>>(); foreach (DataRow dataRow in table.Rows) { string[] row = new string[columnCount]; for (int i = 0; i < columnCount; i++) { row[i] = dataRow[table.Columns[i]].ToString(); } buffer.Rows.Add(new RpcClass<string[]>(row)); } return buffer; }