Ejemplo n.º 1
0
        public void Handle(ConversationUpdated @event)
        {
            // As this is an update of an existing conversation, load the existing conversation
            ConversationSummaryEntity conversationSummary = ConversationSummaryRepository.Load(@event.Rsn);

            // Update the name
            conversationSummary.Name = @event.Name;
            // As this is an update of an existing conversation, pass the updated entity to the Repository to be updated and persisted
            ConversationSummaryRepository.Update(conversationSummary);

            // Update all message projections
            // Define Query
            ICollectionResultQuery <MessageQueryStrategy, MessageEntity> query = QueryFactory.CreateNewCollectionResultQuery <MessageQueryStrategy, MessageEntity>();

            query.QueryStrategy.WithConversationRsn(@event.Rsn);
            query.QueryStrategy.OrderByDatePosted();

            // Retrieve Data
            query = MessageRepository.Retrieve(query);

            foreach (MessageEntity messageEntity in query.Result)
            {
                // Update the name
                messageEntity.ConversationName = @event.Name;

                // As this is an update of an existing message, pass the updated entity to the Repository to be updated and persisted
                MessageRepository.Update(messageEntity);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create an <see cref="IQueryable"/> of <typeparamref name="TData"/>
        /// that expects a collection of <typeparamref name="TData"/> items.
        /// </summary>
        /// <param name="collectionResultQuery">The query.</param>
        public virtual IQueryable <TData> CreateQueryable(ICollectionResultQuery <TQueryStrategy, TData> collectionResultQuery)
        {
            IQueryable <TData> queryable = collectionResultQuery.QueryStrategy.QueryPredicate == null?GetEmptyQueryPredicate() : GeneratePredicate(collectionResultQuery.QueryStrategy.QueryPredicate);

            ApplySorting(collectionResultQuery.QueryStrategy, ref queryable);
            return(queryable);
        }
Ejemplo n.º 3
0
        private IQueryable <OrderViewModel> GetOrders(Guid?orderRsn = null, int?orderId = null)
        {
            // Define Query
            ICollectionResultQuery <OrderQueryStrategy, OrderEntity> query = QueryFactory.CreateNewCollectionResultQuery <OrderQueryStrategy, OrderEntity>();

            // We don't want entities we've marked as deleted.
            query.QueryStrategy.WithNoDeletedOrders();

            // If an orderRsn is provided, query on that
            if (orderRsn != null)
            {
                query.QueryStrategy.WithRsn(orderRsn.Value);
            }
            // If an orderId is provided, query on that
            if (orderId != null)
            {
                query.QueryStrategy.WithOrderId(orderId.Value);
            }

            // Retrieve Data
            query = OrderRepository.Retrieve(query);
            IEnumerable <OrderEntity> queryResults = query.Result;

            IQueryable <OrderViewModel> orders = queryResults
                                                 .Select(x => (OrderViewModel)x)
                                                 .AsQueryable();

            return(orders);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Builds and executes the provided <paramref name="resultQuery"/>.
        /// </summary>
        /// <param name="resultQuery">The <see cref="ICollectionResultQuery{TQueryStrategy,TData}"/> to build and execute.</param>
        public virtual ICollectionResultQuery <TQueryStrategy, TData> Retrieve(ICollectionResultQuery <TQueryStrategy, TData> resultQuery)
        {
            // The .Select(i => i) is necessary due to inheritance
            // http://stackoverflow.com/questions/1021274/linq-to-sql-mapping-exception-when-using-abstract-base-classes
            IQueryable <TData> result = QueryBuilder.CreateQueryable(resultQuery).Select(i => i);

            IList <TData> finalResult = result.ToList();

            try
            {
                return(new CollectionResultQuery <TQueryStrategy, TData>
                {
                    QueryStrategy = resultQuery.QueryStrategy,
                    Result = finalResult
                });
            }
            finally
            {
                TelemetryHelper.TrackMetric(string.Format("Cqrs/Repository/Retrieve/Collection/{0}", typeof(TData).Name), finalResult.Count);
                // This is disabled until I can figure out a better way to handle disposing these... as it will most likely dispose the data store... and that's not cool.

                /*
                 * var disposable = result as IDisposable;
                 * if (disposable != null)
                 *      disposable.Dispose();
                 */
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get all <see cref="MessageEntity">messages</see> for the provided conversation.
        /// </summary>
        public virtual IServiceResponseWithResultData <IEnumerable <MessageEntity> > GetMessages(IServiceRequestWithData <Guid, ConversationParameters> serviceRequest)
        {
            AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
            CorrelationIdHelper.SetCorrelationId(serviceRequest.CorrelationId);

            Guid conversationRsn = serviceRequest.Data.ConversationRsn;

            // Define Query
            ICollectionResultQuery <MessageQueryStrategy, MessageEntity> query = QueryFactory.CreateNewCollectionResultQuery <MessageQueryStrategy, MessageEntity>();

            query.QueryStrategy.WithConversationRsn(conversationRsn);
            query.QueryStrategy.OrderByDatePosted();

            // Retrieve Data
            query = MessageRepository.Retrieve(query);
            IEnumerable <MessageEntity> queryResults = query.Result.ToList();

            var responseData = new ServiceResponseWithResultData <IEnumerable <MessageEntity> >
            {
                State      = ServiceResponseStateType.Succeeded,
                ResultData = queryResults
            };

            // Complete the response
            ServiceResponseWithResultData <IEnumerable <MessageEntity> > response = CompleteResponse(responseData);

            if (!queryResults.Any())
            {
                response.State = ServiceResponseStateType.EntityNotFound;
            }

            return(response);
        }
Ejemplo n.º 6
0
        public virtual HttpResponseMessage <ServiceResponseWithResultData <IEnumerable <MessageEntity> > > GetMessages(Guid conversationRsn)
        {
            // Define Query
            ICollectionResultQuery <MessageQueryStrategy, MessageEntity> query = QueryFactory.CreateNewCollectionResultQuery <MessageQueryStrategy, MessageEntity>();

            query.QueryStrategy.WithConversationRsn(conversationRsn);
            query.QueryStrategy.OrderByDatePosted();

            // Retrieve Data
            query = MessageRepository.Retrieve(query);
            IEnumerable <MessageEntity> queryResults = query.Result.ToList();

            var responseData = new ServiceResponseWithResultData <IEnumerable <MessageEntity> >
            {
                State      = ServiceResponseStateType.Succeeded,
                ResultData = queryResults
            };

            // Complete the response
            HttpResponseMessage <ServiceResponseWithResultData <IEnumerable <MessageEntity> > > response = CompleteResponseWithData(responseData);

            if (!queryResults.Any())
            {
                response.StatusCode = HttpStatusCode.NotFound;
            }

            return(response);
        }
Ejemplo n.º 7
0
        partial void OnGetAll(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, UserServiceGetAllParameters> serviceRequest, ref IServiceResponseWithResultData <IEnumerable <Entities.UserEntity> > results)
        {
            // Define Query
            ICollectionResultQuery <UserQueryStrategy, Entities.UserEntity> query = QueryFactory.CreateNewCollectionResultQuery <UserQueryStrategy, Entities.UserEntity>();

            // Retrieve Data, but remember if no items exist, the value is null
            query = UserRepository.Retrieve(query);
            IEnumerable <Entities.UserEntity> inventoryItems = query.Result;

            results = new ServiceResponseWithResultData <IEnumerable <Entities.UserEntity> >(inventoryItems);
        }
Ejemplo n.º 8
0
        partial void OnGetAllOrders(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, OrderServiceGetAllOrdersParameters> serviceRequest, ref IServiceResponseWithResultData <IEnumerable <OrderEntity> > results)
        {
            // Define Query
            ICollectionResultQuery <OrderQueryStrategy, OrderEntity> query = QueryFactory.CreateNewCollectionResultQuery <OrderQueryStrategy, OrderEntity>();

            // Retrieve Data
            query = OrderRepository.Retrieve(query);
            IEnumerable <OrderEntity> orders = query.Result;

            results = new ServiceResponseWithResultData <IEnumerable <OrderEntity> >
            {
                State      = ServiceResponseStateType.Succeeded,
                ResultData = orders
            };
        }
Ejemplo n.º 9
0
        public virtual ICollectionResultQuery <TQueryStrategy, TData> Retrieve(ICollectionResultQuery <TQueryStrategy, TData> resultQuery)
        {
            IQueryable <TData> result = QueryBuilder.CreateQueryable(resultQuery);

            try
            {
                return(new CollectionResultQuery <TQueryStrategy, TData>
                {
                    QueryStrategy = resultQuery.QueryStrategy,
                    Result = result.ToList()
                });
            }
            finally
            {
                // This is disabled until I can figure out a better way to handle disposing these... as it will most likely dispose the data store... and that's not cool.

                /*
                 * var disposable = result as IDisposable;
                 * if (disposable != null)
                 *      disposable.Dispose();
                 */
            }
        }
        public void Handle(ConversationDeleted @event)
        {
            // As this is a delete of an existing conversation, load the existing conversation
            ConversationSummaryEntity conversationSummary = ConversationSummaryRepository.Load(@event.Rsn);

            // This will logically delete the conversation so it can be retrieved in a list of deleted conversations to be un-deleted.
            ConversationSummaryRepository.Delete(conversationSummary);

            // Update all message projections
            // Define Query
            ICollectionResultQuery <MessageQueryStrategy, MessageEntity> query = QueryFactory.CreateNewCollectionResultQuery <MessageQueryStrategy, MessageEntity>();

            query.QueryStrategy.WithConversationRsn(@event.Rsn);
            query.QueryStrategy.OrderByDatePosted();

            // Retrieve Data
            query = MessageRepository.Retrieve(query);

            foreach (MessageEntity messageEntity in query.Result)
            {
                // This will logically delete the message so it can be retrieved in a list of deleted messages to be un-deleted.
                MessageRepository.Delete(messageEntity);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Get all <see cref="ConversationSummaryEntity">conversations</see>.
        /// </summary>
        public virtual IServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > Get(IServiceRequest <Guid> serviceRequest)
        {
            AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
            CorrelationIdHelper.SetCorrelationId(serviceRequest.CorrelationId);

            // Define Query
            ICollectionResultQuery <ConversationSummaryQueryStrategy, ConversationSummaryEntity> query = QueryFactory.CreateNewCollectionResultQuery <ConversationSummaryQueryStrategy, ConversationSummaryEntity>();

            query.QueryStrategy.WithNoDeletedConversations();

            // Retrieve Data
            query = ConversationSummaryRepository.Retrieve(query);
            IEnumerable <ConversationSummaryEntity> queryResults = query.Result;

            var responseData = new ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> >
            {
                State      = ServiceResponseStateType.Succeeded,
                ResultData = queryResults
            };

            // Complete the response
            ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > response = CompleteResponse(responseData);

            return(response);
        }
Ejemplo n.º 12
0
        public virtual HttpResponseMessage <ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > > Get()
        {
            // Define Query
            ICollectionResultQuery <ConversationSummaryQueryStrategy, ConversationSummaryEntity> query = QueryFactory.CreateNewCollectionResultQuery <ConversationSummaryQueryStrategy, ConversationSummaryEntity>();

            query.QueryStrategy.WithNoDeletedConversations();

            // Retrieve Data
            query = ConversationSummaryRepository.Retrieve(query);
            IEnumerable <ConversationSummaryEntity> queryResults = query.Result;

            var responseData = new ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> >
            {
                State      = ServiceResponseStateType.Succeeded,
                ResultData = queryResults
            };

            // Complete the response
            HttpResponseMessage <ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > > response = CompleteResponseWithData(responseData);

            return(response);
        }