public static IReadOnlyCollection <object> RejectAll(this IHandlerRegistry registry)
 {
     return(new ReadOnlyCollection <object>(new List <object>
     {
         new AlwaysRejectMessageHandler()
     }));
 }
Exemple #2
0
        public QueryDocument(IHandlerRegistry handlerRegistry, Query query)
        {
            InitializeComponent();

            _objectSelectionHandler              = handlerRegistry.GetHandler <IObjectSelectionHandler>();
            _syntaxEditorClipboardHandler        = new SyntaxEditorClipboardHandler(syntaxEditor);
            _syntaxEditorUndoRedoHandler         = new SyntaxEditorUndoRedoHandler(syntaxEditor);
            _resultsDataGridViewClipboardHandler = new ResultsDataGridViewClipboardHandler(resultsDataGridView);
            _errorListClipboardHandler           = new ErrorListClipboardHandler(errorsListView);

            _query = query;

            _actiproLink = new ActiproLink(components);
            _actiproLink.SyntaxEditor = syntaxEditor;
            _actiproLink.Evaluatable  = _query;

            _queryBrowser = new QueryBrowser(handlerRegistry, _query);

            resultsDataGridView.AllowUserToResizeRows       = false;
            resultsDataGridView.BackgroundColor             = System.Drawing.SystemColors.Window;
            resultsDataGridView.BorderStyle                 = System.Windows.Forms.BorderStyle.Fixed3D;
            resultsDataGridView.ColumnHeadersBorderStyle    = DataGridViewHeaderBorderStyle.None;
            resultsDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            resultsDataGridView.GridColor         = System.Drawing.SystemColors.ActiveBorder;
            resultsDataGridView.RowHeadersVisible = false;
            resultsDataGridView.DataError        += delegate { };

            syntaxEditor.Text = _query.Text;

            ClearStatusPanel();
        }
        public DefaultEventDispatcher(IHandlerRegistry handlerRegistry, IHandlerInvoker handlerInvoker)
        {
            Require.NotNull(handlerRegistry, "handlerRegistry");
            Require.NotNull(handlerInvoker, "handlerInvoker");

            _handlerRegistry = handlerRegistry;
            _handlerInvoker = handlerInvoker;
        }
Exemple #4
0
 public void RegisterHandlers(IHandlerRegistry handlerRegistry)
 {
     foreach (var hi in handlers.Value)
     {
         handlerRegistry.Register(hi.MessageType, new HandlerInfo(hi.HandlerType,
                                                                  hi.MessageType, hi.ProcessCode, hi.MethodInfo));
     }
 }
 public static IHandlerRegistry On <T>(this IHandlerRegistry registry, IRpcHandler <T> handler) where T : IRpcRequestMessage
 {
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     return(registry.On <T>(handler.HandleAsync));
 }
 public static IHandlerRegistry On <T>(this IHandlerRegistry registry, Func <T, Action <object>, Task> handler)
 {
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     return(registry.On(typeof(T), (x, a) => handler((T)x, a)));
 }
Exemple #7
0
        public void Init(ITypesProvider typesProvider)
        {
            IHandlerRegistry handlerRegistry = typesProvider.Resolve <IHandlerRegistry>();

            handlerRegistry.RegisterHandler <GetDeviceDefinitionsQuery, GetDeviceDefinitionsQueryHandler>();
            handlerRegistry.RegisterHandler <UpdateDeviceDefinitionCommand, UpdateDeviceDefinitionCommandHandler>();
            handlerRegistry.RegisterHandler <GetStoreSnapshotQuery, GetStoreSnapshotQueryHandler>();
            handlerRegistry.RegisterHandler <UploadSnapshotCommand, UploadSnapshotCommandHandler>();
        }
Exemple #8
0
        public QueryBrowser(IHandlerRegistry handlerRegistry, Evaluatable evaluatable)
        {
            InitializeComponent();

            _handlerRegistry = handlerRegistry;
            _evaluatable     = evaluatable;
            evaluatableBrowser.Evaluatable          = evaluatable;
            evaluatableBrowser.SelectedItemChanged += evaluatableBrowser_SelectedItemChanged;
            Application.Idle += Application_OnIdle;
        }
Exemple #9
0
		public QueryBrowser(IHandlerRegistry handlerRegistry, Evaluatable evaluatable)
		{
			InitializeComponent();

			_handlerRegistry = handlerRegistry;
			_evaluatable = evaluatable;
			evaluatableBrowser.Evaluatable = evaluatable;
			evaluatableBrowser.SelectedItemChanged += evaluatableBrowser_SelectedItemChanged;
			Application.Idle += Application_OnIdle;
		}
 public static IHandlerRegistry On(this IHandlerRegistry registry, Type type, Func <object, Task> handler)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     return(registry.On(type, (x, a) => handler(x)));
 }
