public async Task <EntityListResponse <T> > GetEntitiesAsync <T>(Expression <Func <T, bool> > filter, params Expression <Func <T, object> >[] navigationProperties) where T : EntityBase
        {
            //Create request
            EntityListRequest <T> request = new EntityListRequest <T>(Guid.NewGuid());

            request.NavigationProperties = new NavigationPropertiesHandle <T>(navigationProperties);
            request.Filter = new FilterHandle <T>(filter);
            request.User   = _user;

            //Add to pending requests
            _pendingRequests.Add(request.Id, request);

            //Create tcs for request
            var tcs = new TaskCompletionSource <EntityListResponse <T> >();

            //Setup and subscribe to result queue
            IQueue resultQueue = _busManager.CreateQueue(_busManager.TopicExchange, request.PrivateResponseQueue);

            _busManager.Subscribe <EntityListResponse <T> >(_busManager.TopicExchange, request.PrivateResponseQueue, (response, info) => OnGetEntitiesResponse(response, info, tcs));
            _ownedTemporaryQueues.Add(request.PrivateResponseQueue);

            //Send request
            _busManager.Publish(_busManager.TopicExchange, TopicQueues.ProductEntitiesList, request);

            //Await tcs task
            return(await tcs.Task);
        }
Beispiel #2
0
        public void OnRequest <T>(EntityListRequest <T> request, MessageReceivedInfo info) where T : EntityBase
        {
            EntityListRequestTask <T> task = new EntityListRequestTask <T>(_busManager, request);

            _executionManager.AddTask(task);
            _logger.Log(LogLevel.Info, "Added list request to executor queue: Id " + request.Id.ToString());
        }
Beispiel #3
0
 public async Task <ActionResult <int?> > CountByFilter([FromBody] EntityListRequest request)
 {
     if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementationsContainer, request.EntityTypeName, ActionTypeEnum.Select)))
     {
         return(Unauthorized());
     }
     return(await _entityHandler.CountByFilter(request));
 }
Beispiel #4
0
 internal async Task <int> CountByFilterInternal <TEntity>(EntityListRequest <TEntity> request)
     where TEntity : class
 {
     using (var context = await GetReadBusinessDbContext())
     {
         var query = QueryBuilder.CreateSelectQuery(request, context);
         return(await query.CountAsync());
     }
 }
