Пример #1
0
        /// <summary>
        /// Adds a plugin to the plugin collection
        /// </summary>
        private static void AddPlugin(String fileName)
        {
            Assembly pluginAssembly = Assembly.LoadFrom(fileName);

            try
            {
                foreach (Type pluginType in pluginAssembly.GetTypes())
                {
                    if (pluginType.IsPublic && !pluginType.IsAbstract)
                    {
                        Type typeInterface = pluginType.GetInterface("PluginCore.IPlugin", true);
                        if (typeInterface != null)
                        {
                            AvailablePlugin newPlugin = new AvailablePlugin(fileName);
                            newPlugin.Instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                            if (!Globals.Settings.DisabledPlugins.Contains(newPlugin.Instance.Guid))
                            {
                                newPlugin.Instance.Initialize();
                                newPlugin.IsActive = true;
                            }
                            if (!AvailablePlugins.Contains(newPlugin))
                            {
                                AvailablePlugins.Add(newPlugin);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorManager.ShowError("Unable to load plugin:\n" + fileName, ex);
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a plugin to the plugin collection
        /// </summary>
        private static void AddPlugin(String fileName)
        {
            Assembly pluginAssembly = Assembly.LoadFrom(fileName);

            try
            {
                foreach (Type pluginType in pluginAssembly.GetTypes())
                {
                    if (pluginType.IsPublic && !pluginType.IsAbstract)
                    {
                        Type typeInterface = pluginType.GetInterface("PluginCore.IPlugin", true);
                        if (typeInterface != null)
                        {
                            AvailablePlugin newPlugin = new AvailablePlugin(fileName);
                            newPlugin.Instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                            if (newPlugin.Instance.Api != REQUIRED_API_LEVEL)
                            {
                                // Invalid plugin, ignore...
                                throw new Exception("Required API level does not match.");
                            }
                            if (!Globals.Settings.DisabledPlugins.Contains(newPlugin.Instance.Guid))
                            {
                                newPlugin.Instance.Initialize();
                                newPlugin.IsActive = true;
                            }
                            if (!AvailablePlugins.Contains(newPlugin))
                            {
                                AvailablePlugins.Add(newPlugin);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                String message = TextHelper.GetString("Info.UnableToLoadPlugin");
                ErrorManager.ShowWarning(message + " \n" + fileName, ex);
            }
        }
Пример #3
0
 /// <summary>
 /// Adds a plugin to the plugin collection
 /// </summary>
 private static void AddPlugin(String fileName)
 {
     Assembly pluginAssembly = Assembly.LoadFrom(fileName);
     try
     {
         foreach (Type pluginType in pluginAssembly.GetTypes())
         {
             if (pluginType.IsPublic && !pluginType.IsAbstract)
             {
                 Type typeInterface = pluginType.GetInterface("PluginCore.IPlugin", true);
                 if (typeInterface != null)
                 {
                     AvailablePlugin newPlugin = new AvailablePlugin(fileName);
                     newPlugin.Instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                     if (newPlugin.Instance.Api != REQUIRED_API_LEVEL)
                     {
                         // Invalid plugin, ignore...
                         throw new Exception("Required API level does not match.");
                     }
                     if (!Globals.Settings.DisabledPlugins.Contains(newPlugin.Instance.Guid))
                     {
                         newPlugin.Instance.Initialize();
                         newPlugin.IsActive = true;
                     }
                     if (!AvailablePlugins.Contains(newPlugin))
                     {
                         AvailablePlugins.Add(newPlugin);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         String message = TextHelper.GetString("Info.UnableToLoadPlugin");
         ErrorManager.ShowWarning(message + " \n" + fileName, ex);
     }
 }