Exemplo n.º 1
0
        public MainViewModel(
            IAudioService audioService,
            ICalibrationService calibrationService,
            IDictionaryService dictionaryService,
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            IInputService inputService,
            IKeyboardOutputService keyboardOutputService,
            IMouseOutputService mouseOutputService,
            IWindowManipulationService mainWindowManipulationService,
            List<INotifyErrors> errorNotifyingServices)
        {
            this.audioService = audioService;
            this.calibrationService = calibrationService;
            this.dictionaryService = dictionaryService;
            this.keyStateService = keyStateService;
            this.suggestionService = suggestionService;
            this.capturingStateManager = capturingStateManager;
            this.lastMouseActionStateManager = lastMouseActionStateManager;
            this.inputService = inputService;
            this.keyboardOutputService = keyboardOutputService;
            this.mouseOutputService = mouseOutputService;
            this.mainWindowManipulationService = mainWindowManipulationService;
            this.errorNotifyingServices = errorNotifyingServices;

            calibrateRequest = new InteractionRequest<NotificationWithCalibrationResult>();
            SelectionMode = SelectionModes.Key;

            InitialiseKeyboard(mainWindowManipulationService);
            AttachScratchpadEnabledListener();
            AttachKeyboardSupportsCollapsedDockListener(mainWindowManipulationService);
            AttachKeyboardSupportsSimulateKeyStrokesListener();
        }
Exemplo n.º 2
0
        public MainViewModel(
            IAudioService audioService,
            ICalibrationService calibrationService,
            IDictionaryService dictionaryService,
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            IInputService inputService,
            IKeyboardOutputService keyboardOutputService,
            IMouseOutputService mouseOutputService,
            IWindowManipulationService mainWindowManipulationService,
            List <INotifyErrors> errorNotifyingServices)
        {
            this.audioService                  = audioService;
            this.calibrationService            = calibrationService;
            this.dictionaryService             = dictionaryService;
            this.keyStateService               = keyStateService;
            this.suggestionService             = suggestionService;
            this.capturingStateManager         = capturingStateManager;
            this.lastMouseActionStateManager   = lastMouseActionStateManager;
            this.inputService                  = inputService;
            this.keyboardOutputService         = keyboardOutputService;
            this.mouseOutputService            = mouseOutputService;
            this.mainWindowManipulationService = mainWindowManipulationService;
            this.errorNotifyingServices        = errorNotifyingServices;

            calibrateRequest = new InteractionRequest <NotificationWithCalibrationResult>();
            SelectionMode    = SelectionModes.Key;

            InitialiseKeyboard(mainWindowManipulationService);
            AttachScratchpadEnabledListener();
            AttachKeyboardSupportsCollapsedDockListener(mainWindowManipulationService);
            AttachKeyboardSupportsSimulateKeyStrokesListener();
        }
Exemplo n.º 3
0
        public KeyEnabledStates(
            IKeyboardService keyboardService, 
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            ICalibrationService calibrationService,
            IWindowStateService mainWindowStateService)
        {
            this.keyboardService = keyboardService;
            this.suggestionService = suggestionService;
            this.capturingStateManager = capturingStateManager;
            this.lastMouseActionStateManager = lastMouseActionStateManager;
            this.calibrationService = calibrationService;
            this.mainWindowStateService = mainWindowStateService;

            suggestionService.OnPropertyChanges(ss => ss.Suggestions).Subscribe(_ => NotifyStateChanged());
            suggestionService.OnPropertyChanges(ss => ss.SuggestionsPage).Subscribe(_ => NotifyStateChanged());
            suggestionService.OnPropertyChanges(ss => ss.SuggestionsPerPage).Subscribe(_ => NotifyStateChanged());

            keyboardService.KeyDownStates[KeyValues.SimulateKeyStrokesKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyboardService.KeyDownStates[KeyValues.SleepKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());

            KeyValues.KeysWhichPreventTextCaptureIfDownOrLocked.ForEach(kv =>
                keyboardService.KeyDownStates[kv].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged()));

            capturingStateManager.OnPropertyChanges(csm => csm.CapturingMultiKeySelection).Subscribe(_ => NotifyStateChanged());

            lastMouseActionStateManager.OnPropertyChanges(lmasm => lmasm.LastMouseActionExists).Subscribe(_ => NotifyStateChanged());

            mainWindowStateService.OnPropertyChanges(mwss => mwss.WindowState).Subscribe(_ => NotifyStateChanged());
        }
Exemplo n.º 4
0
        public PositionPage(Position position)
        {
            InitializeComponent();
            var serviceProvider = Startup.ServiceProvider;

            this.wifiConnector             = serviceProvider.GetService <IWifiConnector>();
            this.bluetoothConnector        = serviceProvider.GetService <IBluetoothConnector>();
            this.magneticFieldSensor       = serviceProvider.GetService <MagneticFieldSensor>();
            this.calibrationsService       = serviceProvider.GetService <ICalibrationService>();
            this.positionSignalDataService = serviceProvider.GetService <IPositionSignalDataService>();
            this.positionEstimationService = serviceProvider.GetService <IPositionEstimationService>();
            this.localeProvider            = serviceProvider.GetService <LocaleProvider>();
            this.configuration             = serviceProvider.GetService <Configuration>();
            this.Position = position;

            PositionSignalDataCollection.RefreshCommand = RefreshData_Command;
            PositionSignalDataCollection.ItemsSource    = PositionSignalData;
            Position.PositionSignalData?
            .OrderBy(data => data.SignalType)
            .ThenByDescending(data => data.Strength)
            .ToList()
            .ForEach(data => PositionSignalData.Add(new PositionSignalDataView(data)));

            BindingContext = this;
            timer          = new Timer(configuration !.DataAquisitionInterval * 1000);
            timer.Elapsed += UpdateMonitoringState;
            timer.Start();
            countLabel.Text = count.ToString();
        }
