Beispiel #1
0
        public static async Task <IEnumerable <T> > Match <T>(this IPublishedMessageList published, Expression <Func <IPublishedMessage <T>, bool> > filter, TimeSpan?timeout = default(TimeSpan?)) where T : class
        {
            try
            {
                var giveUpAt = DateTime.Now + (timeout ?? TimeSpan.FromSeconds(30));

                while (DateTime.Now < giveUpAt)
                {
                    if (published.AsQueryable().Where(x => typeof(T).IsAssignableFrom(x.MessageType)).Cast <IPublishedMessage <T> >().Where(filter).Any())
                    {
                        return(published.AsQueryable().Where(x => typeof(T).IsAssignableFrom(x.MessageType)).Cast <IPublishedMessage <T> >().Where(filter).Select(x => x.Context.Message).ToList());
                    }

                    await Task.Delay(10).ConfigureAwait(false);
                }
            }
            catch (InvalidOperationException)
            {
                await Task.Delay(10).ConfigureAwait(false);

                return(await published.Match <T>(filter, timeout));
            }

            return(new T[] { });
        }
Beispiel #2
0
 public static IEnumerable <IPublishedMessage <T> > Select <T>(this IPublishedMessageList published, Func <IPublishedMessage <T>, bool> filter)
     where T : class
 {
     return(published.Select <T>()
            .Cast <IPublishedMessage <T> >()
            .Where(filter));
 }
Beispiel #3
0
 public static async Task <IEnumerable <T> > Any <T>(this IPublishedMessageList published, Expression <Func <IPublishedMessage <T>, bool> > filter, TimeSpan?timeout = default(TimeSpan?)) where T : class
 {
     return(await published.Match <T>(m => m.MessageType == typeof(T) && filter.Compile()(m)));
 }