StartAsync() public method

public StartAsync ( ) : Task
return Task
Esempio n. 1
0
 /// <summary>
 ///     Loads the last active effect and starts the program
 /// </summary>
 public void EnableProgram()
 {
     Logger.Debug("Enabling program");
     ProgramEnabled = true;
     LoopManager.StartAsync();
     RaiseEnabledChangedEvent(new EnabledChangedEventArgs(ProgramEnabled));
 }
Esempio n. 2
0
 /// <summary>
 ///     Loads the last active effect and starts the program
 /// </summary>
 public void EnableProgram()
 {
     Logger.Debug("Enabling program");
     ProgramEnabled = true;
     LoopManager.StartAsync();
     _events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled));
 }
Esempio n. 3
0
        /// <summary>
        ///     Loads the last active effect and starts the program
        /// </summary>
        public async void EnableProgram()
        {
            Logger.Debug("Enabling program");
            ProgramEnabled = true;
            await LoopManager.StartAsync();

            _migrationManager.MigrateProfiles();
            RaiseEnabledChangedEvent(new EnabledChangedEventArgs(ProgramEnabled));
        }
Esempio n. 4
0
        private void EnsurePreviewActive(ModuleViewModel toBeActive)
        {
            // If the current module is the same as what should be active, don't do anything
            if (_moduleManager.ActiveModule != null && _moduleManager.ActiveModule == toBeActive.ModuleModel)
            {
                return;
            }

            _logger.Debug("Activate profile preview");
            _moduleManager.ChangeActiveModule(toBeActive.ModuleModel, null, false);

            // LoopManager might be running, this method won't do any harm in that case.
            _loopManager.StartAsync();
        }