Exemplo n.º 5
0
        public KeyEnabledStates(
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            ICalibrationService calibrationService)
        {
            this.keyStateService             = keyStateService;
            this.suggestionService           = suggestionService;
            this.capturingStateManager       = capturingStateManager;
            this.lastMouseActionStateManager = lastMouseActionStateManager;
            this.calibrationService          = calibrationService;

            suggestionService.OnPropertyChanges(ss => ss.Suggestions).Subscribe(_ => NotifyStateChanged());
            suggestionService.OnPropertyChanges(ss => ss.SuggestionsPage).Subscribe(_ => NotifyStateChanged());
            suggestionService.OnPropertyChanges(ss => ss.SuggestionsPerPage).Subscribe(_ => NotifyStateChanged());

            keyStateService.OnPropertyChanges(kss => kss.SimulateKeyStrokes).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseLeftDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseMiddleDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.MouseRightDownUpKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());
            keyStateService.KeyDownStates[KeyValues.SleepKey].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged());

            KeyValues.KeysWhichPreventTextCaptureIfDownOrLocked.ForEach(kv =>
                                                                        keyStateService.KeyDownStates[kv].OnPropertyChanges(np => np.Value).Subscribe(_ => NotifyStateChanged()));

            capturingStateManager.OnPropertyChanges(csm => csm.CapturingMultiKeySelection).Subscribe(_ => NotifyStateChanged());

            lastMouseActionStateManager.OnPropertyChanges(lmasm => lmasm.LastMouseActionExists).Subscribe(_ => NotifyStateChanged());

            Settings.Default.OnPropertyChanges(s => s.MultiKeySelectionEnabled).Subscribe(_ => NotifyStateChanged());
            Settings.Default.OnPropertyChanges(s => s.MainWindowState).Subscribe(_ => NotifyStateChanged());
            Settings.Default.OnPropertyChanges(s => s.MainWindowDockPosition).Subscribe(_ => NotifyStateChanged());
        }
Exemplo n.º 6
0
        public KeyboardService(
            ISuggestionStateService suggestionService, 
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            ICalibrationService calibrationService,
            IWindowStateService mainWindowStateService)
        {
            keySelectionProgress = new NotifyingConcurrentDictionary<KeyValue, double>();
            keyDownStates = new NotifyingConcurrentDictionary<KeyValue, KeyDownStates>();
            keyEnabledStates = new KeyEnabledStates(this, suggestionService, capturingStateManager, lastMouseActionStateManager, calibrationService, mainWindowStateService);

            InitialiseKeyDownStates();
            AddKeyboardSetChangeHandlers();
            AddKeyDownStatesChangeHandlers();
        }
Exemplo n.º 7
0
        public KeyStateService(
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            ICalibrationService calibrationService,
            Action <KeyValue> fireKeySelectionEvent)
        {
            this.fireKeySelectionEvent = fireKeySelectionEvent;
            this.keySelectionProgress  = new NotifyingConcurrentDictionary <KeyValue, double>();
            this.keyDownStates         = new NotifyingConcurrentDictionary <KeyValue, KeyDownStates>();
            this.keyEnabledStates      = new KeyEnabledStates(this, suggestionService, capturingStateManager, lastMouseActionStateManager, calibrationService);

            InitialiseKeyDownStates();
            AddSettingChangeHandlers();
            AddSimulateKeyStrokesChangeHandler();
            AddKeyDownStatesChangeHandlers();
        }
Exemplo n.º 8
0
        public KeyStateService(
            ISuggestionStateService suggestionService, 
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            ICalibrationService calibrationService,
            Action<KeyValue> fireKeySelectionEvent)
        {
            this.fireKeySelectionEvent = fireKeySelectionEvent;
            keySelectionProgress = new NotifyingConcurrentDictionary<KeyValue, double>();
            keyDownStates = new NotifyingConcurrentDictionary<KeyValue, KeyDownStates>();
            keyEnabledStates = new KeyEnabledStates(this, suggestionService, capturingStateManager, lastMouseActionStateManager, calibrationService);

            InitialiseKeyDownStates();
            AddSettingChangeHandlers();
            AddSimulateKeyStrokesChangeHandler();
            AddKeyDownStatesChangeHandlers();
        }
