public MongoValidationCacheDataRepository(IMongoDatabaseProvider databaseProvider)
        {
            if (databaseProvider == null)
            {
                throw new ArgumentNullException(nameof(databaseProvider));
            }

            string collectionName = CollectionNameFactory.Create <ValidatedObject>();
            var    settings       = new MongoCollectionSettings
            {
                WriteConcern = WriteConcern.Unacknowledged
            };

            this.collection = databaseProvider.Create().GetCollection <ValidatedObject>(collectionName, settings);

            this.updateOptions = new UpdateOptions
            {
                IsUpsert = true,
                BypassDocumentValidation = false
            };
        }
Beispiel #2
0
        private async Task ImportMediatypesToDatabase(ExtensionJson[] mediatypes)
        {
            string collectionName = CollectionNameFactory.Create <Mediatype>();
            var    collection     = this.db.GetCollection <Mediatype>(collectionName);

            foreach (var mediatype in mediatypes)
            {
                try
                {
                    await collection.InsertOneAsync(new Mediatype
                    {
                        FileExtension = mediatype.Extension,
                        Description   = mediatype.Description,
                        Mimetype      = mediatype.Mimetype,
                        Mimesubtype   = mediatype.Mimesubtype
                    });
                }
                catch (Exception e)
                {
                    this.exceptions.Enqueue(e);
                }
            }
        }
        private async Task <object> CreateIndicesToTaxonRankTypesCollection()
        {
            string collectionName = CollectionNameFactory.Create <MongoTaxonRankTypeEntity>();

            var collection = this.db.GetCollection <MongoTaxonRankTypeEntity>(collectionName);

            var indexOptions = new CreateIndexOptions
            {
                Unique = true,
                Sparse = false
            };

            var result = await collection.Indexes
                         .CreateOneAsync(
                Builders <MongoTaxonRankTypeEntity> .IndexKeys.Ascending(t => t.RankType),
                indexOptions);

            result = await collection.Indexes
                     .CreateOneAsync(
                Builders <MongoTaxonRankTypeEntity> .IndexKeys.Ascending(t => t.Name),
                indexOptions);

            return(result);
        }