示例#1
0
 protected Processor(DbController controller, string hostString)
 {
     this.hostString = hostString;
     dbInterfaces = new Dictionary<string, DatabaseInterface>();
     this.controller = controller;
     state = 0;
     authenticationTries = 0;
     dbCallback = OnDatabaseEvent;
 }
示例#2
0
        internal DbSystem(DbController controller, string name, IDbConfig config, IDatabase database)
        {
            this.name = name;
            this.controller = controller;
            this.config = config;
            this.Database = database;
            internalCounter = 0;

            // Register the shut down delegate,
            database.Context.OnShutdown += new EventHandler(Shutdown);

            // Enable commands to the database system...
            database.Context.IsExecutingCommands = true;
        }
示例#3
0
 public DefaultLocalBootable(DbController controller, string databaseName)
 {
     this.controller = controller;
     this.databaseName = databaseName;
 }
示例#4
0
        // ---------- Private methods ----------
        /// <summary>
        /// Disposes of all the resources associated with this system.
        /// </summary>
        /// <remarks>
        /// It may only be called from the shutdown delegate registered 
        /// in the constructor.
        /// </remarks>
        private void InternalDispose()
        {
            if (connections != null && connections.Count > 0) {
                ArrayList list = new ArrayList(connections.Keys);
                for (int i = list.Count - 1; i >= 0; i--) {
                    int id = (int) list[i];
                    IDbConnection connection = connections[id] as IDbConnection;

                    try {
                        if (connection != null)
                            connection.Dispose();
                    } catch(Exception) {
                        // we ignore this ...
                    }
                }
            }

            connections = null;
            controller = null;
            config = null;
        }
示例#5
0
 public DatabaseShutdownCallback(DbController controller, IDatabase database)
 {
     this.controller = controller;
     this.database = database;
 }
示例#6
0
        /// <summary>
        /// Creates a new instance of <see cref="DbController"/> to the
        /// given path on the underlying filesystem.
        /// </summary>
        /// <param name="config">The initial configurations that will
        /// be applied to the subsequent databases within the context.</param>
        /// <remarks>
        /// If the given path doesn't point to any valid database context
        /// this will generate it by creating a configuration file which
        /// will encapsulate all the default configurations and those
        /// provided in this method.
        /// </remarks>
        /// <returns>
        /// Returns an instance of <see cref="DbController"/> which points
        /// to the given path.
        /// </returns>
        public static DbController Create(IDbConfig config)
        {
            StorageType storageType = GetStorageType(config);

            if (config == null)
                config = DbConfig.Default;

            IDbConfig mainConfig;

            if (storageType == StorageType.File) {
                string path = config.BasePath() ?? Environment.CurrentDirectory;

                string configFile = Path.GetFileName(path);

                // we only allow the file extension .conf
                string ext = Path.GetExtension(configFile);
                if (String.Compare(ext, FileExtension, StringComparison.OrdinalIgnoreCase) == 0) {
                    path = Path.GetDirectoryName(path);
                } else {
                    configFile = DefaultConfigFileName;
                }

                // if the directory doesn't exist we will create one...
                if (path != null && !Directory.Exists(path))
                    Directory.CreateDirectory(path);

                mainConfig = GetConfig(config, path, configFile);
                mainConfig.BasePath(path);
            } else {
                mainConfig = config;
            }

            var controller = new DbController(mainConfig);

            if (storageType == StorageType.File) {
                // done with the main configuration... now look for the databases...
                string path = config.BasePath();
                string[] subDirs = Directory.GetDirectories(path);
                foreach (string dir in subDirs) {
                    IDbConfig dbConfig = GetConfig(mainConfig, dir, null);
                    if (dbConfig == null)
                        continue;

                    var dbPath = dir.Substring(dir.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                    string name = dbConfig.DatabaseName();
                    if (name == null)
                        name = dbPath;

                    dbConfig.DatabasePath(dbPath);

                    if (controller.IsDatabaseRegistered(name))
                        throw new InvalidOperationException("The database '" + name + "' was already registered.");

                    IDatabase database = CreateDatabase(dbConfig, name);
                    controller.databases[name] = database;

                    if (database.Exists) {
                        var callback = new DatabaseShutdownCallback(controller, database);
                        database.Context.OnShutdown += (callback.Execute);
                    }
                }
            }

            return controller;
        }
示例#7
0
 public LocalSystem(DbController controller)
 {
     Controller = controller;
 }