Exemplo n.º 9
0
        public MainViewModel(
            IAudioService audioService,
            ICalibrationService calibrationService,
            IDictionaryService dictionaryService,
            IKeyStateService keyStateService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            IInputService inputService,
            IKeyboardOutputService keyboardOutputService,
            IMouseOutputService mouseOutputService,
            IWindowManipulationService mainWindowManipulationService,
            List <INotifyErrors> errorNotifyingServices)
        {
            this.audioService                  = audioService;
            this.calibrationService            = calibrationService;
            this.dictionaryService             = dictionaryService;
            this.keyStateService               = keyStateService;
            this.suggestionService             = suggestionService;
            this.capturingStateManager         = capturingStateManager;
            this.lastMouseActionStateManager   = lastMouseActionStateManager;
            this.inputService                  = inputService;
            this.keyboardOutputService         = keyboardOutputService;
            this.mouseOutputService            = mouseOutputService;
            this.mainWindowManipulationService = mainWindowManipulationService;
            this.errorNotifyingServices        = errorNotifyingServices;

            calibrateRequest = new InteractionRequest <NotificationWithCalibrationResult>();
            SelectionMode    = SelectionModes.Key;

            this.translationService = new TranslationService(new HttpClient());

            SetupInputServiceEventHandlers();
            InitialiseKeyboard(mainWindowManipulationService);
            AttachScratchpadEnabledListener();
            AttachKeyboardSupportsCollapsedDockListener(mainWindowManipulationService);
            AttachKeyboardSupportsSimulateKeyStrokesListener();
            AttachKeyboardSupportsMultiKeySelectionListener();
            ShowCrosshair = Settings.Default.GazeIndicatorStyle == GazeIndicatorStyles.Crosshair ||
                            Settings.Default.GazeIndicatorStyle == GazeIndicatorStyles.Scope;
            ShowMonical = Settings.Default.GazeIndicatorStyle == GazeIndicatorStyles.Monical ||
                          Settings.Default.GazeIndicatorStyle == GazeIndicatorStyles.Scope;
        }
Exemplo n.º 10
0
 private void LoadData()
 {
     try
     {
         ICalibrationService irms = ServiceFactory.Create <ICalibrationService>();
         var req = new GetCalibrationDetailRequest
         {
             Time = _dtQuery
         };
         var res = irms.GetBxDetail(req);
         if (!res.IsSuccess)
         {
             throw new Exception(res.Message);
         }
         BxDetailGri.DataSource = res.Data;
     }
     catch
     {
         MessageBox.Show("数据获取失败,请稍后再试。");
     }
 }
Exemplo n.º 11
0
        public MainViewModel(
            IAudioService audioService,
            ICalibrationService calibrationService,
            IDictionaryService dictionaryService,
            IKeyboardService keyboardService,
            ISuggestionStateService suggestionService,
            ICapturingStateManager capturingStateManager,
            ILastMouseActionStateManager lastMouseActionStateManager,
            IInputService inputService,
            IOutputService outputService,
            IWindowManipulationService mainWindowManipulationService,
            List<INotifyErrors> errorNotifyingServices)
        {
            Log.Debug("Ctor called.");

            this.audioService = audioService;
            this.calibrationService = calibrationService;
            this.dictionaryService = dictionaryService;
            this.keyboardService = keyboardService;
            this.suggestionService = suggestionService;
            this.capturingStateManager = capturingStateManager;
            this.lastMouseActionStateManager = lastMouseActionStateManager;
            this.inputService = inputService;
            this.outputService = outputService;
            this.mainWindowManipulationService = mainWindowManipulationService;
            this.errorNotifyingServices = errorNotifyingServices;

            calibrateRequest = new InteractionRequest<NotificationWithCalibrationResult>();

            SelectionMode = SelectionModes.Key;
            Keyboard = new Alpha();

            SelectKeyboardOnKeyboardSetChanges();
            AttachScratchpadEnabledListener();

            HandleFunctionKeySelectionResult(KeyValues.LeftShiftKey); //Set initial shift state to on
        }
