示例#1
0
 private static void loadMappingInfo( DbConfig dbc )
 {
     if (dbc.Mapping.Count == 0) return;
     foreach (MappingInfo x in dbc.Mapping) {
         dbc.addMapping( x );
     }
 }
示例#2
0
        private static DatabaseType getDbType( String dbname, String connectionString, DbConfig result )
        {
            foreach (KeyValuePair<String, String> kv in result.DbType) {
                if (kv.Key == dbname) return DbTypeChecker.GetFromString( kv.Value );
            }

            DatabaseType dbtype = DbTypeChecker.GetDatabaseType( connectionString );
            return dbtype;
        }
示例#3
0
        private static void checkConnectionString( DbConfig result )
        {
            logger.Info( "checkConnectionString..." );

            if (result.ConnectionStringTable == null) return;

            Dictionary<String, ConnectionString> connStringMap = new Dictionary<String, ConnectionString>();

            Dictionary<String, String> newString = new Dictionary<String, String>();
            foreach (KeyValuePair<String, String> kv in result.ConnectionStringTable) {

                String connectionString = kv.Value;
                DatabaseType dbtype = getDbType( kv.Key, connectionString, result );

                ConnectionString objConnString = new ConnectionString {
                    Name = kv.Key,
                    StringContent = connectionString,
                    DbType = dbtype
                };

                connStringMap.Add( kv.Key, objConnString );

                logger.Info( "connectionString:" + connectionString );

                IDatabaseDialect dialect = DataFactory.GetDialect( dbtype );

                if ((dbtype == DatabaseType.Access)) {
                    String connectionItem = dialect.GetConnectionItem( connectionString, ConnectionItemType.Database );
                    logger.Info( "database path original:" + connectionItem );
                    if (connectionItem == null) throw new Exception( "没有设置access地址:" + connectionString );

                    if (IsRelativePath( connectionItem )) {
                        connectionItem = PathHelper.Map( strUtil.Join( SystemInfo.ApplicationPath, connectionItem ) );
                        logger.Info( "database path now:" + connectionItem );
                        String newConnString = String.Format( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", connectionItem );

                        newString.Add( kv.Key, newConnString );

                    }
                }
            }

            foreach (KeyValuePair<String, String> kv in newString) {
                result.ConnectionStringTable[kv.Key] = kv.Value;
                connStringMap[kv.Key].StringContent = kv.Value;
            }

            result.SetConnectionStringMap( connStringMap );
        }
示例#4
0
 public static void Reset()
 {
     _instance = loadConfig( getConfigPath() );
 }
示例#5
0
        private static void loadMappingInfo( DbConfig dbc )
        {
            if (dbc.Mapping.Count == 0) return;
            foreach (Dictionary<String, object> dic in dbc.Mapping) {

                MappingInfo mi = new MappingInfo();

                if (dic.ContainsKey( "name" )) mi.TypeName = dic["name"].ToString();
                if (dic.ContainsKey( "database" )) mi.Database = dic["database"].ToString();
                if (dic.ContainsKey( "table" )) mi.Table = dic["table"].ToString();

                dbc.addMapping( mi );
            }
        }
示例#6
0
        private static DatabaseType getDbType(String dbname, String connectionString, DbConfig result)
        {
            foreach (KeyValuePair <String, Object> kv in result.DbType)
            {
                if (kv.Key == dbname)
                {
                    return(DbTypeChecker.GetFromString(kv.Value.ToString()));
                }
            }

            DatabaseType dbtype = DbTypeChecker.GetDatabaseType(connectionString);

            return(dbtype);
        }