예제 #1
0
        public static void ClosePluginInstance(ProfilePluginConfiguration config,
                                               IJinxBotPlugin pluginInstance)
        {
            lock (m_lock)
            {
                SavePluginInstanceConfig(config, pluginInstance);

                IMultiClientPlugin mcp = pluginInstance as IMultiClientPlugin;
                if (mcp != null)
                {
                    int count = m_instanceCounter[mcp];
                    if (count == 1)
                    {
                        // this is the last instance, so shut it down completely
                        m_instanceCounter.Remove(mcp);
                        mcp.DestroyPluginWindows(MainWindow);
                        string name = m_instancesToNames[mcp];
                        m_instancesToNames.Remove(mcp);
                        m_activeMultiClientPlugins.Remove(name);
                    }
                    else
                    {
                        m_instanceCounter[mcp] = count - 1;
                    }
                }
            }
        }
예제 #2
0
        public void Close()
        {
            m_client.Close();

            m_cmdTranslator.Dispose();
            m_cmdTranslator = null;

            foreach (ProfilePluginConfiguration config in m_activePlugins.Keys)
            {
                IJinxBotPlugin     plugin = m_activePlugins[config];
                IMultiClientPlugin mcp    = plugin as IMultiClientPlugin;
                if (mcp != null)
                {
                    mcp.RemoveClient(this);
                }

                ISingleClientPlugin scp = plugin as ISingleClientPlugin;
                if (scp != null)
                {
                    scp.UnregisterEvents(this);
                    scp.DestroyPluginWindows(this.ProfileDocument);
                }

                PluginFactory.ClosePluginInstance(config, plugin);

                JinxBotConfiguration.Instance.Save();
            }
        }
예제 #3
0
        public static IJinxBotPlugin CreatePlugin(ProfilePluginConfiguration pluginConfiguration)
        {
            lock (m_lock)
            {
                if (!m_loadedAssemblies.ContainsKey(pluginConfiguration.Assembly))
                {
                    if (!LoadAssembly(pluginConfiguration))
                    {
                        return(null);
                    }
                }

                if (!m_pluginTypes.ContainsKey(pluginConfiguration.Type))
                {
                    if (!LoadType(pluginConfiguration))
                    {
                        return(null);
                    }
                }

                PluginInfo     info   = m_pluginTypes[pluginConfiguration.Type];
                IJinxBotPlugin plugin = null;
                if (info.SupportsMultiClient && !string.IsNullOrEmpty(pluginConfiguration.MultiClientName))
                {
                    if (m_activeMultiClientPlugins.ContainsKey(pluginConfiguration.MultiClientName))
                    {
                        plugin = m_activeMultiClientPlugins[pluginConfiguration.MultiClientName];
                        IMultiClientPlugin mcp = plugin as IMultiClientPlugin;
                        m_instanceCounter[mcp] = m_instanceCounter[mcp] + 1;
                    }
                    else
                    {
                        plugin = Instantiate(info, pluginConfiguration);
                        IMultiClientPlugin mcp = plugin as IMultiClientPlugin;
                        if (mcp == null)
                        {
                            throw new InvalidCastException("Plugin \"" + pluginConfiguration.Name + "\" is configured as a multi-client plugin but does not support that interface.");
                        }
                        mcp.CreatePluginWindows(MainWindow);
                        m_activeMultiClientPlugins.Add(pluginConfiguration.MultiClientName, mcp);
                        m_instancesToNames.Add(mcp, pluginConfiguration.MultiClientName);
                        m_instanceCounter.Add(mcp, 1);
                    }
                }
                else
                {
                    plugin = Instantiate(info, pluginConfiguration);
                }

                return(plugin);
            }
        }
