Ejemplo n.º 1
0
 private void OnGetPagedEntities <T>(PagedEntityListResponse <T> response) where T : EntityBase
 {
     if (response.Status == ResponseStatus.Success)
     {
         _logger.Log(LogLevel.Debug, string.Format("GetEntities {0}: Succeeded", response.Id.ToString()));
         _logger.Log(LogLevel.Debug, string.Format("{0} entities of type {1} retrieved", response.CollectionPage.Items.Count, typeof(T).Name));
     }
     else
     {
         string errors = null;
         response.Errors.ToList().ForEach(x => { errors = errors + x + "/n"; });
         _logger.Log(LogLevel.Error, string.Format("EntitiesUpdated {0}: Failed{2}Errors:{2}{1}", response.Id.ToString(), errors, Environment.NewLine));
     }
 }
        private void OnGetPagedEntitesResponse <T>(PagedEntityListResponse <T> response, MessageReceivedInfo info, Action <PagedEntityListResponse <T> > onResponse) where T : EntityBase
        {
            //Check if we're passing on the result and its one of ours
            if (_pendingRequests.ContainsKey(response.Id) && onResponse != null)
            {
                //Remove from pending
                _pendingRequests.Remove(response.Id);

                //Unsubscribe from temporary queue and delete it
                //Doesn't appear to be valid way to unsubscribe so just delete
                var queueName = response.PrivateResponseQueue;
                _busManager.DeleteQueue(_busManager.TopicExchange, queueName);
                _ownedTemporaryQueues.Remove(_ownedTemporaryQueues.SingleOrDefault(q => q == queueName));

                //Invoke action method
                onResponse.Invoke(response);
            }
        }
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);
        }
Ejemplo n.º 4
0
 private void PagedEntitiesGot(PagedEntityListResponse <T> entitiesGot)
 {
     //response queue won't be in our management bus queue cache so create it first (even though queue should exist on rabbit mq)
     _busManager.CreateQueue(_busManager.TopicExchange, entitiesGot.PrivateResponseQueue);
     _busManager.Publish(_busManager.TopicExchange, entitiesGot.PrivateResponseQueue, entitiesGot);
 }