Exemplo n.º 1
0
        protected void AddDisabledPlugin(string folder)
        {
            NotLoadedPlugin plugin = new NotLoadedPlugin();
            plugin.FriendlyName = FileManager.RemovePath(folder);
            if(plugin.FriendlyName.EndsWith("/") || plugin.FriendlyName.EndsWith("\\"))
            {
                plugin.FriendlyName = plugin.FriendlyName.Substring(0, plugin.FriendlyName.Length - 1);
            }

            PluginContainer container = new PluginContainer(plugin);

            container.AssemblyLocation = folder + "/unknown.dll";

            mPluginContainers.Add(plugin, container);
            container.IsEnabled = false;

            // don't do any startup or anything
        }
Exemplo n.º 2
0
        private bool IsLoadedOnStartup(PluginContainer container)
        {
            #if GLUE


            var plugin = SelectedPlugin.Plugin;

            if (plugin is NotLoadedPlugin)
            {
                var loadedState = (plugin as NotLoadedPlugin).LoadedState;

                if(loadedState == LoadedState.NotLoaded)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                string pluginFolder = FileManager.GetDirectory(SelectedPlugin.AssemblyLocation);

                return GlueState.Self.CurrentPluginSettings.PluginsToIgnore.Contains(pluginFolder) == false;
            }
            #else
            return true;
            #endif
        }
Exemplo n.º 3
0
        protected void StartupPlugin(IPlugin plugin)
        {
            // See if the plugin already exists - it may implement multiple interfaces
            if (!mPluginContainers.ContainsKey(plugin))
            {
                PluginContainer pluginContainer = new PluginContainer(plugin);
                mPluginContainers.Add(plugin, pluginContainer);

                try
                {
                    plugin.StartUp();
                }
                catch (Exception e)
                {
                    pluginContainer.Fail(e, "Plugin failed in StartUp");
                }
            }
        }
Exemplo n.º 4
0
        private static string GetInfoForContainer(PluginContainer container)
        {
            if (container == null)
            {
                return null;
            }
            else if(container.Plugin is NotLoadedPlugin)
            {
                string text = "This plugin is not loaded.\n";

                var asNotLoadedPlugin = container.Plugin as NotLoadedPlugin;

                if(asNotLoadedPlugin.LoadedState == LoadedState.NotLoaded)
                {
                    text += "Plugin is disabled.";
                }
                else
                {
                    text += "Plugin will be loaded next time Glue is started.";
                }

                return text;
            }
            else
            {
                string text = "Version: " + container.Plugin.Version + "\n";

                string fileName = container.AssemblyLocation;
                if (System.IO.File.Exists(fileName))
                {
                    text += "Created: " + System.IO.File.GetCreationTime(fileName).ToShortDateString() + "\n";

                    text += "Location: " + fileName + "\n";
                }

                if (container != null && container.FailureException != null)
                {
                    text += container.FailureException.ToString();

                }
                return text;
            }
        }
Exemplo n.º 5
0
        private RssItem GetItemFor(AllFeed feed, PluginContainer SelectedPlugin)
        {
            string folder = 
                FileManager.RemovePath(
                 FileManager.GetDirectory(SelectedPlugin.AssemblyLocation));
            folder = folder.Replace("/", "");
            if (!folder.ToLowerInvariant().EndsWith("plugin"))
            {
                folder += "plugin";
            }
            folder = folder.ToLower();

            RssItem itemToReturn = null;
                
            string whatToLookFor = folder + ".plug";

            // We're going to narrow things down a bit here:
            whatToLookFor = ">" + whatToLookFor + @"</a>";
            
            foreach (var item in feed.Items)
            {
                var description = item.Description.ToLower();

                if (description.Contains(whatToLookFor))
                {
                    itemToReturn = item;
                    break;
                }
            }

            return itemToReturn;
        }
Exemplo n.º 6
0
 private static void PluginCommandWithThrow(Action action, PluginContainer container, string message)
 {
     if (HandleExceptions)
     {
         try
         {
             action();
         }
         catch (Exception e)
         {
             container.Fail(e, message);
             throw;
         }
     }
     else
     {
         action();
     }
 }