Exemplo n.º 12
0
        private async void App_OnStartup(object sender, StartupEventArgs e)
        {
            try
            {
                Log.Info("Boot strapping the services and UI.");

                //Apply theme
                applyTheme();

                //Define MainViewModel before services so I can setup a delegate to call into the MainViewModel
                //This is to work around the fact that the MainViewModel is created after the services.
                MainViewModel     mainViewModel         = null;
                Action <KeyValue> fireKeySelectionEvent = kv =>
                {
                    if (mainViewModel != null) //Access to modified closure is a good thing here, for once!
                    {
                        mainViewModel.FireKeySelectionEvent(kv);
                    }
                };

                //Create services
                var                          errorNotifyingServices      = new List <INotifyErrors>();
                IAudioService                audioService                = new AudioService();
                IDictionaryService           dictionaryService           = new DictionaryService();
                IPublishService              publishService              = new PublishService();
                ISuggestionStateService      suggestionService           = new SuggestionStateService();
                ICalibrationService          calibrationService          = CreateCalibrationService();
                ICapturingStateManager       capturingStateManager       = new CapturingStateManager(audioService);
                ILastMouseActionStateManager lastMouseActionStateManager = new LastMouseActionStateManager();
                IKeyStateService             keyStateService             = new KeyStateService(suggestionService, capturingStateManager, lastMouseActionStateManager, calibrationService, fireKeySelectionEvent);
                IInputService                inputService                = CreateInputService(keyStateService, dictionaryService, audioService, calibrationService, capturingStateManager, errorNotifyingServices);
                IKeyboardOutputService       keyboardOutputService       = new KeyboardOutputService(keyStateService, suggestionService, publishService, dictionaryService, fireKeySelectionEvent);
                IMouseOutputService          mouseOutputService          = new MouseOutputService(publishService);
                errorNotifyingServices.Add(audioService);
                errorNotifyingServices.Add(dictionaryService);
                errorNotifyingServices.Add(publishService);
                errorNotifyingServices.Add(inputService);

                //Release keys on application exit
                ReleaseKeysOnApplicationExit(keyStateService, publishService);

                //Compose UI
                var mainWindow = new MainWindow(audioService, dictionaryService, inputService);

                IWindowManipulationService mainWindowManipulationService = new WindowManipulationService(
                    mainWindow,
                    () => Settings.Default.MainWindowOpacity,
                    () => Settings.Default.MainWindowState,
                    () => Settings.Default.MainWindowPreviousState,
                    () => Settings.Default.MainWindowFloatingSizeAndPosition,
                    () => Settings.Default.MainWindowDockPosition,
                    () => Settings.Default.MainWindowDockSize,
                    () => Settings.Default.MainWindowFullDockThicknessAsPercentageOfScreen,
                    () => Settings.Default.MainWindowCollapsedDockThicknessAsPercentageOfFullDockThickness,
                    () => Settings.Default.MainWindowMinimisedPosition,
                    o => Settings.Default.MainWindowOpacity                               = o,
                    state => Settings.Default.MainWindowState                             = state,
                    state => Settings.Default.MainWindowPreviousState                     = state,
                    rect => Settings.Default.MainWindowFloatingSizeAndPosition            = rect,
                    pos => Settings.Default.MainWindowDockPosition                        = pos,
                    size => Settings.Default.MainWindowDockSize                           = size,
                    t => Settings.Default.MainWindowFullDockThicknessAsPercentageOfScreen = t,
                    t => Settings.Default.MainWindowCollapsedDockThicknessAsPercentageOfFullDockThickness = t);

                errorNotifyingServices.Add(mainWindowManipulationService);

                mainViewModel = new MainViewModel(
                    audioService, calibrationService, dictionaryService, keyStateService,
                    suggestionService, capturingStateManager, lastMouseActionStateManager,
                    inputService, keyboardOutputService, mouseOutputService, mainWindowManipulationService, errorNotifyingServices);

                mainWindow.MainView.DataContext = mainViewModel;

                //Setup actions to take once main view is loaded (i.e. the view is ready, so hook up the services which kicks everything off)
                Action postMainViewLoaded = mainViewModel.AttachServiceEventHandlers;
                if (mainWindow.MainView.IsLoaded)
                {
                    postMainViewLoaded();
                }
                else
                {
                    RoutedEventHandler loadedHandler = null;
                    loadedHandler = (s, a) =>
                    {
                        postMainViewLoaded();
                        mainWindow.MainView.Loaded -= loadedHandler; //Ensure this handler only triggers once
                    };
                    mainWindow.MainView.Loaded += loadedHandler;
                }

                //Show the main window
                mainWindow.Show();

                //Display splash screen and check for updates (and display message) after the window has been sized and positioned for the 1st time
                EventHandler sizeAndPositionInitialised = null;
                sizeAndPositionInitialised = async(_, __) =>
                {
                    mainWindowManipulationService.SizeAndPositionInitialised -= sizeAndPositionInitialised; //Ensure this handler only triggers once
                    await ShowSplashScreen(inputService, audioService, mainViewModel);

                    inputService.RequestResume(); //Start the input service
                    await CheckForUpdates(inputService, audioService, mainViewModel);
                };
                if (mainWindowManipulationService.SizeAndPositionIsInitialised)
                {
                    sizeAndPositionInitialised(null, null);
                }
                else
                {
                    mainWindowManipulationService.SizeAndPositionInitialised += sizeAndPositionInitialised;
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error starting up application", ex);
                throw;
            }
        }
Exemplo n.º 13
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            try
            {
                Log.Info("Boot strapping the services and UI.");

                // We manually close this because automatic closure steals focus from the
                // dynamic splash screen.
                splashScreen.Close(TimeSpan.FromSeconds(0.5f));

                //Apply theme
                applyTheme();

                //Define MainViewModel before services so I can setup a delegate to call into the MainViewModel
                //This is to work around the fact that the MainViewModel is created after the services.
                MainViewModel     mainViewModel         = null;
                Action <KeyValue> fireKeySelectionEvent = kv =>
                {
                    if (mainViewModel != null) //Access to modified closure is a good thing here, for once!
                    {
                        mainViewModel.FireKeySelectionEvent(kv);
                    }
                };

                CleanupAndPrepareCommuniKateInitialState();

                ValidateDynamicKeyboardLocation();

                // Handle plugins. Validate if directory exists and is accessible and pre-load all plugins, building a in-memory list of available ones.
                ValidatePluginsLocation();
                if (Settings.Default.EnablePlugins)
                {
                    PluginEngine.LoadAvailablePlugins();
                }

                var presageInstallationProblem = PresageInstallationProblemsDetected();

                //Create services
                var           errorNotifyingServices = new List <INotifyErrors>();
                IAudioService audioService           = new AudioService();

                IDictionaryService           dictionaryService           = new DictionaryService(Settings.Default.SuggestionMethod);
                IPublishService              publishService              = new PublishService();
                ISuggestionStateService      suggestionService           = new SuggestionStateService();
                ICalibrationService          calibrationService          = CreateCalibrationService();
                ICapturingStateManager       capturingStateManager       = new CapturingStateManager(audioService);
                ILastMouseActionStateManager lastMouseActionStateManager = new LastMouseActionStateManager();
                IKeyStateService             keyStateService             = new KeyStateService(suggestionService, capturingStateManager, lastMouseActionStateManager, calibrationService, fireKeySelectionEvent);
                IInputService inputService = CreateInputService(keyStateService, dictionaryService, audioService,
                                                                calibrationService, capturingStateManager, errorNotifyingServices);
                IKeyboardOutputService keyboardOutputService = new KeyboardOutputService(keyStateService, suggestionService, publishService, dictionaryService, fireKeySelectionEvent);
                IMouseOutputService    mouseOutputService    = new MouseOutputService(publishService);
                errorNotifyingServices.Add(audioService);
                errorNotifyingServices.Add(dictionaryService);
                errorNotifyingServices.Add(publishService);
                errorNotifyingServices.Add(inputService);

                ReleaseKeysOnApplicationExit(keyStateService, publishService);

                //Compose UI
                var mainWindow = new MainWindow(audioService, dictionaryService, inputService, keyStateService);
                IWindowManipulationService mainWindowManipulationService = CreateMainWindowManipulationService(mainWindow);
                errorNotifyingServices.Add(mainWindowManipulationService);
                mainWindow.WindowManipulationService = mainWindowManipulationService;

                //Subscribing to the on closing events.
                mainWindow.Closing += dictionaryService.OnAppClosing;

                mainViewModel = new MainViewModel(
                    audioService, calibrationService, dictionaryService, keyStateService,
                    suggestionService, capturingStateManager, lastMouseActionStateManager,
                    inputService, keyboardOutputService, mouseOutputService, mainWindowManipulationService,
                    errorNotifyingServices);

                mainWindow.SetMainViewModel(mainViewModel);

                //Setup actions to take once main view is loaded (i.e. the view is ready, so hook up the services which kicks everything off)
                Action postMainViewLoaded = () =>
                {
                    mainViewModel.AttachErrorNotifyingServiceHandlers();
                    mainViewModel.AttachInputServiceEventHandlers();
                };

                mainWindow.AddOnMainViewLoadedAction(postMainViewLoaded);

                //Show the main window
                mainWindow.Show();

                if (Settings.Default.LookToScrollShowOverlayWindow)
                {
                    // Create the overlay window, but don't show it yet. It'll make itself visible when the conditions are right.
                    new LookToScrollOverlayWindow(mainViewModel);
                }

                //Display splash screen and check for updates (and display message) after the window has been sized and positioned for the 1st time
                EventHandler sizeAndPositionInitialised = null;
                sizeAndPositionInitialised = async(_, __) =>
                {
                    mainWindowManipulationService.SizeAndPositionInitialised -= sizeAndPositionInitialised; //Ensure this handler only triggers once
                    await ShowSplashScreen(inputService, audioService, mainViewModel, OptiKey.Properties.Resources.OPTIKEY_SYMBOL_DESCRIPTION);

                    await mainViewModel.RaiseAnyPendingErrorToastNotifications();
                    await AttemptToStartMaryTTSService(inputService, audioService, mainViewModel);
                    await AlertIfPresageBitnessOrBootstrapOrVersionFailure(presageInstallationProblem, inputService, audioService, mainViewModel);

                    inputService.RequestResume(); //Start the input service

                    await CheckForUpdates(inputService, audioService, mainViewModel);
                };

                if (mainWindowManipulationService.SizeAndPositionIsInitialised)
                {
                    sizeAndPositionInitialised(null, null);
                }
                else
                {
                    mainWindowManipulationService.SizeAndPositionInitialised += sizeAndPositionInitialised;
                }

                Current.Exit += (o, args) =>
                {
                    mainWindowManipulationService.PersistSizeAndPosition();
                    Settings.Default.Save();
                };
            }
            catch (Exception ex)
            {
                Log.Error("Error starting up application", ex);
                throw;
            }
        }