예제 #4
0
        private bool ProcessPlugin(bool hasSetCommandQueue, ProfilePluginConfiguration pluginConfig)
        {
            IJinxBotPlugin plugin = PluginFactory.CreatePlugin(pluginConfig);

            m_activePlugins.Add(pluginConfig, plugin);

            // test if the plugin is a command queue
            ICommandQueue commandQueuePlugin = plugin as ICommandQueue;

            if (!hasSetCommandQueue && commandQueuePlugin != null)
            {
                m_client.CommandQueue = commandQueuePlugin;
                hasSetCommandQueue    = true;
            }

            // test if the plugin is a database plugin
            IJinxBotDatabase databasePlugin = plugin as IJinxBotDatabase;

            if (databasePlugin != null)
            {
                m_database = databasePlugin;
            }

            // test if the plugin is a command handler
            ICommandHandler handler = plugin as ICommandHandler;

            if (handler != null)
            {
                m_commandHandlers.Add(handler);
            }

            // test if the plugin is multi-client
            IMultiClientPlugin mcp = plugin as IMultiClientPlugin;

            if (mcp != null)
            {
                mcp.AddClient(this);
            }
            else
            {
                ISingleClientPlugin scp = plugin as ISingleClientPlugin;
                if (scp != null)
                {
                    scp.CreatePluginWindows(this.ProfileDocument);
                    scp.RegisterEvents(this);
                }
            }

            return(hasSetCommandQueue);
        }
예제 #5
0
        private static IJinxBotPlugin Instantiate(PluginInfo info, ProfilePluginConfiguration config)
        {
            IJinxBotPlugin plugin = Activator.CreateInstance(info.Type) as IJinxBotPlugin;

            if (plugin == null)
            {
                throw new InvalidCastException("Could not cast \"" + info.Type.FullName + "\" to \"IJinxBotPlugin\".");
            }

            Dictionary <string, string> settings = config.Settings.ToDictionary(s => s.Name, s => s.Value);

            plugin.Startup(settings);

            return(plugin);
        }
예제 #6
0
        public static void ClosePluginInstance(ProfilePluginConfiguration config, 
            IJinxBotPlugin pluginInstance)
        {
            lock (m_lock)
            {
                SavePluginInstanceConfig(config, pluginInstance);

                IMultiClientPlugin mcp = pluginInstance as IMultiClientPlugin;
                if (mcp != null)
                {
                    int count = m_instanceCounter[mcp];
                    if (count == 1)
                    {
                        // this is the last instance, so shut it down completely
                        m_instanceCounter.Remove(mcp);
                        mcp.DestroyPluginWindows(MainWindow);
                        string name = m_instancesToNames[mcp];
                        m_instancesToNames.Remove(mcp);
                        m_activeMultiClientPlugins.Remove(name);
                    }
                    else
                    {
                        m_instanceCounter[mcp] = count - 1;
                    }
                }
            }
        }
예제 #7
0
 private static void SavePluginInstanceConfig(ProfilePluginConfiguration config, IJinxBotPlugin pluginInstance)
 {
     Dictionary<string, string> settings = config.Settings.ToDictionary(s => s.Name, s => s.Value);
     pluginInstance.Shutdown(settings);
     List<ProfilePluginSettingConfiguration> settingsToSave = new List<ProfilePluginSettingConfiguration>();
     foreach (string key in settings.Keys)
     {
         settingsToSave.Add(new ProfilePluginSettingConfiguration { Name = key, Value = settings[key] });
     }
     config.Settings = settingsToSave.ToArray();
 }
예제 #8
0
        private static void SavePluginInstanceConfig(ProfilePluginConfiguration config, IJinxBotPlugin pluginInstance)
        {
            Dictionary <string, string> settings = config.Settings.ToDictionary(s => s.Name, s => s.Value);

            pluginInstance.Shutdown(settings);
            List <ProfilePluginSettingConfiguration> settingsToSave = new List <ProfilePluginSettingConfiguration>();

            foreach (string key in settings.Keys)
            {
                settingsToSave.Add(new ProfilePluginSettingConfiguration {
                    Name = key, Value = settings[key]
                });
            }
            config.Settings = settingsToSave.ToArray();
        }