Ejemplo n.º 1
0
        public void OnRequest <T>(PagedEntityListRequest <T> request, MessageReceivedInfo info) where T : EntityBase
        {
            PagedEntityListRequestTask <T> task = new PagedEntityListRequestTask <T>(_busManager, request);

            _executionManager.AddTask(task);
            _logger.Log(LogLevel.Info, "Added paged list request to executor queue: Id " + request.Id.ToString());
        }
        public Guid GetPagedEntities <T>(Action <PagedEntityListResponse <T> > onResponse, int page, int itemsPerPage, Expression <Func <T, bool> > filter, params Expression <Func <T, object> >[] navigationProperties) where T : EntityBase
        {
            //Create request
            PagedEntityListRequest <T> request = new PagedEntityListRequest <T>(Guid.NewGuid());

            request.Page                 = page;
            request.ItemsPerPage         = itemsPerPage;
            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 <PagedEntityListResponse <T> >(_busManager.TopicExchange, request.PrivateResponseQueue, (response, info) => OnGetPagedEntitesResponse(response, info, onResponse));
            _ownedTemporaryQueues.Add(request.PrivateResponseQueue);

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

            //Return request guid
            return(request.Id);
        }
Ejemplo n.º 3
0
        public void GetPagedEntities(PagedEntityListRequest <T> request)
        {
            var responseQueue        = request.PrivateResponseQueue;
            var filter               = request.Filter.GetFilter();
            var navigationProperties = request.NavigationProperties.GetNavigationProperties();
            var page         = request.Page;
            var itemsPerPage = request.ItemsPerPage;
            var user         = request.User;
            var requestId    = request.Id;

            PagedEntityListResponse <T> response       = null;
            CollectionPage <T>          collectionPage = null;
            var result = false;

            //Use generic data accessor
            using (var dataAccessor = new DataAccessor <T>(user))
            {
                try
                {
                    collectionPage = dataAccessor.GetPagedEntities(page, itemsPerPage, 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 PagedEntityListResponse <T> {
                        Errors = new string[] { exception.Message }.ToList(), Id = requestId, NavigationProperties = request.NavigationProperties, Status = ResponseStatus.Failure
                    };
                }
            }

            if (result)
            {
                _logger.Log(LogLevel.Info, string.Format("GetPagedEntities request Id {0} completed successfully.", requestId));
                response = new PagedEntityListResponse <T> {
                    CollectionPage = collectionPage, Id = requestId, NavigationProperties = request.NavigationProperties, Status = ResponseStatus.Success
                };
            }

            PagedEntitiesGot(response);
        }