Exemplo n.º 7
0
        private static bool WasExceptionCausedByPlugin(Exception exception, PluginContainer plugin)
        {
            if(plugin.Plugin.GetType().Assembly.GetName().Name == exception.Source)
            {
                return true;
            }

            foreach (var name in plugin.Plugin.GetType().Assembly.GetReferencedAssemblies())
            {
                if (name.Name == exception.Source)
                {
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 8
0
        private static void PluginCommand(Action action, PluginContainer container, string message)
        {
            if (HandleExceptions)
            {
                if (mMenuStrip.IsDisposed)
                {
                    try
                    {
                        action();
                    }
                    catch (Exception e)
                    {
                        container.Fail(e, message);

                        ReceiveError(message + "\n" + e.ToString());


                    }
                }
                else
                {
                    if (mMenuStrip.IsDisposed == false)
                    {
                        // Do this on a UI thread
                        mMenuStrip.Invoke((MethodInvoker)delegate
                        {
                            try
                            {
                                action();
                            }
                            catch (Exception e)
                            {
                                container.Fail(e, message);

                                ReceiveError(message + "\n" + e.ToString());


                            }
                        });
                    }
                    else
                    {
                        try
                        {
                            action();
                        }
                        catch (Exception e)
                        {
                            container.Fail(e, message);

                            ReceiveError(message + "\n" + e.ToString());


                        }
                    }
                }
            }
            else
            {
                action();
            }
        }
Exemplo n.º 9
0
        private static void PluginCommandNotUiThread(Action action, PluginContainer container, string message)
        {
            if (HandleExceptions)
            {
                try
                {
                    action();
                }
                catch (Exception e)
                {
                    container.Fail(e, message);

                    ReceiveError(message + "\n" + e.ToString());
                }
            }
            else
            {
                action();
            }
        }
Exemplo n.º 10
0
        private bool IsRequiredByProject(PluginContainer selectedPlugin)
        {
            string nameToSearchFor = selectedPlugin.Name;

            return GlueState.Self.CurrentGlueProject.PluginData.RequiredPlugins.Contains(nameToSearchFor);
        }
Exemplo n.º 11
0
        private void RespondToRequiredByProject(PluginContainer pluginContainer, bool requiredByProject)
        {
            var name = pluginContainer.Name;

            var requiredPlugins = GlueState.Self.CurrentGlueProject.PluginData.RequiredPlugins;

            bool shouldSave = false;

            if(requiredByProject && requiredPlugins.Contains(name) == false)
            {
                requiredPlugins.Add(name);
                shouldSave = true;
            }
            else if(requiredByProject == false && requiredPlugins.Contains(name))
            {
                requiredPlugins.Remove(name);
                shouldSave = true;
            }

            if(shouldSave)
            {
                TaskManager.Self.AddAsyncTask(
                    ()=>GlueCommands.Self.GluxCommands.SaveGlux(),
                    "Saving project after changing plugin requirements");
            }
        }
Exemplo n.º 12
0
        private void RespondToLoadOnStartupChange(PluginContainer pluginContainer, bool shouldBeLoaded)
        {
            string pluginFolder = FileManager.GetDirectory(SelectedPlugin.AssemblyLocation);

#if GLUE
            var pluginSettings = GlueState.Self.CurrentPluginSettings;
            bool shouldSave = false;
            if (shouldBeLoaded && !IsLoadedOnStartup(pluginContainer))
            {
                pluginSettings.PluginsToIgnore.Remove(pluginFolder);

                if (pluginContainer.Plugin is NotLoadedPlugin)
                {
                    (pluginContainer.Plugin as NotLoadedPlugin).LoadedState = LoadedState.LoadedNextTime;
                }

                shouldSave = true;
            }
            else if (!shouldBeLoaded && IsLoadedOnStartup(pluginContainer))
            {
                pluginSettings.PluginsToIgnore.Add(pluginFolder);

                if (pluginContainer.Plugin is NotLoadedPlugin)
                {
                    (pluginContainer.Plugin as NotLoadedPlugin).LoadedState = LoadedState.NotLoaded;
                }

                shouldSave = true;
            }
            if (shouldSave)
            {
                GlueState.Self.CurrentPluginSettings.Save(FileManager.GetDirectory(ProjectManager.GlueProjectFileName));
            }
#endif
        }