Exemple #11
0
        private async Task <bool> CallHandlers(IHandlerRegistry handlers, Type type, object message, Action <object> action)
        {
            var result       = true;
            var errorHandler = handlers.FindErrorHandler(type);
            var typeHandlers = handlers.FindHandler(type);

            if (typeHandlers != null)
            {
                foreach (var handler in typeHandlers)
                {
                    var hresult      = true;
                    var errorMessage = "No error.";
                    try
                    {
                        await handler(message, action);
                    }
                    catch (Exception ex)
                    {
                        errorMessage = string.Format("Message handler failed: {0}", ex.Message);
                        _logger.Error("Message handler exception:", ex);
                        hresult = false;
                    }
                    if (!hresult && errorHandler != null)
                    {
                        try
                        {
                            await errorHandler(errorMessage, action);
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("Error handler exception:", ex);
                        }
                    }
                    result = result && hresult;
                }
            }
            else
            {
                _logger.Error("Handler for type '{0}' not found. Dropping message.", type.Name);
                result = false;
            }
            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public Dispatcher(DispatcherConfiguration configuration)
        {
            if (configuration.ServiceLocator == null)
                throw new ArgumentException("Service Locator is not registered for distributor.");

            _registry = configuration.Builder.BuildHandlerRegistry();
            _serviceLocator = configuration.ServiceLocator;

            /*
            if (configuration.DispatcherHandlerRegistry == null)
                throw new ArgumentException("Dispatcher Handler Registry is null in distributor.");

            
            _registry = configuration.DispatcherHandlerRegistry;
            _maxRetries = configuration.MaxRetries;

            // order handlers 
            _registry.InsureOrderOfHandlers(configuration.Order);*/
        }
Exemple #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public Dispatcher(DispatcherConfiguration configuration)
        {
            if (configuration.ServiceLocator == null)
            {
                throw new ArgumentException("Service Locator is not registered for distributor.");
            }

            _registry       = configuration.Builder.BuildHandlerRegistry();
            _serviceLocator = configuration.ServiceLocator;

            /*
             * if (configuration.DispatcherHandlerRegistry == null)
             *  throw new ArgumentException("Dispatcher Handler Registry is null in distributor.");
             *
             *
             * _registry = configuration.DispatcherHandlerRegistry;
             * _maxRetries = configuration.MaxRetries;
             *
             * // order handlers
             * _registry.InsureOrderOfHandlers(configuration.Order);*/
        }
Exemple #14
0
        /// <summary>
        /// Initializes a new interpreter and discovers methods marked
        /// with <see cref="CommandHandlerAttribute"/> attribute.
        /// </summary>
        protected CommandInterpreter()
        {
            var interpreters = new Dictionary <int, CommandHandler>();
            var formatters   = new Dictionary <Type, FormatterInfo>();
            const BindingFlags publicInstanceMethod = BindingFlags.Public | BindingFlags.Instance;

            foreach (var method in GetType().GetMethods(publicInstanceMethod))
            {
                var handlerAttr = method.GetCustomAttribute <CommandHandlerAttribute>();
                if (handlerAttr is not null && method.ReturnType == typeof(ValueTask))
                {
                    var parameters = method.GetParameterTypes();
                    if (GetLength(parameters) != 2 || !parameters[0].IsValueType || parameters[1] != typeof(CancellationToken))
                    {
                        continue;
                    }
                    var commandType = parameters[0];
                    var commandAttr = commandType.GetCustomAttribute <CommandAttribute>();
                    if (commandAttr is null || commandAttr.Formatter is null)
                    {
                        continue;
                    }
                    var formatter = new FormatterInfo(commandAttr);
                    if (formatter.IsEmpty)
                    {
                        continue;
                    }
                    var interpreter = Delegate.CreateDelegate(typeof(Func <, ,>).MakeGenericType(commandType, typeof(CancellationToken), typeof(ValueTask)), method.IsStatic ? null : this, method);
                    interpreters.Add(commandAttr.Id, Cast <CommandHandler>(Activator.CreateInstance(typeof(CommandHandler <>).MakeGenericType(commandType), formatter, interpreter)));
                    formatters.Add(commandType, formatter);
                }
            }

            this.interpreters = CreateRegistry(interpreters);
            interpreters.Clear();

            formatters.TrimExcess();
            this.formatters = formatters;
        }
 public void Register(IHandlerRegistry <TAgg, TId, TState> registry)
 {
     registry.Register(this);
 }
Exemple #16
0
 public MessageUnit Use(IHandlerRegistry registry)
 {
     this.registry = registry;
     return this;
 }
 public IncomingPipelineFactory(IHandlerRegistry registry)
 {
     this.registry = registry;
 }
 public UnitIncomingPipelineFactory(IHandlerRegistry registry, ICollection<LogicalMessage> incoming, ICollection<TransportMessage> deadLetter)
 {
     this.incoming = incoming;
     this.deadLetter = deadLetter;
     this.registry = registry;
 }
Exemple #19
0
 public static IEnumerable <IEventHandler <TEvent> > GetEventHandlers <TEvent>(this IHandlerRegistry handlerRegistry)
     where TEvent : IEvent => handlerRegistry.GetEventHandlers(typeof(TEvent)).Cast <IEventHandler <TEvent> >();
Exemple #20
0
 public UnitIncomingPipelineFactory(IHandlerRegistry registry, ICollection<LogicalMessage> incoming)
 {
     this.incoming = incoming;
     this.registry = registry;
 }
Exemple #21
0
 internal InterpretingTransformation(int id, IHandlerRegistry registry)
 {
     this.handler = registry.TryGetValue(id, out var handler) ? handler : throw new UnknownCommandException(id);
     this.id      = id;
 }
Exemple #22
0
 public static ICommandHandler <TCommand> GetCommandHandler <TCommand>(this IHandlerRegistry handlerRegistry)
     where TCommand : ICommand => (ICommandHandler <TCommand>)handlerRegistry.GetCommandHandler(typeof(TCommand));
Exemple #23
0
 public static IReadOnlyCollection <IHandleMessageAsync <TMessage> > ConsumeWith <TMessage>(this IHandlerRegistry registry, params IHandleMessageAsync <TMessage>[] handlers)
 {
     return(new ReadOnlyCollection <IHandleMessageAsync <TMessage> >(handlers.ToList()));
 }
Exemple #24
0
 public static IEnumerable <ICommandHandlerWrapper <TCommand> > GetCommandHandlerWrappers <TCommand>(this IHandlerRegistry handlerRegistry)
     where TCommand : ICommand => handlerRegistry.GetCommandHandlerWrappers(typeof(TCommand)).Cast <ICommandHandlerWrapper <TCommand> >();
 public IncomingPipelineFactory(IHandlerRegistry registry)
 {
     this.registry = registry;
 }
Exemple #26
0
 public static IQueryHandler <TQuery, TResult> GetQueryHandler <TQuery, TResult>(this IHandlerRegistry handlerRegistry)
     where TQuery : IQuery <TResult> => (IQueryHandler <TQuery, TResult>)handlerRegistry.GetQueryHandler(typeof(TQuery), typeof(TResult));
Exemple #27
0
 public UnitIncomingPipelineFactory(IHandlerRegistry registry, ICollection <LogicalMessage> incoming, ICollection <TransportMessage> deadLetter)
 {
     this.incoming   = incoming;
     this.deadLetter = deadLetter;
     this.registry   = registry;
 }
 public RootController(ApplicationContext context, IHandlerRegistry handlerRegistry)
 {
     _context         = context;
     _handlerRegistry = handlerRegistry;
 }
 public MessageUnit Use(IHandlerRegistry registry)
 {
     this.registry = registry;
     return(this);
 }
 public MessageHandlerDiscovery(IHandlerRegistry registry)
 {
     _registry = registry;
 }
 public UnitIncomingPipelineFactory(IHandlerRegistry registry, ICollection <LogicalMessage> incoming)
 {
     this.incoming = incoming;
     this.registry = registry;
 }
Exemple #32
0
 public DynamicDispatcher(IHandlerRegistry handlerRegistry, IServiceProvider serviceProvider, IUnitOfWork unitOfWork)
 {
     this.handlerRegistry = handlerRegistry;
     this.serviceProvider = serviceProvider;
     this.unitOfWork      = unitOfWork;
 }
Exemple #33
0
 public static IReadOnlyCollection <object> ConsumeAll(this IHandlerRegistry registry)
 {
     return(new ReadOnlyCollection <object>(new List <object>()));
 }
Exemple #34
0
 public static IEnumerable <IQueryHandlerWrapper <TQuery, TResult> > GetQueryHandlerWrappers <TQuery, TResult>(this IHandlerRegistry handlerRegistry)
     where TQuery : IQuery <TResult> => handlerRegistry.GetQueryHandlerWrappers(typeof(TQuery), typeof(TResult)).Cast <IQueryHandlerWrapper <TQuery, TResult> >();
 public static IEnumerable <Func <object, Action <object>, Task> > FindHandler <T>(this IHandlerRegistry registry)
 {
     return(registry.FindHandler(typeof(T)));
 }
Exemple #36
0
 public IncomingPipelineFactory(IHandlerRegistry registry, IMessageSerializer serializer)
 {
     this.registry   = registry;
     this.serializer = serializer;
 }
 public LoadMessageHandlersStep(IHandlerRegistry registry)
 {
     this.registry = registry;
 }
 public LoadMessageHandlersStep(IHandlerRegistry registry)
 {
     this.registry = registry;
 }
Exemple #39
0
 private CommandInterpreter(IDictionary <int, CommandHandler> interpreters, IDictionary <Type, FormatterInfo> formatters)
 {
     this.interpreters = CreateRegistry(interpreters);
     this.formatters   = ImmutableDictionary.ToImmutableDictionary(formatters);
 }
 public DefaultEventDispatcher(IHandlerRegistry handlerRegistry)
     : this(handlerRegistry, new DefaultHandlerInvoker())
 {
 }