Exemple #1
0
 private void createDatabaseAndSaveConnectionString()
 {
     _connectionString = DatabaseBuilder.ConnectionStringPrefix + DatabaseBuilder.BuildAccessDb4o();
     logger.Info("connection String : " + _connectionString);
     DbConfig.SaveConnectionString(_connectionString);
     logger.Info("the connection String is resetted");
 }
Exemple #2
0
 public DbConfig()
 {
     this.ConnectionStringTable = new Dictionary <String, object>();
     this.AssemblyList          = new List <object>();
     this.DbType          = new Dictionary <String, object>();
     this.Interceptor     = new List <object>();
     this.IsCheckDatabase = true;
     this.ContextCache    = true;
     this.Mapping         = new List <object>();
     string[] ddlfiles = System.IO.Directory.GetFiles(PathHelper.Map("~/"), "*.dll");
     if (ddlfiles.Length == 0)
     {
         ddlfiles = System.IO.Directory.GetFiles(PathHelper.Map("~/bin"), "*.dll");
     }
     foreach (string dll in ddlfiles)
     {
         string str = System.IO.Path.GetFileName(dll).Replace(".dll", "");
         this.AssemblyList.Add(str);
     }
     //this.AssemblyList.Add("XCore");
     this.DbType.Add("default", "access");
     this.ConnectionStringTable.Add("default", DatabaseBuilder.BuildAccessDb4oWithPrefix());
 }
Exemple #3
0
 public void CheckDatabase()
 {
     logger.Info("begin check database");
     if (strUtil.IsNullOrEmpty(_connectionString))
     {
         logger.Info("connection String is empty. begin to create access database and set connection string");
         createDatabaseAndSaveConnectionString();
     }
     else
     {
         String connectionItem = DataFactory.GetDialect(DatabaseType.Access).GetConnectionItem(_connectionString, ConnectionItemType.Database);
         if (strUtil.IsNullOrEmpty(connectionItem))
         {
             logger.Info("connection String is found, but database is empty. begin to create access database and set connection string");
             createDatabaseAndSaveConnectionString();
         }
         else if (!File.Exists(connectionItem))
         {
             logger.Info("ConnectionString:" + _connectionString);
             logger.Info("the database [" + connectionItem + "] is not found. begin to create access database and set connection string");
             DatabaseBuilder.BuildAccessDb4o(connectionItem);
         }
     }
 }
Exemple #4
0
        public static void CreateDbConfig()
        {
            DbConfig config = new DbConfig();

            string[] ddlfiles = System.IO.Directory.GetFiles(PathHelper.Map("~/"), "*.dll");
            if (ddlfiles.Length == 0)
            {
                ddlfiles = System.IO.Directory.GetFiles(PathHelper.Map("~/bin"), "*.dll");
            }
            foreach (string dll in ddlfiles)
            {
                config.AssemblyList.Add(System.IO.Path.GetFileName(dll).Replace(".dll", ""));
            }
            //this.AssemblyList.Add("XCore");
            config.DbType.Add("default", "access");
            config.ConnectionStringTable.Add("default", DatabaseBuilder.ConnectionStringPrefix + DatabaseBuilder.BuildAccessDb4o());

            String cfgPath = getConfigPath();

            file.Write(cfgPath, JsonString.ConvertObject(config, true));
            loadMappingInfo(config);
            checkConnectionString(config);
            DbConfig.Instance = config;
            MappingClass.loadByReflection();
            MappingClass.checkMultiDB(MappingClass.Instance);
        }
Exemple #5
0
        void UpdateDatabase()
        {
            if (Model == null)
            {
                Log.Warn("Cannot update database. Model doesn't exist");
                return;
            }
            Log.Inform("Updating Database {0}", Model.DatabaseName);

            DatabaseBuilder = new DatabaseBuilder(Database);
            DatabaseBuilder.Log = Log;
            var dbName = Model.DatabaseName;
            var model = Model;
            if (model.GetTables().FirstOrDefault<MetaTable>() == null)
            {
                Log.Inform("No Tables found, nothing to update...");
                return;
                //throw Common.CreateDatabaseFailedBecauseOfContextWithNoTables(model.DatabaseName);
            }
            foreach (MetaTable table4 in model.GetTables())
            {
                DatabaseBuilder.BuildTable(table4);
            }
            ProcessPendingActions();
            foreach (MetaTable table5 in model.GetTables())
            {
                DatabaseBuilder.BuildForeignKeys(table5);
            }
            ProcessPendingActions();
        }