async Task IPostMessageAsyncFilter.OnPostMessageAsync(PostMessageFilterContext context)
            {
                LogBoard <string> .Add(context.Actor, $"{_actorType.Name} Async.OnPostMessageAsync");

                await Task.Yield();

                LogBoard <string> .Add(context.Actor, $"{_actorType.Name} Async.OnPostMessageAsync Done");
            }
 void IPostMessageFilter.OnPostMessage(PostMessageFilterContext context)
 {
     LogBoard<string>.Add(context.Actor, $"{_name}.OnPostMessage");
 }
Beispiel #3
0
        private static MessageAsyncHandler BuildAsyncHandler(
            Type targetType, Type messageType, MethodInfo method, FilterChain filterChain)
        {
            var isAsyncMethod = method.ReturnType.Name.StartsWith("Task");
            var handler       = isAsyncMethod
                ? MessageHandlerAsyncBuilder.Build(targetType, method)
                : MessageHandlerSyncToAsyncBuilder.Build(targetType, method);

            if (filterChain.Empty)
            {
                return(handler);
            }

            return(async(self, message) =>
            {
                var filterPerInstanceProvider = filterChain.PerInstanceFilterExists ? (IFilterPerInstanceProvider)self : null;

                // Create PerRequest filters

                IFilter[] filterPerRequests = null;
                if (filterChain.PerInvokeFilterFactories.Length > 0)
                {
                    filterPerRequests = new IFilter[filterChain.PerInvokeFilterFactories.Length];
                    for (var i = 0; i < filterChain.PerInvokeFilterFactories.Length; i++)
                    {
                        filterPerRequests[i] = filterChain.PerInvokeFilterFactories[i].CreateInstance(self, message);
                    }
                }

                // Call PreFilters

                var handled = false;
                if (filterChain.PreFilterAccessors.Length > 0)
                {
                    var context = new PreMessageFilterContext
                    {
                        Actor = self,
                        Message = message
                    };
                    foreach (var filterAccessor in filterChain.PreFilterAccessors)
                    {
                        var filter = filterAccessor(filterPerInstanceProvider, filterPerRequests);
                        var preFilter = filter as IPreMessageFilter;
                        if (preFilter != null)
                        {
                            preFilter.OnPreMessage(context);
                        }
                        else
                        {
                            await((IPreMessageAsyncFilter)filter).OnPreMessageAsync(context);
                        }
                    }
                    handled = context.Handled;
                }

                // Call Handler

                if (handled == false)
                {
                    await handler(self, message);
                }

                // Call PostFilters

                if (filterChain.PostFilterAccessors.Length > 0)
                {
                    var context = new PostMessageFilterContext
                    {
                        Actor = self,
                        Message = message,
                        Intercepted = handled
                    };
                    foreach (var filterAccessor in filterChain.PostFilterAccessors)
                    {
                        var filter = filterAccessor(filterPerInstanceProvider, filterPerRequests);
                        var postFilter = filter as IPostMessageFilter;
                        if (postFilter != null)
                        {
                            postFilter.OnPostMessage(context);
                        }
                        else
                        {
                            await((IPostMessageAsyncFilter)filter).OnPostMessageAsync(context);
                        }
                    }
                }
            });
        }