Exemplo n.º 14
0
 public async Task <ActionResult <List <Calibration> > > GetCalibrations(
     [FromServices] ICalibrationService calibrationService,
     [FromQuery] CalibrationsQuery query)
 {
     return(await calibrationService.GetCalibrations(query));
 }
Exemplo n.º 15
0
        private IInputService CreateInputService(
            IKeyStateService keyStateService,
            IDictionaryService dictionaryService,
            IAudioService audioService,
            ICalibrationService calibrationService,
            ICapturingStateManager capturingStateManager,
            List <INotifyErrors> errorNotifyingServices)
        {
            Log.Info("Creating InputService.");

            //Instantiate point source
            IPointSource pointSource;

            switch (Settings.Default.PointsSource)
            {
            case PointsSources.GazeTracker:
                pointSource = new GazeTrackerSource(
                    Settings.Default.PointTtl,
                    Settings.Default.GazeTrackerUdpPort,
                    new Regex(Settings.Default.GazeTrackerUdpRegex));
                break;

            case PointsSources.TheEyeTribe:
                var theEyeTribePointService = new TheEyeTribePointService();
                errorNotifyingServices.Add(theEyeTribePointService);
                pointSource = new PointServiceSource(
                    Settings.Default.PointTtl,
                    theEyeTribePointService);
                break;

            case PointsSources.TobiiEyeX:
            case PointsSources.TobiiRex:
            case PointsSources.TobiiPcEyeGo:
                var tobiiEyeXPointService       = new TobiiEyeXPointService();
                var tobiiEyeXCalibrationService = calibrationService as TobiiEyeXCalibrationService;
                if (tobiiEyeXCalibrationService != null)
                {
                    tobiiEyeXCalibrationService.EyeXHost = tobiiEyeXPointService.EyeXHost;
                }
                errorNotifyingServices.Add(tobiiEyeXPointService);
                pointSource = new PointServiceSource(
                    Settings.Default.PointTtl,
                    tobiiEyeXPointService);
                break;

            case PointsSources.MousePosition:
                pointSource = new MousePositionSource(
                    Settings.Default.PointTtl);
                break;

            default:
                throw new ArgumentException("'PointsSource' settings is missing or not recognised! Please correct and restart OptiKey.");
            }

            //Instantiate key trigger source
            ITriggerSource keySelectionTriggerSource;

            switch (Settings.Default.KeySelectionTriggerSource)
            {
            case TriggerSources.Fixations:
                keySelectionTriggerSource = new KeyFixationSource(
                    Settings.Default.KeySelectionTriggerFixationLockOnTime,
                    Settings.Default.KeySelectionTriggerFixationResumeRequiresLockOn,
                    Settings.Default.KeySelectionTriggerFixationCompleteTime,
                    Settings.Default.KeySelectionTriggerIncompleteFixationTtl,
                    pointSource.Sequence);
                break;

            case TriggerSources.KeyboardKeyDownsUps:
                keySelectionTriggerSource = new KeyboardKeyDownUpSource(
                    Settings.Default.KeySelectionTriggerKeyboardKeyDownUpKey,
                    pointSource.Sequence);
                break;

            case TriggerSources.MouseButtonDownUps:
                keySelectionTriggerSource = new MouseButtonDownUpSource(
                    Settings.Default.KeySelectionTriggerMouseDownUpButton,
                    pointSource.Sequence);
                break;

            default:
                throw new ArgumentException(
                          "'KeySelectionTriggerSource' setting is missing or not recognised! Please correct and restart OptiKey.");
            }

            //Instantiate point trigger source
            ITriggerSource pointSelectionTriggerSource;

            switch (Settings.Default.PointSelectionTriggerSource)
            {
            case TriggerSources.Fixations:
                pointSelectionTriggerSource = new PointFixationSource(
                    Settings.Default.PointSelectionTriggerFixationLockOnTime,
                    Settings.Default.PointSelectionTriggerFixationCompleteTime,
                    Settings.Default.PointSelectionTriggerLockOnRadiusInPixels,
                    Settings.Default.PointSelectionTriggerFixationRadiusInPixels,
                    pointSource.Sequence);
                break;

            case TriggerSources.KeyboardKeyDownsUps:
                pointSelectionTriggerSource = new KeyboardKeyDownUpSource(
                    Settings.Default.PointSelectionTriggerKeyboardKeyDownUpKey,
                    pointSource.Sequence);
                break;

            case TriggerSources.MouseButtonDownUps:
                pointSelectionTriggerSource = new MouseButtonDownUpSource(
                    Settings.Default.PointSelectionTriggerMouseDownUpButton,
                    pointSource.Sequence);
                break;

            default:
                throw new ArgumentException(
                          "'PointSelectionTriggerSource' setting is missing or not recognised! "
                          + "Please correct and restart OptiKey.");
            }

            var inputService = new InputService(keyStateService, dictionaryService, audioService, capturingStateManager,
                                                pointSource, keySelectionTriggerSource, pointSelectionTriggerSource);

            inputService.RequestSuspend(); //Pause it initially
            return(inputService);
        }
