Beispiel #1
0
        /// <inheritdoc />
        public virtual Task InsertManyAsync(IEnumerable <TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(documents, "documents");

            var models = documents.Select(x => new InsertOneModel <TDocument>(x));
            BulkWriteOptions bulkWriteOptions = options == null ? null : new BulkWriteOptions {
                IsOrdered = options.IsOrdered
            };

            return(BulkWriteAsync(models, bulkWriteOptions, cancellationToken));
        }
        private Task InsertManyAsync(IEnumerable <TDocument> documents, InsertManyOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, Task> bulkWriteAsync)
        {
            Ensure.IsNotNull(documents, nameof(documents));

            var models           = documents.Select(x => new InsertOneModel <TDocument>(x));
            var bulkWriteOptions = options == null ? null : new BulkWriteOptions
            {
                BypassDocumentValidation = options.BypassDocumentValidation,
                IsOrdered = options.IsOrdered
            };

            return(bulkWriteAsync(models, bulkWriteOptions));
        }
        /// <inheritdoc />
        public virtual void InsertMany(IEnumerable <TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(documents, nameof(documents));

            var models = documents.Select(x => new InsertOneModel <TDocument>(x));
            BulkWriteOptions bulkWriteOptions = options == null ? null : new BulkWriteOptions
            {
                BypassDocumentValidation = options.BypassDocumentValidation,
                IsOrdered = options.IsOrdered
            };

            BulkWrite(models, bulkWriteOptions, cancellationToken);
        }
        private void InsertMany(IEnumerable <TDocument> documents, InsertManyOptions options, Action <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions> bulkWrite)
        {
            Ensure.IsNotNull(documents, nameof(documents));

            var models = documents.Select(x => new InsertOneModel <TDocument>(x));
            BulkWriteOptions bulkWriteOptions = options == null ? null : new BulkWriteOptions
            {
                BypassDocumentValidation = options.BypassDocumentValidation,
                IsOrdered = options.IsOrdered
            };

            bulkWrite(models, bulkWriteOptions);
        }
        public async Task Execute()
        {
            Category<ObjectId> category = SelectCategory();
            if (category == null)
            {
                _logger.Error(InnerMessages.CategoryMissing);
                return;
            }

            List<Post<ObjectId>> posts = new List<Post<ObjectId>>();
            List<PostEssentials> postEssencials = ContentProvider.GetPosts(_settings.PostContentPath);

            foreach (PostEssentials item in postEssencials)
            {
                if (item.ShortContent == null)
                {
                    item.ShortContent =
                        ContentMinifier.Minify(item.FullContent, 250, ContentMinifyMode.ToClosestDot);
                }

                var post = new Post<ObjectId>()
                {
                    ContentID = ObjectId.GenerateNewId(),
                    CategoryID = _settings.CategoryID,
                    AuthorID = _settings.Author.ID,
                    AuthorName = _settings.Author.Name,
                    Title = item.Title,
                    Url = Translit.RussianToTranslitUrl(item.Title),
                    CommentsCount = 0,
                    ViewsCount = 0,
                    FullContent = item.FullContent,
                    ShortContent = item.ShortContent,
                    HasImage = true,
                    IsPublished = true,
                    AddTimeUtc = DateTime.UtcNow,
                    PublishTimeUtc = DateTime.UtcNow,
                    IsIndexed = false
                };
                post.CreateUpdateNonce();
                posts.Add(post);

                if (item.ImageFile != null)
                {
                    using (Stream file = item.ImageFile.OpenRead())
                    {
                        PipelineResult imageResult = await _previewQueries.CreateStaticImage(file, post.Url);
                    }
                }

                await UploadContentImages(post);
            }

            var insertOptions = new InsertManyOptions() { IsOrdered = false };
            await _context.Posts.InsertManyAsync(posts, insertOptions);

        }
 /// <inheritdoc />
 public virtual Task InsertManyAsync(IClientSessionHandle session, IEnumerable <TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(InsertManyAsync(documents, options, (requests, bulkWriteOptions) => BulkWriteAsync(session, requests, bulkWriteOptions, cancellationToken)));
 }
 /// <inheritdoc />
 public virtual void InsertMany(IClientSessionHandle session, IEnumerable <TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     InsertMany(documents, options, (requests, bulkWriteOptions) => BulkWrite(session, requests, bulkWriteOptions, cancellationToken));
 }
Beispiel #8
0
 public static Task InsertManyAsync <T, TK>(this IMongoCollection <T> instance, IEnumerable <T> documents, InsertManyOptions options = null, CancellationToken cancellation = default)
     where T : DocumentBase <TK>
 {
     return(instance.InsertManyAsync(documents, options, cancellation));
 }
Beispiel #9
0
 public static void AddMany <TDocument>(this IMongoCollection <TDocument> collection, IEnumerable <TDocument> documents, InsertManyOptions options = null)
 {
     collection.InsertMany(documents, options);
 }