Beispiel #4
0
        private static MessageHandler BuildHandler(
            Type targetType, Type messageType, MethodInfo method, FilterChain filterChain)
        {
            var handler = MessageHandlerFuncBuilder.Build(targetType, method);

            if (filterChain.Empty)
            {
                return(handler);
            }

            return((self, message) =>
            {
                var filterPerInstanceProvider = filterChain.PerInstanceFilterExists ? (IFilterPerInstanceProvider)self : null;

                // Create PerRequest filters

                IFilter[] filterPerRequests = null;

                if (filterChain.PerInvokeFilterFactories.Length > 0)
                {
                    filterPerRequests = new IFilter[filterChain.PerInvokeFilterFactories.Length];
                    for (var i = 0; i < filterChain.PerInvokeFilterFactories.Length; i++)
                    {
                        filterPerRequests[i] = filterChain.PerInvokeFilterFactories[i].CreateInstance(self, message);
                    }
                }

                // Call PreFilters

                var handled = false;
                if (filterChain.PreFilterAccessors.Length > 0)
                {
                    var context = new PreMessageFilterContext
                    {
                        Actor = self,
                        Message = message
                    };
                    foreach (var filterAccessor in filterChain.PreFilterAccessors)
                    {
                        var filter = filterAccessor(filterPerInstanceProvider, filterPerRequests);
                        ((IPreMessageFilter)filter).OnPreMessage(context);
                    }
                    handled = context.Handled;
                }

                // Call Handler

                if (handled == false)
                {
                    handler(self, message);
                }

                // Call PostFilters

                if (filterChain.PostFilterAccessors.Length > 0)
                {
                    var context = new PostMessageFilterContext
                    {
                        Actor = self,
                        Message = message,
                        Intercepted = handled
                    };
                    foreach (var filterAccessor in filterChain.PostFilterAccessors)
                    {
                        var filter = filterAccessor(filterPerInstanceProvider, filterPerRequests);
                        ((IPostMessageFilter)filter).OnPostMessage(context);
                    }
                }
            });
        }
 void IPostMessageFilter.OnPostMessage(PostMessageFilterContext context)
 {
     LogBoard <string> .Add(context.Actor, $"{_name}.OnPostMessage");
 }
        private static MessageAsyncHandler BuildAsyncHandler(
            Type targetType, Type messageType, MethodInfo method, FilterChain filterChain)
        {
            var isAsyncMethod = method.ReturnType.Name.StartsWith("Task");
            var handler = isAsyncMethod
                ? MessageHandlerAsyncBuilder.Build(targetType, method)
                : MessageHandlerSyncToAsyncBuilder.Build(targetType, method);
            if (filterChain.Empty)
                return handler;

            return async (self, message) =>
            {
                var filterPerInstanceProvider = filterChain.PerInstanceFilterExists ? (IFilterPerInstanceProvider)self : null;

                // Create PerRequest filters

                IFilter[] filterPerRequests = null;
                if (filterChain.PerInvokeFilterFactories.Length > 0)
                {
                    filterPerRequests = new IFilter[filterChain.PerInvokeFilterFactories.Length];
                    for (var i = 0; i < filterChain.PerInvokeFilterFactories.Length; i++)
                    {
                        filterPerRequests[i] = filterChain.PerInvokeFilterFactories[i].CreateInstance(self, message);
                    }
                }

                // Call PreFilters

                var handled = false;
                if (filterChain.PreFilterAccessors.Length > 0)
                {
                    var context = new PreMessageFilterContext
                    {
                        Actor = self,
                        Message = message
                    };
                    foreach (var filterAccessor in filterChain.PreFilterAccessors)
                    {
                        var filter = filterAccessor(filterPerInstanceProvider, filterPerRequests);
                        var preFilter = filter as IPreMessageFilter;
                        if (preFilter != null)
                            preFilter.OnPreMessage(context);
                        else
                            await ((IPreMessageAsyncFilter)filter).OnPreMessageAsync(context);
                    }
                    handled = context.Handled;
                }

                // Call Handler

                if (handled == false)
                    await handler(self, message);

                // Call PostFilters

                if (filterChain.PostFilterAccessors.Length > 0)
                {
                    var context = new PostMessageFilterContext
                    {
                        Actor = self,
                        Message = message,
                        Intercepted = handled
                    };
                    foreach (var filterAccessor in filterChain.PostFilterAccessors)
                    {
                        var filter = filterAccessor(filterPerInstanceProvider, filterPerRequests);
                        var postFilter = filter as IPostMessageFilter;
                        if (postFilter != null)
                            postFilter.OnPostMessage(context);
                        else
                            await ((IPostMessageAsyncFilter)filter).OnPostMessageAsync(context);
                    }
                }
            };
        }
        private static MessageHandler BuildHandler(
            Type targetType, Type messageType, MethodInfo method, FilterChain filterChain)
        {
            var handler = MessageHandlerFuncBuilder.Build(targetType, method);
            if (filterChain.Empty)
                return handler;

            return (self, message) =>
            {
                var filterPerInstanceProvider = filterChain.PerInstanceFilterExists ? (IFilterPerInstanceProvider)self : null;

                // Create PerRequest filters

                IFilter[] filterPerRequests = null;

                if (filterChain.PerInvokeFilterFactories.Length > 0)
                {
                    filterPerRequests = new IFilter[filterChain.PerInvokeFilterFactories.Length];
                    for (var i = 0; i < filterChain.PerInvokeFilterFactories.Length; i++)
                    {
                        filterPerRequests[i] = filterChain.PerInvokeFilterFactories[i].CreateInstance(self, message);
                    }
                }

                // Call PreFilters

                var handled = false;
                if (filterChain.PreFilterAccessors.Length > 0)
                {
                    var context = new PreMessageFilterContext
                    {
                        Actor = self,
                        Message = message
                    };
                    foreach (var filterAccessor in filterChain.PreFilterAccessors)
                    {
                        var filter = filterAccessor(filterPerInstanceProvider, filterPerRequests);
                        ((IPreMessageFilter)filter).OnPreMessage(context);
                    }
                    handled = context.Handled;
                }

                // Call Handler

                if (handled == false)
                    handler(self, message);

                // Call PostFilters

                if (filterChain.PostFilterAccessors.Length > 0)
                {
                    var context = new PostMessageFilterContext
                    {
                        Actor = self,
                        Message = message,
                        Intercepted = handled
                    };
                    foreach (var filterAccessor in filterChain.PostFilterAccessors)
                    {
                        var filter = filterAccessor(filterPerInstanceProvider, filterPerRequests);
                        ((IPostMessageFilter)filter).OnPostMessage(context);
                    }
                }
            };
        }
 async Task IPostMessageAsyncFilter.OnPostMessageAsync(PostMessageFilterContext context)
 {
     LogBoard<string>.Add(context.Actor, $"{_actorType.Name} Async.OnPostMessageAsync");
     await Task.Yield();
     LogBoard<string>.Add(context.Actor, $"{_actorType.Name} Async.OnPostMessageAsync Done");
 }