/// <summary>
        /// Appends a project stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="projection">The projection.</param>
        /// <returns>
        /// The fluent aggregate interface.
        /// </returns>
        public static IAggregateFluent <BsonDocument> Project <TResult>(this IAggregateFluent <TResult> aggregate, ProjectionDefinition <TResult, BsonDocument> projection)
        {
            Ensure.IsNotNull(aggregate, "aggregate");
            Ensure.IsNotNull(projection, "projection");

            return(aggregate.Project <BsonDocument>(projection));
        }
        /// <summary>
        /// Appends a project stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="TNewResult">The type of the new result.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="projection">The projection.</param>
        /// <returns>
        /// The fluent aggregate interface.
        /// </returns>
        public static IAggregateFluent <TNewResult> Project <TResult, TNewResult>(this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TNewResult> > projection)
        {
            Ensure.IsNotNull(aggregate, nameof(aggregate));
            Ensure.IsNotNull(projection, nameof(projection));

            return(aggregate.Project <TNewResult>(new ProjectExpressionProjection <TResult, TNewResult>(projection, aggregate.Options.TranslationOptions)));
        }
        /// <summary>
        /// Appends a project stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="TNewResult">The type of the new result.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="projection">The projection.</param>
        /// <returns>
        /// The fluent aggregate interface.
        /// </returns>
        public static IAggregateFluent <TNewResult> Project <TResult, TNewResult>(this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TNewResult> > projection)
        {
            Ensure.IsNotNull(aggregate, "aggregate");
            Ensure.IsNotNull(projection, "projection");

            return(aggregate.Project <TNewResult>(new ProjectExpressionProjection <TResult, TNewResult>(projection)));
        }
Esempio n. 4
0
        public List <T> GetMany(FilterDefinition <T> filter, SortDefinition <T> sorter, ProjectionDefinition <T> projection, ref PagerInfo pagerInfo)
        {
            IMongoCollection <T> myCollection = GetCollection();

            AggregateOptions opts = new AggregateOptions()
            {
                AllowDiskUse = true,
                BatchSize    = int.MaxValue,
                MaxTime      = TimeSpan.FromMinutes(10)
            };

            IAggregateFluent <T> aggregate = GetAggregateFluent(opts);

            if (filter == null)
            {
                filter = Builders <T> .Filter.Empty;
            }
            aggregate = aggregate.Match(filter);

            if (sorter != null)
            {
                aggregate.Sort(sorter);
            }
            if (projection != null)
            {
                aggregate = aggregate.Project <T>(projection);
            }

            pagerInfo.Total = myCollection.CountAsync(filter).GetAwaiter().GetResult();

            List <T> result = aggregate.Match(filter).Sort(sorter).Skip(pagerInfo.Page).Limit(pagerInfo.PageSize)
                              .ToListAsync <T>().GetAwaiter().GetResult();

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Appends a project stage to the pipeline.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="project">The project specifications.</param>
        /// <returns>The fluent aggregate interface.</returns>
        public static IAggregateFluent <TDocument, BsonDocument> Project <TDocument, TResult>(this IAggregateFluent <TDocument, TResult> source, object project)
        {
            Ensure.IsNotNull(source, "source");
            Ensure.IsNotNull(project, "project");

            return(source.Project <BsonDocument>(project, BsonDocumentSerializer.Instance));
        }
Esempio n. 6
0
        /// <summary>
        /// Appends a project stage to the pipeline.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="TNewResult">The type of the new result.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="project">The project specifications.</param>
        /// <returns>The fluent aggregate interface.</returns>
        public static IAggregateFluent <TDocument, TNewResult> Project <TDocument, TResult, TNewResult>(this IAggregateFluent <TDocument, TResult> source, Expression <Func <TResult, TNewResult> > project)
        {
            Ensure.IsNotNull(source, "source");
            Ensure.IsNotNull(project, "projector");

            var serializer     = source.ResultSerializer ?? source.Collection.Settings.SerializerRegistry.GetSerializer <TResult>();
            var projectionInfo = AggregateProjectionTranslator.TranslateProject(project, serializer, source.Collection.Settings.SerializerRegistry);

            return(source.Project <TNewResult>(projectionInfo.Projection, projectionInfo.Serializer));
        }
Esempio n. 7
0
        private static IAggregateFluent <BsonDocument> PlaceTypeFilter(HeatDataResultRequestDto input, IAggregateFluent <BsonDocument> orderAggregateFluent)
        {
            string poinitLocationName = "$startPoinitLocation";

            switch (input.PlaceType)
            {
            case InputPlaceType.ExpectedGetOnLocation:
            default:
                break;

            case InputPlaceType.ExpectedGetOutLocation:
                poinitLocationName = "$endPointLocation";
                break;

            case InputPlaceType.ActualGetOnLocation:
                poinitLocationName = "$startPoinitLocationReal";
                break;

            case InputPlaceType.ActualGetOutLocation:
                poinitLocationName = "$endPointLocationReal";
                break;
            }

            orderAggregateFluent = orderAggregateFluent.Project(new BsonDocument {
                { "lat", new BsonDocument
                  {
                      {
                          "$arrayElemAt", new BsonArray(new List <BsonValue>()
                            {
                                poinitLocationName, 0
                            })
                      }
                  } },
                { "lng", new BsonDocument
                  {
                      {
                          "$arrayElemAt", new BsonArray(new List <BsonValue>()
                            {
                                poinitLocationName, 1
                            })
                      }
                  } },
            });
            return(orderAggregateFluent);
        }
Esempio n. 8
0
        /// <summary>
        /// Applies filtering sorting and projections on the <see cref="IExecutable{T}.Source"/>
        /// </summary>
        /// <returns>A aggregate fluent including the configuration of this executable</returns>
        public IAggregateFluent <T> BuildPipeline()
        {
            IAggregateFluent <T> pipeline = _aggregate;

            if (Sorting is not null)
            {
                pipeline = pipeline.Sort(Sorting.ToSortDefinition <T>());
            }

            if (Filters is not null)
            {
                pipeline = pipeline.Match(Filters.ToFilterDefinition <T>());
            }

            if (Projection is not null)
            {
                pipeline = pipeline.Project <T>(Projection.ToProjectionDefinition <T>());
            }

            return(pipeline);
        }
Esempio n. 9
0
        public IDocumentAggregateCursor <TNewResult> Project <TNewResult>(Expression <Func <TResult, TNewResult> > projection)
        {
            var next = _fluentAggregateCursor.Project(projection);

            return(CreateNextStage(next));
        }