示例#1
0
 private void EnsureMaxEventCountLimitIsRespected(SimpleEventQuery query, IEnumerable <EpcisEvent> events)
 {
     if (query.Parameters.SingleOrDefault(x => x is MaxEventCountParameter) is MaxEventCountParameter maxEventCountParameter && events.Count() == _limit)
     {
         throw new EpcisException(ExceptionType.QueryTooLargeException, $"Query returned more than {maxEventCountParameter.Limit} events.");
     }
 }
示例#2
0
        public async Task <IEnumerable <EpcisEvent> > Execute(SimpleEventQuery query)
        {
            query.Parameters.ForEach(x => Apply((dynamic)x));
            _query.OrderBy($"{_orderProperty} {_orderDirection.ToSql()}"); // Apply order by parameter (default is request record_time desc).
            _parameters.SetLimit(_limit == 0 ? 1024 : _limit);

            var events = await _unitOfWork.Query <EpcisEvent>(_sqlTemplate.RawSql, _parameters.Values);

            // If a MaxEventCountParameter exist and the number of events == the limit, throw an exception
            EnsureMaxEventCountLimitIsRespected(query, events);

            using (var reader = await _unitOfWork.FetchMany(SqlRequests.RelatedQuery, new { EventIds = events.Select(x => x.Id).ToArray() }))
            {
                var epcs = await reader.ReadAsync <Epc>();

                var fields = await reader.ReadAsync <CustomField>();

                var transactions = await reader.ReadAsync <BusinessTransaction>();

                var sourceDests = await reader.ReadAsync <SourceDestination>();

                foreach (var evt in events)
                {
                    evt.Epcs                  = epcs.Where(x => x.EventId == evt.Id).ToList();
                    evt.CustomFields          = fields.Where(x => x.EventId == evt.Id).ToList();
                    evt.BusinessTransactions  = transactions.Where(x => x.EventId == evt.Id).ToList();
                    evt.SourceDestinationList = sourceDests.Where(x => x.EventId == evt.Id).ToList();
                }
            }

            return(events);
        }
示例#3
0
        public async Task Run(Subscription subscription)
        {
            var query  = new SimpleEventQuery { /*Parameters = subscription.Parameters*/
            };
            var result = await _dispatcher.Dispatch(query);

            await _resultSender.Send(subscription.Destination, result);
        }
示例#4
0
 public override void Arrange()
 {
     base.Arrange();
     Query = new SimpleEventQuery();
 }