public NavigationPresenter(INavigationView view,
            ISettingsSerializer settingsSerializer,
            IKeyboardListener keyboardListener,
            IMatchModelMapper matchModelMapper,
            IPresentationService presentationService,
            INavigationServiceBuilder navigationServiceBuilder)
        {
            _view = view;
            _settingsSerializer = settingsSerializer;
            _keyboardListener = keyboardListener;
            _matchModelMapper = matchModelMapper;
            _navigationServiceBuilder = navigationServiceBuilder;
            _presentationService = presentationService;

            Settings settings = _settingsSerializer.Deserialize();

            _keyboardListener.KeyCombinationPressed += GlobalKeyCombinationPressed;
            _keyboardListener.StartListening(settings.GlobalKeyCombination);

            _view.CurrentSettings = settings;
            _view.ShowMatches(new List<MatchModel> {new MatchModel(_matchModelMapper, Resources.InitialMatchesMessage)});
            _view.ShowInitializingScreen = true;

            //Initialize navigation service asynchronously, as it may require a long operation (file system parsing).
            //Clone settings to avoid any coupling
            Settings settingsCopy = settings.Clone() as Settings;
            InitializeDelegate initialize = Initialize;
            initialize.BeginInvoke(settingsCopy, EndInitialize, initialize);
        }
        public NavigationPresenter(INavigationView view,
                                   ISettingsSerializer settingsSerializer,
                                   IKeyboardListener keyboardListener,
                                   IMatchModelMapper matchModelMapper,
                                   IPresentationService presentationService,
                                   INavigationServiceBuilder navigationServiceBuilder)
        {
            _view = view;
            _settingsSerializer       = settingsSerializer;
            _keyboardListener         = keyboardListener;
            _matchModelMapper         = matchModelMapper;
            _navigationServiceBuilder = navigationServiceBuilder;
            _presentationService      = presentationService;

            Settings settings = _settingsSerializer.Deserialize();

            _keyboardListener.KeyCombinationPressed += GlobalKeyCombinationPressed;
            _keyboardListener.StartListening(settings.GlobalKeyCombination);

            _view.CurrentSettings = settings;
            _view.ShowMatches(new List <MatchModel> {
                new MatchModel(_matchModelMapper, Resources.InitialMatchesMessage)
            });
            _view.ShowInitializingScreen = true;

            //Initialize navigation service asynchronously, as it may require a long operation (file system parsing).
            //Clone settings to avoid any coupling
            Settings           settingsCopy = settings.Clone() as Settings;
            InitializeDelegate initialize   = Initialize;

            initialize.BeginInvoke(settingsCopy, EndInitialize, initialize);
        }
Example #3
0
        //For keysToPress refer to http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx
        public void TestListeningToKeyCombination(Keys keysToListen, string keysToPress, bool shouldRaiseEvent)
        {
            _keyboardListener.StartListening(keysToListen);

            SendKeys.SendWait(keysToPress);

            Thread.Sleep(200);

            Assert.That(_keyPressHandled, Is.EqualTo(shouldRaiseEvent));
        }
        public void UpdateSettings(Settings settings)
        {
            lock (_syncObject)
            {
                _view.CurrentSettings = settings;

                _keyboardListener.StopListening();
                _keyboardListener.StartListening(settings.GlobalKeyCombination);

                if (_navigationAssistant != null)
                {
                    //This code will not be called, if _navigationServiceBuilder is used in the
                    //Initialize function; so we don't need to synchronize _navigationServiceBuilder additionally.
                    _navigationServiceBuilder.UpdateNavigationSettings(_navigationAssistant, settings);
                }
            }
        }