public static string GetTableName(this ICURDProperties updateProperties, string tableIndex = null, int id = 0) { var tableAttribute = updateProperties.GetCustomerAttributes <MatchedTableAttribute>().FirstOrDefault(w => w.ID == id); var tableName = tableAttribute?.Name; if (string.IsNullOrEmpty(tableName)) { tableName = updateProperties.GetType().Name; } //tableName = tableName.Trim();//Support Use Sencond Type TableIndex For Table FullName var ITableSharding = updateProperties as ITableSharding; string tableNameFormat = string.Empty; if (ITableSharding != null) { tableNameFormat = string.Format(tableName, ITableSharding.__TableIndex__); if (tableIndex == null) { return(tableNameFormat); } } if (tableName.StartsWith("{") && tableName.EndsWith("}")) { tableName = AppSetting.GetConfig(tableName.TrimStart('{').TrimEnd('}')); } if (tableName.Contains("{") && tableName.Contains("}")) { tableNameFormat = string.Format(tableName, tableIndex); return(tableNameFormat); } return(tableName); }
static CommonHelper() { string sLogSql = AppSetting.GetConfig("daoextend:logsql"); if (string.Compare(sLogSql, "true", true) == 0) { LogSql = true; } else { LogSql = false; } }
//DataTable dt; //OracleConnection cn; //OracleCommand cmd; //OracleDataAdapter da; public static OracleConnection Conn(/*string strconn*/) { string strcn = AppSetting.GetConfig("ConnectionStrings:SyncOrcl"); OracleConnection cn = new OracleConnection(strcn); try { cn.Open(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(cn); }
/// <summary> /// 获取数据库连接 /// </summary> /// <returns></returns> public static IDbConnection CreateConnection() { IDbConnection connection = null; //获取配置进行转换 var type = AppSetting.GetConfig("ComponentDbType"); var dbType = GetDataBaseType(type); //DefaultDatabase 根据这个配置项获取对应连接字符串 var database = AppSetting.GetConfig("DefaultDatabase"); if (string.IsNullOrEmpty(database)) { database = "sqlserver";//默认配置 } // var strConn = AppConfig.Configuration.GetConnectionString(database); var strConn = AppSetting.GetConnectionString(database); switch (dbType) { case DatabaseType.SqlServer: connection = new System.Data.SqlClient.SqlConnection(strConn); break; case DatabaseType.MySql: // connection = new MySql.Data.MySqlClient.MySqlConnection(strConn); break; case DatabaseType.Npgsql: // connection = new Npgsql.NpgsqlConnection(strConn); break; case DatabaseType.Sqlite: // connection = new SQLiteConnection(strConn); break; case DatabaseType.Oracle: // connection = new Oracle.ManagedDataAccess.Client.OracleConnection(strConn); //connection = new System.Data.OracleClient.OracleConnection(strConn); break; case DatabaseType.DB2: //connection = new System.Data.OleDb.OleDbConnection(strConn); break; } return(connection); }
public static string GetConnectionKey(this ICURDProperties updateProperties, int id = 0) { var tableAttribute = updateProperties.GetCustomerAttributes <MatchedTableAttribute>().FirstOrDefault(w => w.ID == id); var connectionKey = tableAttribute?.ConnectionKey; if (string.IsNullOrEmpty(connectionKey)) { return(connectionKey); } connectionKey = connectionKey.Trim(); if (connectionKey.StartsWith('{') && connectionKey.EndsWith('}')) { connectionKey = AppSetting.GetConfig(connectionKey.TrimStart('{').TrimEnd('}')); } return(connectionKey); }
public static IDbConnection GetDBConnection(this ICURDProperties cURDProperties, int id = 0) { var tableAttribute = cURDProperties.GetMatchedTableAttribute(); if (tableAttribute == null) { throw new Exception("TableAttribute Not Found"); } DBServerType dBServerType = tableAttribute.DBServerType; string connectionKey = tableAttribute.ConnectionKey; string connectionString = AppSetting.GetConfig(connectionKey); string connectionStringFormat = connectionString; var IDataBaseSharding = cURDProperties as IDataBaseSharding; if (IDataBaseSharding != null) { connectionStringFormat = string.Format(connectionString, IDataBaseSharding.__DataBaseIndex__); } return(DBConnectionFactory.GetDbConnection(connectionStringFormat, dBServerType)); }
static void Main(string[] args) { string host = AppSetting.GetConfig("ConnectionSocket:Host"); int prot = Convert.ToInt32(AppSetting.GetConfig("ConnectionSocket:Port")); MarketClient socket = new MarketClient(); socket.Init(host, prot); while (true) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("=> "); Console.ForegroundColor = ConsoleColor.White; string cmd = Console.ReadLine(); string[] parms = cmd.Split('.', StringSplitOptions.RemoveEmptyEntries); switch (parms[0]) { case "exit": //todo 推出程序 break; } } }
public static List <T> SelectPropertiesByKey <T>(this ISelectProperties selectProperties, int id = 0, string tableIndex = null, List <List <object> > listsIn = null, string sqlAppend = "", params string[] properties) { try { if (selectProperties == null) { return(default(List <T>)); } string connectionKey = selectProperties.GetConnectionKey(); string connectionString = AppSetting.GetConfig(connectionKey); using (IDbConnection dbConnection = selectProperties.GetDBConnection(id)) { dbConnection.Open(); var sql = selectProperties.GetInSelectSql(id, tableIndex, listsIn, sqlAppend, properties); //Logger.Info(sql); //if (listsIn == null) return(dbConnection.Query <T>(sql, selectProperties).ToList()); //else // return dbConnection.Query<T>(sql).ToList(); } } catch (Exception ex) { throw ex; } }