Beispiel #5
0
        public async Task <IEnumerable> GetByFilter(EntityListRequest request)
        {
            var entityType = _implementationsContainer.Reflector.GetType(request.EntityTypeName);
            var method     = _handlerInternal.GetType().GetMethod(nameof(EfCoreEntityHandlerInternal.GetByFilterInternal), BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(entityType);
            var r          = this.GetType().GetMethod(nameof(CreateGenericListRequest), BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(entityType)
                             .Invoke(this, new object[] { request });
            var awaitable = method.Invoke(_handlerInternal, new object[] { r }) as Task <IEnumerable>;

            return(await awaitable);
        }
Beispiel #6
0
 private EntityListRequest <TEntity> CreateGenericListRequest <TEntity>(EntityListRequest request)
 {
     return(new EntityListRequest <TEntity>()
     {
         Order = request.Order,
         StartIndex = request.StartIndex,
         Count = request.Count,
         Filters = request.Filters?.Select(x => FilterNodeConverter.ToExpression <TEntity>(x, _implementationsContainer.Reflector)).ToArray()
     });
 }
Beispiel #7
0
 internal async Task <IEnumerable> GetByFilterInternal <TEntity>(EntityListRequest <TEntity> request)
     where TEntity : class
 {
     using (var context = await GetReadBusinessDbContext())
     {
         var query = QueryBuilder.CreateSelectQuery(request, context);
         query = QueryBuilder.SortQuery(request, query);
         query = QueryBuilder.PageQuery(request, query);
         return(await query.ToListAsync());
     }
 }
        public async Task <EntityListResponse> Get(EntityListRequest request)
        {
            if (!HasPremission(request.RequestOwner, EntityPremission.CanSee))
            {
                return(UnauthorizedListRequest());
            }
            var entities = AccessManager.Filter(_dataSrv.Query).FilterByEntityQuery(request.Query).ApplyEntityOrderBy(request.Query.Order);

            return(new EntityListResponse()
            {
                Access = ResponseAccess.Granted,
                Entities =
                    await entities.Include(x => x.Scheme).Include(x => x.PrimaryCategory).OrderByDescending(x => x.CreateDateTime)
                    .Paginate(request.Query ?? new Pagenation())
                    .ToViewModelListAsync(),
                Count = entities.Count()
            });
        }
        public void GetEntities(EntityListRequest <T> request)
        {
            var responseQueue        = request.PrivateResponseQueue;
            var filter               = request.Filter.GetFilter();
            var navigationProperties = request.NavigationProperties.GetNavigationProperties();
            var user      = request.User;
            var requestId = request.Id;

            EntityListResponse <T> response = null;
            IList <T> entities = null;
            var       result   = false;

            //Use generic data accessor
            using (var dataAccessor = new DataAccessor <T>(user))
            {
                try
                {
                    entities = dataAccessor.GetEntities(filter, navigationProperties);
                    result   = true;
                }
                catch (Exception ex)
                {
                    //Cast as our own exception to get base message
                    var exception = new BaseDbException(ex);
                    _logger.Log(LogLevel.Error, ex);
                    result   = false;
                    response = new EntityListResponse <T> {
                        Errors = new string[] { exception.Message }.ToList(), Id = requestId, NavigationProperties = request.NavigationProperties, Status = ResponseStatus.Failure
                    };
                }
            }

            if (result)
            {
                _logger.Log(LogLevel.Info, string.Format("GetEntities request Id {0} completed successfully.", requestId));
                response = new EntityListResponse <T> {
                    Entities = entities.ToList(), Id = requestId, NavigationProperties = request.NavigationProperties, Status = ResponseStatus.Success
                };
            }

            EntitiesGot(response);
        }
        public async void RemoveItemsToOrderTest()
        {
            // Arrange
            var content = new EntityListRequest <Item>()
            {
                Items = new List <Item>()
                {
                    new Item()
                    {
                        OrderId = "OR002", Id = "I002"
                    }
                }
            };

            // Act
            var response = await client.PostAsync(service.GetClient(), $"{url}/Order('OR002')/Checkout.RemoveItems", content);

            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
        }
        public async void AddItemsToOrderTest()
        {
            // Arrange
            var content = new EntityListRequest <Item>()
            {
                Items = new List <Item>()
                {
                    new Item()
                    {
                        OrderId = "OR001", ProductId = "P003", Quantity = 1
                    }
                }
            };

            // Act
            var response = await client.PostAsync(service.GetClient(), $"{url}/Order('OR001')/Checkout.AddItems", content);

            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
        }
        public Guid GetEntities <T>(Action <EntityListResponse <T> > onResponse, Expression <Func <T, bool> > filter, params Expression <Func <T, object> >[] navigationProperties) where T : EntityBase
        {
            //Create request
            EntityListRequest <T> request = new EntityListRequest <T>(Guid.NewGuid());

            request.NavigationProperties = new NavigationPropertiesHandle <T>(navigationProperties);
            request.Filter = new FilterHandle <T>(filter);
            request.User   = _user;

            //Add to pending requests
            _pendingRequests.Add(request.Id, request);

            //Setup and subscribe to result queue
            IQueue resultQueue = _busManager.CreateQueue(_busManager.TopicExchange, request.PrivateResponseQueue);

            _busManager.Subscribe <EntityListResponse <T> >(_busManager.TopicExchange, request.PrivateResponseQueue, (response, info) => OnGetEntitiesResponse(response, info, onResponse));
            _ownedTemporaryQueues.Add(request.PrivateResponseQueue);

            //Send request
            _busManager.Publish(_busManager.TopicExchange, TopicQueues.ProductEntitiesList, request);

            //Return request guid
            return(request.Id);
        }