Example #1
0
 /// <summary>
 /// 获取指定配置的集合
 /// </summary>
 /// <typeparam name="TDocument">文档类型</typeparam>
 /// <param name="collectionSettings">集合配置</param>
 /// <returns>集合</returns>
 protected virtual MagpieCollection <TDocument> GetCollection <TDocument>(MagpieCollectionSettings <TDocument> collectionSettings) where TDocument : IMagpieDocumentId
 {
     lock (_databaseLock)
     {
         MagpieCollection collection;
         if (!_collections.TryGetValue(collectionSettings, out collection))
         {
             collection = new MagpieCollection <TDocument>(this, collectionSettings);
             _collections.Add(collectionSettings, collection);
         }
         return((MagpieCollection <TDocument>)collection);
     }
 }
        /// <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();
        }
Example #3
0
        /// <summary>
        /// 获取指定名称的集合
        /// </summary>
        /// <typeparam name="TDocument">文档类型</typeparam>
        /// <param name="collectionName">集合名称</param>
        /// <returns>集合</returns>
        public virtual MagpieCollection <TDocument> GetCollection <TDocument>(string collectionName) where TDocument : IMagpieDocumentId
        {
            var collectionSettings = new MagpieCollectionSettings <TDocument>(this, collectionName);

            return(GetCollection(collectionSettings));
        }