Esempio n. 1
0
            private void ExecuteCommandFromEvent(object sender, EventArgs args)
            {
                BaseEventArgs typedArgs = (BaseEventArgs)args;

                CommandMapping mapping = commandMappings[sender.GetType()];

                if (!mapping.HasMapping(typedArgs.EventId))
                {
                    return;
                }

                foreach (Type commandType in mapping.GetCommandTypes(typedArgs.EventId))
                {
                    ICommand command = GetCommandInstance(commandType, typedArgs);
                    command.Execute();
                }
            }
Esempio n. 2
0
            public void MapCommand(Type dispatcherType, int eventId, Type commandType)
            {
                if (!typeof(IEventDispatcher).IsAssignableFrom(dispatcherType))
                {
                    throw new Exception($"Type {dispatcherType} must implement IDispatcher.");
                }

                if (!typeof(ICommand).IsAssignableFrom(commandType))
                {
                    throw new Exception($"Type {commandType} must implement ICommand.");
                }

                if (!commandMappings.ContainsKey(dispatcherType))
                {
                    CommandMapping mapping = new CommandMapping(dispatcherType);
                    mapping.MapEvent(eventId, commandType);
                    commandMappings.Add(dispatcherType, mapping);
                }
                else
                {
                    CommandMapping mapping = commandMappings[dispatcherType];
                    mapping.MapEvent(eventId, commandType);
                }
            }