QueryContinuation <IEnumerable <IPackageSearchMetadata> > GetPackageQuery(string searchTerm)
        {
            if (PackageManager == null)
            {
                return(null);
            }

            var selectedRepository      = SelectedRepository;
            var allowPrereleaseVersions = AllowPrereleaseVersions;
            var updateFeed = getUpdateFeed();

            if (selectedRepository == null)
            {
                var repositories   = PackageManager.SourceRepositoryProvider.GetRepositories();
                var packageQueries = repositories.Select(repository => GetPackageQuery(repository, searchTerm, allowPrereleaseVersions, updateFeed)).ToList();
                if (packageQueries.Count == 1)
                {
                    return(packageQueries[0]);
                }
                else
                {
                    return(AggregateQuery.Create(packageQueries, results => results.SelectMany(xs => xs)));
                }
            }

            return(GetPackageQuery(selectedRepository, searchTerm, allowPrereleaseVersions, updateFeed));
        }
        public IAggregateState FindById(DomainContext session, AggregateQuery aggregateQuery)
        {
            //ignoring Aggregate Version
            var db        = session.Set <Pizzeria.PizzeriaState>();
            var aggregate = db.Include(nameof(Pizzeria.PizzeriaState.Orders))
                            .Single(p => p.Id == aggregateQuery.Id);

            return(aggregate);
        }
Beispiel #3
0
        /// <inheritdoc />
        public IAggregator Create(
            IEnumerable <string> resultSetFieldNames,
            string requestedQueryName,
            AggregateQuery aggregateQuery)
        {
            Aggregator toReturn = new Aggregator(
                resultSetFieldNames,
                this.aggregationFieldsCache,
                requestedQueryName,
                aggregateQuery);

            return(toReturn);
        }
        /// <summary>
        /// Initialises a new instance of the <see cref="Aggregator" /> class.
        /// </summary>
        /// <param name="resultSetFieldNames">
        /// A set of field names, obtained from the result set itself, upfront.
        /// </param>
        /// <param name="aggregationFieldsCache">
        /// An instance of <see cref="AggregationFieldsCache" />.
        /// </param>
        /// <param name="requestedQueryName">
        /// The name of the originally requested query.
        /// </param>
        /// <param name="aggregateQuery">
        /// An instance of <see cref="AggregateQuery" />.
        /// </param>
        public Aggregator(
            IEnumerable <string> resultSetFieldNames,
            AggregationFieldsCache aggregationFieldsCache,
            string requestedQueryName,
            AggregateQuery aggregateQuery)
        {
            this.resultSetFieldNames = resultSetFieldNames;

            this.aggregationFieldsCache = aggregationFieldsCache;
            this.requestedQueryName     = requestedQueryName;
            this.aggregateQuery         = aggregateQuery;

            this.aggregateTotal = 0;
        }
        public void AggregateQueryConcatenatesIndividualQueriesIfNoOrderingButSequenceIsInvalid()
        {
            // Arrange
            IEnumerable <IQueryable <string> > sources = new[] {
                Enumerable.Range(0, 3).Select(i => i + "C").AsQueryable(),
                GetInvalidSequence("B"),
                Enumerable.Range(0, 3).Select(i => i + "A").AsQueryable(),
            };

            // Act
            var aggregateQuery = new AggregateQuery <string>(sources, StringComparer.Ordinal, NullLogger.Instance, ignoreFailures: false);

            // Assert
            ExceptionAssert.Throws <Exception>(() => aggregateQuery.ToArray(), "Bad sequence");
        }
        public void CountDoesNotThrowIfForInvalidRepositoriesIfFlagIsSet()
        {
            // Arrange
            IEnumerable <IQueryable <string> > sources = new[] {
                Enumerable.Range(0, 3).Select(i => i + "A").AsQueryable(),
                GetInvalidSequence("B"),
                Enumerable.Range(0, 3).Select(i => i + "C").AsQueryable(),
            };

            // Act
            var aggregateQuery = new AggregateQuery <string>(sources, StringComparer.Ordinal, NullLogger.Instance, ignoreFailures: true).OrderBy(c => c);

            // Assert
            Assert.Equal(6, aggregateQuery.Count());
        }
