예제 #1
0
        public async Task AddTaskAsync(TaskRequest request, TimeSpan?delay = null)
        {
            var serializedRequest = JsonConvert.SerializeObject(request);
            var message           = new Message(Encoding.UTF8.GetBytes(serializedRequest));

            if (delay != null)
            {
                message.Delay(delay.Value);
            }

            await SendMessageAsync(message);
        }
예제 #2
0
        public IEnumerable <ITaskHandler> ResolveHandlers(TaskRequest taskRequest)
        {
            if (_log.IsEnabled(LogLevel.Debug))
            {
                _log.LogDebug($"Resolving request {taskRequest.Name} from {_handlerContainers.Count} handlers");
            }

            var matchingHandlers = _handlerContainers.Where(container => container.Key.HandlesRequest(taskRequest))
                                   .Select(handlerContainer => {
                var handler     = handlerContainer.Value.Value;
                handler.Request = taskRequest;
                return(handler);
            });

            return(matchingHandlers);
        }
예제 #3
0
        public static bool HandlesRequest(this Type handlerType, TaskRequest taskRequest)
        {
            var taskRequestName = taskRequest.Name;

            var handledRequestsField = handlerType.GetCustomAttribute <TaskHandlesRequestAttribute>();

            if (handledRequestsField == null)
            {
                return(false);
            }

            return(handledRequestsField.RequestTypes.Any(handledRequest => {
                var handledName = handledRequest.GetCustomAttribute <TaskRequestNameAttribute>()?.Name;
                return string.Equals(handledName, taskRequestName);
            }));
        }