コード例 #1
0
        /// <summary>
        /// Create a new connection to an existing instance.
        /// </summary>
        /// <param name="database">The database to connect to.</param>
        /// <param name="mode">The mode to connect to the database in.</param>
        /// <returns>A new connection to the database.</returns>
        private Connection CreateNewConnection(string database, DatabaseOpenMode mode)
        {
            Instance       instance       = this.instances[database].Instance;
            string         connectionName = Path.GetFileName(database);
            ConnectionBase connection;

            if (DatabaseOpenMode.ReadOnly == mode)
            {
                connection = new ReadOnlyConnection(instance, connectionName, database);
            }
            else
            {
                Debug.Assert(DatabaseOpenMode.ReadWrite == mode, "Unknown DatabaseOpenMode");
                connection = new ReadWriteConnection(instance, connectionName, database);
            }

            this.instances[database].Connections.Add(connection);
            connection.Disposed += this.OnConnectionClose;

            this.Tracer.TraceVerbose("created new connection '{0}'", connectionName);
            this.Tracer.TraceVerbose("database '{0}' has {1} connections", database, this.instances[database].Connections.Count);
            return(connection);
        }
コード例 #2
0
ファイル: ConnectionManager.cs プロジェクト: nzdunic/ravendb
        /// <summary>
        /// Create a new connection to an existing instance.
        /// </summary>
        /// <param name="database">The database to connect to.</param>
        /// <param name="mode">The mode to connect to the database in.</param>
        /// <returns>A new connection to the database.</returns>
        private Connection CreateNewConnection(string database, DatabaseOpenMode mode)
        {
            Instance instance = this.instances[database].Instance;
            string connectionName = Path.GetFileName(database);
            ConnectionBase connection;
            if (DatabaseOpenMode.ReadOnly == mode)
            {
                connection = new ReadOnlyConnection(instance, connectionName, database);
            }
            else
            {
                Debug.Assert(DatabaseOpenMode.ReadWrite == mode, "Unknown DatabaseOpenMode");
                connection = new ReadWriteConnection(instance, connectionName, database);
            }

            this.instances[database].Connections.Add(connection);
            connection.Disposed += this.OnConnectionClose;

            this.Tracer.TraceVerbose("created new connection '{0}'", connectionName);
            this.Tracer.TraceVerbose("database '{0}' has {1} connections", database, this.instances[database].Connections.Count);
            return connection;
        }