Exemplo n.º 16
0
        public MainWindow CreateKeyboard()
        {
            ////Apply resource language (and listen for changes)
            Action <OptiKey.Enums.Languages> applyResourceLanguage = language => OptiKey.Properties.Resources.Culture = language.ToCultureInfo();

            Settings.Default.OnPropertyChanges(s => s.UiLanguage).Subscribe(applyResourceLanguage);
            applyResourceLanguage(Settings.Default.UiLanguage);

            MainWindow mainWindow;

            //Define MainViewModel before services so I can setup a delegate to call into the MainViewModel
            //This is to work around the fact that the MainViewModel is created after the services.
            OptiKey.UI.ViewModels.MainViewModel mainViewModel = null;
            Action <KeyValue> fireKeySelectionEvent           = kv =>
            {
                if (mainViewModel != null) //Access to modified closure is a good thing here, for once!
                {
                    mainViewModel.FireKeySelectionEvent(kv);
                }
            };

            //Create services
            var                          errorNotifyingServices      = new List <INotifyErrors>();
            IAudioService                audioService                = new AudioService();
            IDictionaryService           dictionaryService           = new DictionaryService(OptiKey.Enums.AutoCompleteMethods.NGram);
            IPublishService              publishService              = new PublishService();
            ISuggestionStateService      suggestionService           = new SuggestionStateService();
            ICalibrationService          calibrationService          = OptiKey.App.CreateCalibrationService();
            ICapturingStateManager       capturingStateManager       = new CapturingStateManager(audioService);
            ILastMouseActionStateManager lastMouseActionStateManager = new LastMouseActionStateManager();
            IKeyStateService             keyStateService             = new KeyStateService(suggestionService, capturingStateManager, lastMouseActionStateManager, calibrationService, fireKeySelectionEvent);
            IInputService                inputService                = CreateInputService(keyStateService, dictionaryService, audioService, calibrationService, capturingStateManager, errorNotifyingServices);
            IKeyboardOutputService       keyboardOutputService       = new KeyboardOutputService(keyStateService, suggestionService, publishService, dictionaryService, fireKeySelectionEvent);
            IMouseOutputService          mouseOutputService          = new MouseOutputService(publishService);

            errorNotifyingServices.Add(audioService);
            errorNotifyingServices.Add(dictionaryService);
            errorNotifyingServices.Add(publishService);
            errorNotifyingServices.Add(inputService);

            //Release keys on application exit
            //ReleaseKeysOnApplicationExit(keyStateService, publishService);

            //Compose UI
            mainWindow = new MainWindow(audioService, dictionaryService, inputService, keyStateService);

            //for testing just hard code the size and position of the mainWindow

            ////get the size of the screen
            Rectangle screenSize   = Screen.PrimaryScreen.Bounds;
            double    windowWidth  = screenSize.Width - toolBarOffset;
            double    windowHeight = screenSize.Height * 0.40;

            Rect windowDimensions = new Rect(0, (screenSize.Height - windowHeight) - taskBarOffset, windowWidth, windowHeight);

            //Settings.Default.MainWindowFloatingSizeAndPosition = windowDimensions;

            IWindowManipulationService mainWindowManipulationService = new WindowManipulationService(
                mainWindow,
                () => Settings.Default.MainWindowOpacity,
                () => Settings.Default.MainWindowState,
                () => Settings.Default.MainWindowPreviousState,
                //() => Settings.Default.MainWindowFloatingSizeAndPosition,
                () => windowDimensions,
                () => Settings.Default.MainWindowDockPosition,
                () => Settings.Default.MainWindowDockSize,
                () => Settings.Default.MainWindowFullDockThicknessAsPercentageOfScreen,
                () => Settings.Default.MainWindowCollapsedDockThicknessAsPercentageOfFullDockThickness,
                () => Settings.Default.MainWindowMinimisedPosition,
                o => Settings.Default.MainWindowOpacity                               = o,
                state => Settings.Default.MainWindowState                             = state,
                state => Settings.Default.MainWindowPreviousState                     = state,
                rect => Settings.Default.MainWindowFloatingSizeAndPosition            = rect,
                pos => Settings.Default.MainWindowDockPosition                        = pos,
                size => Settings.Default.MainWindowDockSize                           = size,
                t => Settings.Default.MainWindowFullDockThicknessAsPercentageOfScreen = t,
                t => Settings.Default.MainWindowCollapsedDockThicknessAsPercentageOfFullDockThickness = t);

            errorNotifyingServices.Add(mainWindowManipulationService);
            mainWindow.WindowManipulationService = mainWindowManipulationService;

            mainViewModel = new MainViewModel(
                audioService, calibrationService, dictionaryService, keyStateService,
                suggestionService, capturingStateManager, lastMouseActionStateManager,
                inputService, keyboardOutputService, mouseOutputService, mainWindowManipulationService, errorNotifyingServices);

            mainWindow.MainView.DataContext = mainViewModel;

            //Setup actions to take once main view is loaded (i.e. the view is ready, so hook up the services which kicks everything off)
            Action postMainViewLoaded = mainViewModel.AttachServiceEventHandlers;

            if (mainWindow.MainView.IsLoaded)
            {
                postMainViewLoaded();
            }
            else
            {
                RoutedEventHandler loadedHandler = null;
                loadedHandler = (s, a) =>
                {
                    postMainViewLoaded();
                    mainWindow.MainView.Loaded -= loadedHandler; //Ensure this handler only triggers once
                };
                mainWindow.MainView.Loaded += loadedHandler;
            }

            //Show the main window
            ResourceDictionary resourses = new ResourceDictionary();

            mainWindow.Resources = resourses;
            ThemeResourceDictionary themeDictionary = new ThemeResourceDictionary();

            resourses.MergedDictionaries.Add(themeDictionary);

            //setSize

            //Display splash screen and check for updates (and display message) after the window has been sized and positioned for the 1st time
            EventHandler sizeAndPositionInitialised = null;

            sizeAndPositionInitialised = async(_, __) =>
            {
                mainWindowManipulationService.SizeAndPositionInitialised -= sizeAndPositionInitialised; //Ensure this handler only triggers once
                inputService.RequestResume();                                                           //Start the input service
            };
            if (mainWindowManipulationService.SizeAndPositionIsInitialised)
            {
                sizeAndPositionInitialised(null, null);
            }
            else
            {
                mainWindowManipulationService.SizeAndPositionInitialised += sizeAndPositionInitialised;
            }


            mainWindow.Closed           += (_, __) => ReleaseKeysOnApplicationExit(keyStateService, publishService);
            mainWindow.IsVisibleChanged += (_, __) => ReleaseKeysOnApplicationExit(keyStateService, publishService);

            return(mainWindow);
        }
