Ejemplo n.º 1
0
        public void ShowFilteredmessages(ConcurrentBag <Message> messages)
        {
            var filteredMessages = MessageFilter.ApplyFilter(messages);

            Output.Write(filteredMessages.OrderBy(m => m.ReceivedAt)
                         .ToList());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the messages.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        /// filter - Filter cannot be null
        /// or
        /// Direction - Direction filter cannot be empty
        /// </exception>
        /// <exception cref="Eu.EDelivery.AS4.Fe.BusinessException">No messages found</exception>
        public async Task <MessageResult <Message> > GetMessages(MessageFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter), @"Filter cannot be null");
            }
            if (filter.Direction == null)
            {
                throw new ArgumentNullException(nameof(filter.Direction), @"Direction filter cannot be empty");
            }

            IQueryable <InMessage>  inMessageQuery  = context.InMessages;
            IQueryable <OutMessage> outMessageQuery = context.OutMessages;

            var inMessages  = filter.Direction.Contains(Direction.Inbound) ? filter.ApplyFilter(inMessageQuery).ProjectTo <Message>(mapperConfig) : null;
            var outMessages = filter.Direction.Contains(Direction.Outbound) ? filter.ApplyFilter(outMessageQuery).ProjectTo <Message>(mapperConfig) : null;

            IQueryable <Message> result = null;

            if (inMessages != null && outMessages != null)
            {
                result = inMessages.Concat(outMessages);
            }
            else if (inMessages != null)
            {
                result = inMessages;
            }
            else if (outMessages != null)
            {
                result = outMessages;
            }
            if (result == null)
            {
                throw new BusinessException("No messages found");
            }

            var returnValue = await filter.ToResult(filter.ApplyStatusFilter(result).OrderByDescending(msg => msg.InsertionTime));

            UpdateHasExceptions(returnValue, await GetExceptionIds(returnValue));

            return(returnValue);
        }
Ejemplo n.º 3
0
        public void FilterByUserTest()
        {
            var filter = new MessageFilter();
            var rules  = FilteringRules.GetFilteringRules();

            rules.Sender         = "User1";
            rules.IsConditionAnd = true;

            var messages = filter.ApplyFilter(Messages);

            rules.ResetFilter();
            Assert.AreEqual(0, messages.Where(m => m.User != "User1").ToList().Count);
        }
Ejemplo n.º 4
0
        public void FilterByUserAndMessage()
        {
            var filter = new MessageFilter();
            var rules  = FilteringRules.GetFilteringRules();

            rules.IsConditionAnd = true;
            rules.FromDate       = DateTime.MinValue;
            rules.ToDate         = DateTime.MaxValue;
            rules.Sender         = "User1";
            rules.Message        = "ge2";

            var messages = filter.ApplyFilter(Messages);

            rules.ResetFilter();
            Assert.AreEqual(1, messages.Count());
        }