Beispiel #7
0
        public void AggregateQueryConcatenatesIndividualQueriesIfNoOrderingButSequenceIsInvalid()
        {
            // Arrange
            IEnumerable<IQueryable<string>> sources = new[] {
                Enumerable.Range(0, 3).Select(i => i + "C").AsQueryable(),
                GetInvalidSequence("B"),
                Enumerable.Range(0, 3).Select(i => i + "A").AsQueryable(),
            };

            // Act
            var aggregateQuery = new AggregateQuery<string>(sources, StringComparer.Ordinal, NullLogger.Instance, ignoreFailures: false);

            // Assert
            ExceptionAssert.Throws<Exception>(() => aggregateQuery.ToArray(), "Bad sequence");
        }
        public void CountDoesNotThrowIfForInvalidRepositoriesIfFlagIsSet()
        {
            // Arrange
            IEnumerable<IQueryable<string>> sources = new[] {
                Enumerable.Range(0, 3).Select(i => i + "A").AsQueryable(),
                GetInvalidSequence("B"),
                Enumerable.Range(0, 3).Select(i => i + "C").AsQueryable(),
            };

            // Act 
            var aggregateQuery = new AggregateQuery<string>(sources, StringComparer.Ordinal, NullLogger.Instance, ignoreFailures: true).OrderBy(c => c);

            // Assert
            Assert.Equal(6, aggregateQuery.Count());
        }
        public void AggregateQueryConcatenatesIndividualQueriesIfNoOrderingIsAvailable()
        {
            // Arrange
            IEnumerable <IQueryable <string> > sources = new[] {
                Enumerable.Range(0, 3).Select(i => i + "C").AsQueryable(),
                Enumerable.Range(0, 3).Select(i => i + "A").AsQueryable(),
            };

            // Act
            var aggregateQuery = new AggregateQuery <string>(sources, StringComparer.Ordinal, NullLogger.Instance, ignoreFailures: false);

            // Assert
            Assert.Equal(
                new[] { "0C", "1C", "2C", "0A", "1A", "2A" },
                aggregateQuery.ToArray()
                );
        }
Beispiel #10
0
        public void AggregateQueryConcatenatesIndividualQueriesIfNoOrderingIsAvailable()
        {
            // Arrange
            IEnumerable<IQueryable<string>> sources = new[] {
                Enumerable.Range(0, 3).Select(i => i + "C").AsQueryable(),
                Enumerable.Range(0, 3).Select(i => i + "A").AsQueryable(),
            };

            // Act
            var aggregateQuery = new AggregateQuery<string>(sources, StringComparer.Ordinal, NullLogger.Instance, ignoreFailures: false);

            // Assert
            Assert.Equal(
                new[] { "0C", "1C", "2C", "0A", "1A", "2A" },
                aggregateQuery.ToArray()
            );
        }
        public IAggregateState FindById(DomainContext session, Type stateType, AggregateQuery aggregateQuery)
        {
            var db = session.Set(stateType);

            if (aggregateQuery.Version.HasValue)
            {
                var specificStateQuery = db.Where("Id.Equals(@0) AND Version = @1", aggregateQuery.Id, aggregateQuery.Version);

                var specificState = specificStateQuery.Provider.Execute(
                    Expression.Call(
                        typeof(Queryable), "SingleOrDefault",
                        new Type[] { specificStateQuery.ElementType },
                        specificStateQuery.Expression));

                return((IAggregateState)specificState);
            }

            var state = db.Find(aggregateQuery.Id);

            return((IAggregateState)state);
        }
        protected override object OnExecute(TCommand command)
        {
            TAggregate aggregate = null;

            using (var session = this.RepositoryFactory.OpenSession())
            {
                var aggregateId      = this.GetAggregateId(command);
                var aggregateVersion = this.GetAggregateVersion(command);
                if (aggregateVersion.HasValue)
                {
                    aggregate = session.GetById <TAggregate>(AggregateQuery.GetLatest(aggregateId, aggregateVersion.Value));
                }
                else
                {
                    aggregate = session.GetById <TAggregate>(aggregateId);
                }

                this.Manipulate(aggregate, command);
                session.CommitChanges();

                return(aggregate.Id);
            }
        }
Beispiel #13
0
        TAggregate IDefaultAggregateFinder <DomainContext> .FindById <TAggregate>(DomainContext session, AggregateQuery aggregateQuery)
        {
            var db = session.Set <TAggregate>();

            if (aggregateQuery.Version.HasValue)
            {
                var specific = db.Where(a => a.Id == aggregateQuery.Id && a.Version == aggregateQuery.Version).SingleOrDefault();

                return(specific);
            }

            var aggregate = db.Find(aggregateQuery.Id);

            return(aggregate);
        }