Esempio n. 1
0
        public static bool Initialize(string configurationPath, string modulesDirectory = null)
        {
            var assemblyDir = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
            var path        = configurationPath;

            if (!Path.IsPathRooted(path))
            {
                path = Path.Combine(assemblyDir, configurationPath);
            }

            if (!string.IsNullOrEmpty(path))
            {
                log.Info("Reading Database Configuration File From '" + path + "'");

                var modulesDir = assemblyDir;
                if (!string.IsNullOrEmpty(modulesDirectory))
                {
                    modulesDir = modulesDirectory;
                    if (!Path.IsPathRooted(modulesDir))
                    {
                        modulesDir = Path.Combine(assemblyDir, modulesDir);
                    }
                }

                log.Info("Reading Database Modules From '" + modulesDir + "'");

                var modules = FindModules(modulesDir);
                if (modules != null)
                {
                    foreach (var module in modules)
                    {
                        try
                        {
                            if (module.Initialize(path))
                            {
                                log.Info(module.Name + " Database Module Initialize Successfully");
                                Module = module;
                                return(true);
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Trace(ex);
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Change the strategy type
        /// </summary>
        /// <param name="type"></param>
        public IDatabase ChangeStrategy(Type type)
        {
            try
            {
                var obj = Activator.CreateInstance(type);
                this._strategyContext = ( IDatabaseModule )obj;
            }
            catch (Exception error)
            {
                Framework.EventBus.Publish(error);
            }

            return(this);
        }
Esempio n. 3
0
        public static bool Initialize(string databaseConfigurationPath)
        {
            MySQLModule module = new MySQLModule();

            if (module != null)
            {
                if (module.Initialize(databaseConfigurationPath))
                {
                    Module = module;
                }
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        public static bool Initialize(DatabaseConfiguration config)
        {
            var assemblyDir = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);

            if (config != null && !string.IsNullOrEmpty(assemblyDir))
            {
                if (Verbose)
                {
                    log.Info("Reading Database Modules From '" + assemblyDir + "'");
                }

                var modules = FindModules(assemblyDir);
                if (modules != null)
                {
                    foreach (var module in modules)
                    {
                        try
                        {
                            if (module.Initialize(config))
                            {
                                if (Verbose)
                                {
                                    log.Info(module.Name + " Database Module Initialize Successfully");
                                }
                                Module        = module;
                                Configuration = config;
                                return(true);
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Trace(ex);
                        }
                    }
                }
            }

            return(false);
        }
 public DatabaseLoaderController(DatabaseLoaderControllerDescription description, IApplication application) : base(description, application)
 {
     ControllerModule = Application.GetModule <IControllerModule>();
     DatabaseModule   = Application.GetModule <IDatabaseModule>();
 }
Esempio n. 6
0
 /// <summary>
 /// Defines a new Database Helper with a user-defined module and immediate sets up login information.
 /// </summary>
 /// <param name="type">The type of the underlying database</param>
 /// <param name="username">The id of the user.</param>
 /// <param name="password">The password to the database.</param>
 /// <param name="databasename">The name of the database.</param>
 /// <param name="serverURL">The url of the server hosting the database.</param>
 public DBHelper(IDatabaseModule module, string username, string password, string databasename, string serverURL)
     : this(module)
 {
     SetLoginInformation(username, password, databasename, serverURL);
 }
Esempio n. 7
0
 /// <summary>
 /// Defines a new database helper with a user-defined module.
 /// </summary>
 /// <param name="module">The desired module.</param>
 public DBHelper(IDatabaseModule module)
 {
     setDBModule(module);
 }
Esempio n. 8
0
 /// <summary>
 /// Sets the type of the database. 
 /// </summary>
 /// <param name="type">DatabaseType: The type of the underlying database.</param>
 public void setDBType(DatabaseType type)
 {
     databaseType = type;
     switch (type)
     {
         case DatabaseType.MicrosoftSQLServer:
             module = new MicrosoftSQLServerModule(this);
             break;
         case DatabaseType.Simulation:
             module = new SimulationModule();
             break;
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Sets the module to a user-defined module.
 /// </summary>
 /// <param name="module">The desired module.</param>
 public void setDBModule(IDatabaseModule module)
 {
     databaseType = DatabaseType.SelfDefined;
     this.module = module;
 }