Beispiel #1
0
        public Scope(ScopeDef?scopeDef, ICollectionFactory collectionFactory, BucketBase bucket, ILogger <Scope> logger)
        {
            _bucket = bucket ?? throw new ArgumentNullException(nameof(bucket));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (scopeDef != null)
            {
                Name = scopeDef.name;
                Id   = scopeDef.uid;

                _collections = new ConcurrentDictionary <string, ICouchbaseCollection>(
                    scopeDef.collections
                    .Select(p => collectionFactory.Create(bucket, this, Convert.ToUInt32(p.uid, 16), p.name))
                    .ToDictionary(x => x.Name, v => v));
            }
            else
            {
                Name = DefaultScopeName;
                Id   = DefaultScopeId;

                _collections = new ConcurrentDictionary <string, ICouchbaseCollection>();
                _collections.TryAdd(CouchbaseCollection.DefaultCollectionName,
                                    collectionFactory.Create(bucket, this, null, CouchbaseCollection.DefaultCollectionName));
            }

            _queryContext = $"{_bucket.Name}.{Name}";
        }
Beispiel #2
0
        public IEnumerable <IScope> CreateScopes(BucketBase bucket, Manifest manifest)
        {
            if (bucket == null)
            {
                throw new ArgumentNullException(nameof(bucket));
            }
            if (manifest == null)
            {
                throw new ArgumentNullException(nameof(manifest));
            }

            foreach (var scopeDef in manifest.scopes)
            {
                var collections = new List <ICollection>();
                foreach (var collectionDef in scopeDef.collections)
                {
                    collections.Add(_collectionFactory.Create(bucket,
                                                              Convert.ToUInt32(collectionDef.uid, 16),
                                                              collectionDef.name,
                                                              scopeDef.name));
                }

                yield return(new Scope(scopeDef.name, scopeDef.uid, collections, bucket, _scopeLogger));
            }
        }
Beispiel #3
0
 public ICouchbaseCollection this[string name]
 {
     get
     {
         _logger.LogDebug("Fetching collection {collectionName}.", name);
         return(_collections.GetOrAdd(name,
                                      key => _collectionFactory.Create(_bucket, this, key)));
     }
 }
Beispiel #4
0
        private Collection GetCollection(CreatePieceModel model)
        {
            Collection collection = null;

            if (model.CollectionId >= 0)
            {
                collection = repository.GetCollection(model.CollectionId.Value);
            }
            else if (model.CollectionId < 0 && !string.IsNullOrWhiteSpace(model.CollectionName))
            {
                collection = repository.GetCollections().SingleOrDefault(g => g.Name == model.CollectionName && g.MuseumId == model.MuseumId);
                if (collection == null)
                {
                    collection = collectionFactory.Create(model.CollectionName, model.MuseumId);

                    repository.AddCollection(collection);
                }
            }

            return(collection);
        }