Example #1
0
        /// <summary>
        /// 集合配置
        /// </summary>
        /// <param name="database">集合所属数据库</param>
        /// <param name="collectionName">集合名称</param>
        /// <param name="defaultDocumentType">默认的文档类型</param>
        protected MagpieCollectionSettings(MagpieDatabase database, string collectionName, Type defaultDocumentType)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }
            if (collectionName == null)
            {
                throw new ArgumentNullException("collectionName");
            }
            if (defaultDocumentType == null)
            {
                throw new ArgumentNullException("defaultDocumentType");
            }

            _database            = database;
            _collectionName      = collectionName;
            _defaultDocumentType = defaultDocumentType;
        }
Example #2
0
        /// <summary>
        /// 获取指定配置的数据库
        /// </summary>
        /// <param name="databaseSettings">数据库配置</param>
        /// <returns>数据库</returns>
        protected virtual MagpieDatabase GetDatabase(MagpieDatabaseSettings databaseSettings)
        {
            if (databaseSettings == null)
            {
                throw new ArgumentNullException("databaseSettings");
            }

            lock (_serverLock)
            {
                MagpieDatabase database;
                if (!_databases.TryGetValue(databaseSettings, out database))
                {
                    database = new MagpieDatabase(this, databaseSettings);
                    _databases.Add(databaseSettings, database);

                    Directory.CreateDirectory(databaseSettings.Path);
                }
                return(database);
            }
        }
        /// <summary>
        /// 集合
        /// </summary>
        /// <param name="database">集合所属数据库</param>
        /// <param name="settings">集合配置</param>
        protected MagpieCollection(MagpieDatabase database, MagpieCollectionSettings settings)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (!database.IsCollectionNameValid(settings.CollectionName))
            {
                throw new ArgumentException("Invalid collection name.");
            }

            _database = database;
            _settings = settings;
            _name     = settings.CollectionName;
            _tree     = GetIndexTree();
            _tree.Commit();
        }