Esempio n. 1
0
        public async Task Subscribe(Subscription request, CancellationToken cancellationToken)
        {
            var epcisQuery = _queries.SingleOrDefault(x => x.Name == request.QueryName);

            EnsureQueryExists(epcisQuery, request.QueryName);
            EnsureQueryAllowsSubscription(epcisQuery);
            SubscriptionValidator.Validate(request);

            request.Parameters = QueryParameterFormatter.Format(request.Parameters);
            epcisQuery.ValidateParameters(request.Parameters, true);

            await _unitOfWork.Execute(async tx =>
            {
                await EnsureSubscriptionDoesNotExist(tx, request, cancellationToken);
                await tx.SubscriptionManager.Store(request, cancellationToken);
                _backgroundService.Register(request);
            });
        }
Esempio n. 2
0
        // TODO: differentiate between QueryParameterException and other exceptions (PgSQL, runtime...)
        public async Task <PollResponse> Poll(Poll query, CancellationToken cancellationToken)
        {
            var epcisQuery = _queries.SingleOrDefault(x => x.Name == query.QueryName);

            EnsureQueryExists(epcisQuery, query.QueryName);

            query.Parameters = QueryParameterFormatter.Format(query.Parameters);
            try
            {
                epcisQuery.ValidateParameters(query.Parameters);
                var results = await epcisQuery.Execute(query.Parameters, _unitOfWork, cancellationToken);

                return(new PollResponse {
                    QueryName = query.QueryName, Entities = results
                });
            }
            catch (Exception ex) when(!(ex is EpcisException))
            {
                throw new EpcisException(ExceptionType.QueryParameterException, ex.Message);
            }
        }