Esempio n. 5
0
        /// <summary>
        ///     Keeps track of profiles being previewed and sets up the active efffect accordingly
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SetupProfilePreview(object sender, ElapsedEventArgs e)
        {
            if (string.IsNullOrEmpty(_generalSettings.LastKeyboard) || _deviceManager.ChangingKeyboard ||
                ProfilePreviewModel == null)
            {
                return;
            }

            var activePreview = GameViewModels.FirstOrDefault(vm => vm.IsActive);

            if (activePreview == null)
            {
                // Should not be active if no selected profile is set
                if (_effectManager.ActiveEffect != ProfilePreviewModel)
                {
                    return;
                }

                _logger.Debug("Loading last effect after profile preview");
                var lastEffect = _effectManager.GetLastEffect();
                if (lastEffect != null)
                {
                    _effectManager.ChangeEffect(lastEffect);
                }
                else
                {
                    _effectManager.ClearEffect();
                }
            }
            else
            {
                if (_effectManager.ActiveEffect != ProfilePreviewModel && !(_effectManager.ActiveEffect is GameModel))
                {
                    _logger.Debug("Activate profile preview");
                    _effectManager.ChangeEffect(ProfilePreviewModel);
                }

                // LoopManager might be running, this method won't do any harm in that case.
                _loopManager.StartAsync();

                ProfilePreviewModel.ProfileViewModel = activePreview.ProfileEditor.ProfileViewModel;
                if (!ReferenceEquals(ProfilePreviewModel.Profile, activePreview.ProfileEditor.SelectedProfile))
                {
                    ProfilePreviewModel.Profile = activePreview.ProfileEditor.SelectedProfile;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Disables the current module and changes it to the provided module.
        /// </summary>
        /// <param name="moduleModel">The module to activate</param>
        /// <param name="loopManager">Optionally pass the LoopManager to automatically start it, if it's not running.</param>
        /// <param name="storeAsLast">Whether or not to store this effect as the last effect</param>
        public void ChangeActiveModule(ModuleModel moduleModel, LoopManager loopManager = null, bool storeAsLast = true)
        {
            if (_waitEffect != null)
            {
                _logger.Debug("Stopping module change because a change is already queued");
                return;
            }

            if (moduleModel == null)
            {
                throw new ArgumentNullException(nameof(moduleModel));
            }

            if (_deviceManager.ActiveKeyboard == null)
            {
                _logger.Debug("Stopping module change until keyboard is enabled");
                _waitEffect      = moduleModel;
                _waitLoopManager = loopManager;
                _deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
                _deviceManager.EnableLastKeyboard();
                return;
            }

            // Process bound modules are only used if they are enabled
            if (moduleModel.Settings != null && !moduleModel.Settings.IsEnabled && moduleModel.IsBoundToProcess)
            {
                _logger.Debug("Cancelling module change, provided module is process bound and not enabled");
                return;
            }

            var wasNull = false;

            if (ActiveModule == null)
            {
                wasNull      = true;
                ActiveModule = moduleModel;
            }

            lock (ActiveModule)
            {
                if (!wasNull)
                {
                    ActiveModule.Dispose();
                }
                lock (moduleModel)
                {
                    ActiveModule = moduleModel;
                    ActiveModule.Enable();
                    if (!ActiveModule.IsInitialized)
                    {
                        _logger.Debug("Cancelling module change, couldn't initialize the module ({0})", moduleModel.Name);
                        ActiveModule = null;
                        return;
                    }
                }
            }

            if (loopManager != null && !loopManager.Running)
            {
                _logger.Debug("Starting LoopManager for module change");
                loopManager.StartAsync();
            }

            if (!ActiveModule.IsBoundToProcess && !ActiveModule.IsOverlay && storeAsLast)
            {
                _generalSettings.LastModule = ActiveModule?.Name;
                _generalSettings.Save();
            }

            _logger.Debug("Changed active module to: {0}", moduleModel.Name);
            RaiseEffectChangedEvent(new ModuleChangedEventArgs(moduleModel));
        }
Esempio n. 7
0
        /// <summary>
        ///     Disables the current effect and changes it to the provided effect.
        /// </summary>
        /// <param name="effectModel">The effect to activate</param>
        /// <param name="loopManager">Optionally pass the LoopManager to automatically start it, if it's not running.</param>
        public void ChangeEffect(EffectModel effectModel, LoopManager loopManager = null)
        {
            if (_waitEffect != null)
            {
                _logger.Debug("Stopping effect because a change is already queued");
                return;
            }

            if (effectModel == null)
                throw new ArgumentNullException(nameof(effectModel));
            if (effectModel is OverlayModel)
                throw new ArgumentException("Can't set an Overlay effect as the active effect");

            if (_deviceManager.ActiveKeyboard == null)
            {
                _logger.Debug("Stopping effect change until keyboard is enabled");
                _waitEffect = effectModel;
                _waitLoopManager = loopManager;
                _deviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent;
                _deviceManager.EnableLastKeyboard();
                return;
            }

            // Game models are only used if they are enabled
            var gameModel = effectModel as GameModel;
            if (gameModel != null)
                if (!gameModel.Enabled)
                {
                    _logger.Debug("Cancelling effect change, provided game not enabled");
                    return;
                }


            var wasNull = false;
            if (ActiveEffect == null)
            {
                wasNull = true;
                ActiveEffect = effectModel;
            }

            lock (ActiveEffect)
            {
                if (!wasNull)
                    ActiveEffect.Dispose();

                ActiveEffect = effectModel;
                ActiveEffect.Enable();
                if (!ActiveEffect.Initialized)
                {
                    _logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name);
                    ActiveEffect = null;
                    return;
                }
            }

            if (loopManager != null && !loopManager.Running)
            {
                _logger.Debug("Starting LoopManager for effect change");
                loopManager.StartAsync();
            }

            _logger.Debug("Changed active effect to: {0}", effectModel.Name);

            if (ActiveEffect is GameModel || ActiveEffect is ProfilePreviewModel)
                return;

            // Non-game effects are stored as the new LastEffect.
            _generalSettings.LastEffect = ActiveEffect?.Name;
            _generalSettings.Save();
        }
Esempio n. 8
0
        /// <summary>
        ///     Disables the current effect and changes it to the provided effect.
        /// </summary>
        /// <param name="effectModel">The effect to activate</param>
        /// <param name="loopManager">Optionally pass the LoopManager to automatically start it, if it's not running.</param>
        public void ChangeEffect(EffectModel effectModel, LoopManager loopManager = null)
        {
            if (effectModel == null)
            {
                throw new ArgumentNullException(nameof(effectModel));
            }
            if (effectModel is OverlayModel)
            {
                throw new ArgumentException("Can't set an Overlay effect as the active effect");
            }

            if (_deviceManager.ActiveKeyboard == null)
            {
                _deviceManager.EnableLastKeyboard();
            }
            // If still null, no last keyboard, so stop.
            if (_deviceManager.ActiveKeyboard == null)
            {
                _logger.Debug("Cancelling effect change, no LastKeyboard");
                return;
            }

            // Game models are only used if they are enabled
            var gameModel = effectModel as GameModel;

            if (gameModel != null)
            {
                if (!gameModel.Enabled)
                {
                    _logger.Debug("Cancelling effect change, provided game not enabled");
                    return;
                }
            }


            var wasNull = false;

            if (ActiveEffect == null)
            {
                wasNull      = true;
                ActiveEffect = effectModel;
            }

            lock (ActiveEffect)
            {
                if (!wasNull)
                {
                    ActiveEffect.Dispose();
                }

                ActiveEffect = effectModel;
                ActiveEffect.Enable();
                if (!ActiveEffect.Initialized)
                {
                    _logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name);
                    ActiveEffect = null;
                    return;
                }
            }

            if (loopManager != null && !loopManager.Running)
            {
                _logger.Debug("Starting LoopManager for effect change");
                loopManager.StartAsync();
            }

            _logger.Debug("Changed active effect to: {0}", effectModel.Name);

            if (ActiveEffect is GameModel || ActiveEffect is ProfilePreviewModel)
            {
                return;
            }

            // Non-game effects are stored as the new LastEffect.
            General.Default.LastEffect = ActiveEffect?.Name;
            General.Default.Save();
        }
Esempio n. 9
0
        /// <summary>
        ///     Disables the current effect and changes it to the provided effect.
        /// </summary>
        /// <param name="effectModel">The effect to activate</param>
        /// <param name="loopManager">Optionally pass the LoopManager to automatically start it, if it's not running.</param>
        public void ChangeEffect(EffectModel effectModel, LoopManager loopManager = null)
        {
            if (_waitEffect != null)
            {
                _logger.Debug("Stopping effect because a change is already queued");
                return;
            }

            if (effectModel == null)
            {
                throw new ArgumentNullException(nameof(effectModel));
            }
            if (effectModel is OverlayModel)
            {
                throw new ArgumentException("Can't set an Overlay effect as the active effect");
            }

            if (_deviceManager.ActiveKeyboard == null)
            {
                _logger.Debug("Stopping effect change until keyboard is enabled");
                _waitEffect      = effectModel;
                _waitLoopManager = loopManager;
                _deviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent;
                _deviceManager.EnableLastKeyboard();
                return;
            }

            // Game models are only used if they are enabled
            var gameModel = effectModel as GameModel;

            if (gameModel != null)
            {
                if (!gameModel.Enabled)
                {
                    _logger.Debug("Cancelling effect change, provided game not enabled");
                    return;
                }
            }


            var wasNull = false;

            if (ActiveEffect == null)
            {
                wasNull      = true;
                ActiveEffect = effectModel;
            }

            lock (ActiveEffect)
            {
                if (!wasNull)
                {
                    ActiveEffect.Dispose();
                }

                ActiveEffect = effectModel;
                ActiveEffect.Enable();
                if (!ActiveEffect.Initialized)
                {
                    _logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name);
                    ActiveEffect = null;
                    return;
                }
            }

            if (loopManager != null && !loopManager.Running)
            {
                _logger.Debug("Starting LoopManager for effect change");
                loopManager.StartAsync();
            }

            _logger.Debug("Changed active effect to: {0}", effectModel.Name);

            if (ActiveEffect is GameModel || ActiveEffect is ProfilePreviewModel)
            {
                return;
            }

            // Non-game effects are stored as the new LastEffect.
            _generalSettings.LastEffect = ActiveEffect?.Name;
            _generalSettings.Save();
        }