Beispiel #1
0
 internal PluginSettings(PluginInfo pluginInfo, IPluginRepository pluginRepository)
 {
     PluginInfo        = pluginInfo;
     _pluginRepository = pluginRepository;
     _settingEntities  = new Dictionary <string, object>();
 }
Beispiel #2
0
 public ArtemisPluginException(PluginInfo pluginInfo)
 {
     PluginInfo = pluginInfo;
 }
 public PluginEventArgs(PluginInfo pluginInfo)
 {
     PluginInfo = pluginInfo;
 }
Beispiel #4
0
 public ArtemisPluginException(PluginInfo pluginInfo, string message, Exception inner) : base(message, inner)
 {
     PluginInfo = pluginInfo;
 }
Beispiel #5
0
        internal void SetEnabled(bool enable, bool isAutoEnable = false)
        {
            if (enable && !Enabled)
            {
                try
                {
                    if (isAutoEnable && PluginInfo.GetLockFileCreated())
                    {
                        // Don't wrap existing lock exceptions, simply rethrow them
                        if (PluginInfo.LoadException is ArtemisPluginLockException)
                        {
                            throw PluginInfo.LoadException;
                        }

                        throw new ArtemisPluginLockException(PluginInfo.LoadException);
                    }

                    Enabled            = true;
                    PluginInfo.Enabled = true;
                    PluginInfo.CreateLockFile();

                    // Allow up to 15 seconds for plugins to activate.
                    // This means plugins that need more time should do their long running tasks in a background thread, which is intentional
                    // Little meh: Running this from a different thread could cause deadlocks
                    Task enableTask = Task.Run(InternalEnablePlugin);
                    if (!enableTask.Wait(TimeSpan.FromSeconds(15)))
                    {
                        throw new ArtemisPluginException(PluginInfo, "Plugin load timeout");
                    }

                    PluginInfo.LoadException = null;
                    OnPluginEnabled();
                }
                // If enable failed, put it back in a disabled state
                catch (Exception e)
                {
                    Enabled                  = false;
                    PluginInfo.Enabled       = false;
                    PluginInfo.LoadException = e;
                    throw;
                }
                finally
                {
                    if (!(PluginInfo.LoadException is ArtemisPluginLockException))
                    {
                        PluginInfo.DeleteLockFile();
                    }
                }
            }
            else if (!enable && Enabled)
            {
                Enabled            = false;
                PluginInfo.Enabled = false;

                // Even if disable failed, still leave it in a disabled state to avoid more issues
                InternalDisablePlugin();
                OnPluginDisabled();
            }
            // A failed load is still enabled in plugin info (to avoid disabling it permanently after a fail)
            // update even that when manually disabling
            else if (!enable && !Enabled)
            {
                PluginInfo.Enabled = false;
            }
        }