private static bool ProcessInput(string shortcut, bool isGlobal)
        {
            if (!IsEnabled)
            {
                return(false);
            }

            InputMapping mapping = CommandMappings.FirstOrDefault(
                c => c.KeyboardShortcut == shortcut &&
                c.IsGlobal == isGlobal);

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

            Debug.WriteLine($"Processing '{shortcut}' (global = {isGlobal}) => {mapping.CommandId}");

            if (!Commands.ContainsKey(mapping.CommandId))
            {
                return(false);
            }

            ScriptplayerCommand command = Commands[mapping.CommandId];

            if (!command.CanExecute(null))
            {
                return(false);
            }

            command.Execute(null);
            return(true);
        }
Esempio n. 2
0
        public static bool ProcessInput(Key key, ModifierKeys modifiers)
        {
            string shortcut = GetShortcut(key, modifiers);

            InputMapping mapping = CommandMappings.FirstOrDefault(c => c.KeyboardShortcut == shortcut);

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

            if (!Commands.ContainsKey(mapping.CommandId))
            {
                return(false);
            }

            ScriptplayerCommand command = Commands[mapping.CommandId];

            if (!command.CanExecute(null))
            {
                return(false);
            }

            command.Execute(null);
            return(true);
        }
        protected override void DoSetUp()
        {
            var commandMappings = new CommandMappings()
                                  .Map <CustomMappedErronousCommand>((context, command) =>
            {
                throw new InvalidOperationException("oh no, you cannot do that");
            });

            var services = new ServiceCollection();

            services.AddCirqus(config =>
                               config.EventStore(e => _eventStore = e.UseInMemoryEventStore())
                               .EventDispatcher(e => e.UseEventDispatcher(c =>
                                                                          new ConsoleOutEventDispatcher(c.GetService <IEventStore>())))
                               .Options(o =>
            {
                o.AddDomainExceptionType <InvalidOperationException>();
                o.AddCommandMappings(commandMappings);
            }));

            var provider = services.BuildServiceProvider();

            _cirqus = provider.GetService <ICommandProcessor>();

            RegisterForDisposal(_cirqus);
        }
Esempio n. 4
0
        protected override void DoSetUp()
        {
            var commandMappings = new CommandMappings()
                                  .Map <CustomMappedErronousCommand>((context, command) =>
            {
                throw new InvalidOperationException("oh no, you cannot do that");
            });

            _cirqus = CommandProcessor.With()
                      .EventStore(e => _eventStore = e.UseInMemoryEventStore())
                      .EventDispatcher(e => e.UseEventDispatcher(c => new ConsoleOutEventDispatcher()))
                      .Options(o =>
            {
                o.AddDomainExceptionType <InvalidOperationException>();
                o.AddCommandMappings(commandMappings);
            })
                      .Create();

            RegisterForDisposal(_cirqus);
        }
Esempio n. 5
0
        private static bool ProcessInput(string shortcut, bool isGlobal)
        {
            if (!IsEnabled)
            {
                return(false);
            }

            InputMapping mapping = CommandMappings.FirstOrDefault(
                c => c.KeyboardShortcut == shortcut &&
                c.IsGlobal == isGlobal);

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

            Debug.WriteLine($"Processing '{shortcut}' (global = {isGlobal}) => {mapping.CommandId}");

            return(ExecuteCommand(mapping.CommandId));
        }
        public static bool ProcessInput(Key key, ModifierKeys modifiers, KeySource source)
        {
            if (OnPreviewKeyReceived(key, modifiers))
            {
                return(true);
            }

            if (!IsEnabled)
            {
                return(false);
            }

            bool   isGlobal = source == KeySource.Global;
            string shortcut = GetShortcut(key, modifiers);

            InputMapping mapping = CommandMappings.FirstOrDefault(
                c => c.KeyboardShortcut == shortcut &&
                c.IsGlobal == isGlobal);

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

            Debug.WriteLine($"Processing '{shortcut}' from {source} => {mapping.CommandId}");

            if (!Commands.ContainsKey(mapping.CommandId))
            {
                return(false);
            }

            ScriptplayerCommand command = Commands[mapping.CommandId];

            if (!command.CanExecute(null))
            {
                return(false);
            }

            command.Execute(null);
            return(true);
        }
Esempio n. 7
0
        protected override void DoSetUp()
        {
            var commandMappings = new CommandMappings()
                                  .Map <RawRootCommand>((context, command) =>
            {
                var instance = context.TryLoad <Root>(command.AggregateRootId)
                               ?? context.Create <Root>(command.AggregateRootId);

                instance.DoStuff();
            })
                                  .Map <AnotherRawRootCommand>((context, command) =>
            {
                var instance = context.TryLoad <Root>(command.AggregateRootId)
                               ?? context.Create <Root>(command.AggregateRootId);

                instance
                .DoStuff()
                .DoStuff();

                var otherInstance = context.TryLoad <Root>(command.AggregateRootId + "w00t!")
                                    ?? context.Create <Root>(command.AggregateRootId + "w00t!");

                otherInstance
                .DoStuff()
                .DoStuff()
                .DoStuff();
            });

            _realCommandProcessor = CommandProcessor.With()
                                    .EventStore(e => e.Register <IEventStore>(c => new InMemoryEventStore()))
                                    .Options(o => o.AddCommandMappings(commandMappings))
                                    .Create();

            RegisterForDisposal(_realCommandProcessor);

            _fakeCommandProcessor = TestContext.With()
                                    .Options(x => x.AddCommandMappings(commandMappings))
                                    .Create();
        }
Esempio n. 8
0
 public void AddMappings(CommandMappings commandMappings)
 {
     _commandMappings.Add(commandMappings);
 }
Esempio n. 9
0
 /// <summary>
 /// Decorates the <see cref="ICommandMapper"/> pipeline with a command mapper that can use the given <see cref="CommandMappings"/>
 /// </summary>
 public void AddCommandMappings(CommandMappings mappings)
 {
     Decorate(c => mappings.CreateCommandMapperDecorator(c.Get <ICommandMapper>()));
 }
Esempio n. 10
0
 public void AddMappings(CommandMappings commandMappings)
 {
     _commandMappings.Add(commandMappings);
 }
Esempio n. 11
0
 /// <summary>
 /// Decorates the <see cref="ICommandMapper"/> pipeline with a command mapper that can use the given <see cref="CommandMappings"/>
 /// </summary>
 public void AddCommandMappings(CommandMappings mappings)
 {
     Decorate <ICommandMapper>((inner, ctx) => mappings.CreateCommandMapperDecorator(inner));
 }