Exemplo n.º 1
0
        public void DisablePluginFeature(PluginFeature pluginFeature, bool saveState)
        {
            try
            {
                _logger.Verbose("Disabling plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
                pluginFeature.SetEnabled(false);
            }
            finally
            {
                if (saveState)
                {
                    pluginFeature.Entity.IsEnabled = false;
                    SavePlugin(pluginFeature.Plugin);
                }

                if (!pluginFeature.IsEnabled)
                {
                    _logger.Verbose("Successfully disabled plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
                    OnPluginFeatureDisabled(new PluginFeatureEventArgs(pluginFeature));
                }
            }
        }
Exemplo n.º 2
0
        public void EnablePluginFeature(PluginFeature pluginFeature, bool saveState, bool isAutoEnable)
        {
            _logger.Verbose("Enabling plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);

            OnPluginFeatureEnabling(new PluginFeatureEventArgs(pluginFeature));

            if (pluginFeature.Plugin.Info.RequiresAdmin && !_isElevated)
            {
                if (!saveState)
                {
                    throw new ArtemisCoreException("Cannot enable a feature that requires elevation without saving it's state.");
                }

                pluginFeature.Entity.IsEnabled        = true;
                pluginFeature.Plugin.Entity.IsEnabled = true;
                SavePlugin(pluginFeature.Plugin);

                _logger.Information("Restarting because a newly enabled feature requires elevation");
                Utilities.Restart(true, TimeSpan.FromMilliseconds(500));
                return;
            }

            try
            {
                pluginFeature.SetEnabled(true, isAutoEnable);
                if (saveState)
                {
                    pluginFeature.Entity.IsEnabled = true;
                }
            }
            catch (Exception e)
            {
                _logger.Warning(
                    new ArtemisPluginException(pluginFeature.Plugin, $"Exception during SetEnabled(true) on {pluginFeature}", e),
                    "Failed to enable plugin"
                    );
                throw;
            }
            finally
            {
                // On an auto-enable, ensure PluginInfo.Enabled is true even if enable failed, that way a failure on auto-enable does
                // not affect the user's settings
                if (saveState)
                {
                    if (isAutoEnable)
                    {
                        pluginFeature.Entity.IsEnabled = true;
                    }

                    SavePlugin(pluginFeature.Plugin);
                }

                if (pluginFeature.IsEnabled)
                {
                    _logger.Verbose("Successfully enabled plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
                    OnPluginFeatureEnabled(new PluginFeatureEventArgs(pluginFeature));
                }
                else
                {
                    OnPluginFeatureEnableFailed(new PluginFeatureEventArgs(pluginFeature));
                }
            }
        }