Пример #1
0
        private void LoadPlugin(string Name)
        {
            SC.Interfaces.IScServerPluginBase plugin = null;
            try
            {
                plugin = SC.PluginLoader.PluginLoader.Instance.LoadServerPlugin(Name);
            }
            catch (NotSupportedException e)
            {
                throw new SC.Interfaces.SCException(e);
            }
            catch (Exception e)
            {
                throw new SC.Interfaces.SCException("An unexpected error occurred during construction of plugin with name " + Name, e);
            }

            if (plugin == null)
            {
                Logger.Error("Plugin " + Name + " does not exist.");
                throw new ArgumentException("Unknown plugin");
            }

            try
            {
                plugin.AssertLicense();
            }
            catch (SC.Interfaces.LicenseException e)
            {
                Logger.Error("Plugin is not licensed.", e);
                throw;
            }

            try
            {
                plugin.SetProvider(new PluginProvider(GetName() + "." + Name));
                plugin.AttachServer(this);
                SC.Messaging.Invokeable i = plugin as SC.Messaging.Invokeable;
                if (i != null)
                {
                    this.Register(i);
                }
                plugins.Add(Name, plugin);
            }
            catch (Exception e1)
            {
                Logger.Error("An exception occurred during creation of plugin " + Name + ". Will try to destruct plugin.", e1);
                try
                {
                    plugin.Destroy();
                    plugin.DetachServer();
                }
                catch (Exception e2)
                {
                    Logger.Error("A second exception occurred during destruction of plugin " + Name, e2);
                }
                throw new SC.Interfaces.SCException("An exception occurred during creation of plugin.", e1);;
            }
        }
Пример #2
0
        private void UnloadPlugin(string Name, bool destroy)
        {
            Logger.Info("Unloading plugin " + Name + "...");
            SC.Interfaces.IScServerPluginBase plugin = plugins[Name];

            SC.Messaging.Invokeable i = plugin as SC.Messaging.Invokeable;
            if (i != null)
            {
                this.Unregister(i);
            }
            if (destroy)
            {
                plugin.Destroy();
            }
            plugin.DetachServer();
        }