Exemplo n.º 17
0
 public async Task <ActionResult <int> > CreateCalibrations(
     [FromServices] ICalibrationService calibrationService,
     [FromBody] CreateCalibrationsCommand command)
 {
     return(await calibrationService.CreateCalibrations(command));
 }
Exemplo n.º 18
0
 public async Task <ActionResult <bool> > DeleteCalibrations(
     [FromServices] ICalibrationService calibrationService,
     [FromQuery] CalibrationsQuery query)
 {
     return(await calibrationService.DeleteCalibrations(query));
 }
Exemplo n.º 19
0
        private static IInputService CreateInputService(
            IKeyStateService keyStateService,
            IDictionaryService dictionaryService,
            IAudioService audioService,
            ICalibrationService calibrationService,
            ICapturingStateManager capturingStateManager,
            List<INotifyErrors> errorNotifyingServices)
        {
            Log.Info("Creating InputService.");

            //Instantiate point source
            IPointSource pointSource;
            switch (Settings.Default.PointsSource)
            {
                case PointsSources.GazeTracker:
                    pointSource = new GazeTrackerSource(
                        Settings.Default.PointTtl,
                        Settings.Default.GazeTrackerUdpPort,
                        new Regex(GazeTrackerUdpRegex));
                    break;

                case PointsSources.TheEyeTribe:
                    var theEyeTribePointService = new TheEyeTribePointService();
                    errorNotifyingServices.Add(theEyeTribePointService);
                    pointSource = new PointServiceSource(
                        Settings.Default.PointTtl,
                        theEyeTribePointService);
                    break;

                case PointsSources.TobiiEyeX:
                case PointsSources.TobiiRex:
                case PointsSources.TobiiPcEyeGo:
                    var tobiiEyeXPointService = new TobiiEyeXPointService();
                    var tobiiEyeXCalibrationService = calibrationService as TobiiEyeXCalibrationService;
                    if (tobiiEyeXCalibrationService != null)
                    {
                        tobiiEyeXCalibrationService.EyeXHost = tobiiEyeXPointService.EyeXHost;
                    }
                    errorNotifyingServices.Add(tobiiEyeXPointService);
                    pointSource = new PointServiceSource(
                        Settings.Default.PointTtl,
                        tobiiEyeXPointService);
                    break;

                case PointsSources.MousePosition:
                    pointSource = new MousePositionSource(
                        Settings.Default.PointTtl);
                    break;

                default:
                    throw new ArgumentException("'PointsSource' settings is missing or not recognised! Please correct and restart OptiKey.");
            }

            //Instantiate key trigger source
            ITriggerSource keySelectionTriggerSource;
            switch (Settings.Default.KeySelectionTriggerSource)
            {
                case TriggerSources.Fixations:
                    keySelectionTriggerSource = new KeyFixationSource(
                       Settings.Default.KeySelectionTriggerFixationLockOnTime,
                       Settings.Default.KeySelectionTriggerFixationResumeRequiresLockOn,
                       Settings.Default.KeySelectionTriggerFixationDefaultCompleteTime,
                       Settings.Default.KeySelectionTriggerFixationCompleteTimesByIndividualKey
                        ? Settings.Default.KeySelectionTriggerFixationCompleteTimesByKeyValues
                        : null, 
                       Settings.Default.KeySelectionTriggerIncompleteFixationTtl,
                       pointSource.Sequence);
                    break;

                case TriggerSources.KeyboardKeyDownsUps:
                    keySelectionTriggerSource = new KeyboardKeyDownUpSource(
                        Settings.Default.KeySelectionTriggerKeyboardKeyDownUpKey,
                        pointSource.Sequence);
                    break;

                case TriggerSources.MouseButtonDownUps:
                    keySelectionTriggerSource = new MouseButtonDownUpSource(
                        Settings.Default.KeySelectionTriggerMouseDownUpButton,
                        pointSource.Sequence);
                    break;

                default:
                    throw new ArgumentException(
                        "'KeySelectionTriggerSource' setting is missing or not recognised! Please correct and restart OptiKey.");
            }

            //Instantiate point trigger source
            ITriggerSource pointSelectionTriggerSource;
            switch (Settings.Default.PointSelectionTriggerSource)
            {
                case TriggerSources.Fixations:
                    pointSelectionTriggerSource = new PointFixationSource(
                        Settings.Default.PointSelectionTriggerFixationLockOnTime,
                        Settings.Default.PointSelectionTriggerFixationCompleteTime,
                        Settings.Default.PointSelectionTriggerLockOnRadiusInPixels,
                        Settings.Default.PointSelectionTriggerFixationRadiusInPixels,
                        pointSource.Sequence);
                    break;

                case TriggerSources.KeyboardKeyDownsUps:
                    pointSelectionTriggerSource = new KeyboardKeyDownUpSource(
                        Settings.Default.PointSelectionTriggerKeyboardKeyDownUpKey,
                        pointSource.Sequence);
                    break;

                case TriggerSources.MouseButtonDownUps:
                    pointSelectionTriggerSource = new MouseButtonDownUpSource(
                        Settings.Default.PointSelectionTriggerMouseDownUpButton,
                        pointSource.Sequence);
                    break;

                default:
                    throw new ArgumentException(
                        "'PointSelectionTriggerSource' setting is missing or not recognised! "
                        + "Please correct and restart OptiKey.");
            }

            var inputService = new InputService(keyStateService, dictionaryService, audioService, capturingStateManager,
                pointSource, keySelectionTriggerSource, pointSelectionTriggerSource);
            inputService.RequestSuspend(); //Pause it initially
            return inputService;
        }
Exemplo n.º 20
0
 public async Task <ActionResult <Calibration> > GetCalibrationById(
     [FromServices] ICalibrationService calibrationService,
     [FromRoute] int calibrationId)
 {
     return(await calibrationService.FindCalibrationById(calibrationId));
 }