Exemple #1
0
        public void Restart(Plugin plugin)
        {
            PluginDomain domain = GetDomain(plugin);

            if (domain != null)
            {
                domain.Stop(false);
                domain.Initialize();
                if (domain.Plugin.State == PluginState.Failed)
                {
                    return;
                }
                domain.Start();
            }
            else
            {
                Bridge.Logger.Fatal("No domain found for plugin {ID}!", plugin.Meta.Id);
            }
        }
Exemple #2
0
        public void Reload()
        {
            if (_isLoaded)
            {
                Unload();
                Context = new PluginLoadContext();
            }

            _isLoaded = true;
            bool reloadAfter = false;
            List <PluginDomain> domainCache = new List <PluginDomain>();

            foreach (string pluginPath in Directory.GetFiles(Bridge.PluginsPath))
            {
                if (!Path.GetExtension(pluginPath).ToLower().Contains("dll"))
                {
                    continue;
                }
                PluginDomain domain = new PluginDomain(this, pluginPath);
                domain.Initialize();
                if (domain.Plugin.State == PluginState.Failed)
                {
                    continue;
                }
                if (domain.UpdatingData != null)
                {
                    if (!Bridge.Config.KeepPluginsUpdated)
                    {
                        Bridge.Logger.Warn("There is an update available for {PLUGIN} ({OLD} -> {NEW})!",
                                           domain.Plugin.Display, domain.Plugin.Meta.Version, domain.UpdatingData.Version);
                    }
                    else
                    {
                        Bridge.Logger.Warn("There is an update available for {PLUGIN} ({OLD} -> {NEW})! Starting updater...",
                                           domain.Plugin.Display, domain.Plugin.Meta.Version, domain.UpdatingData.Version);
                        AutoUpdater updater = new AutoUpdater(domain);
                        updater.Start();
                        reloadAfter = true;
                    }
                }

                if (domain.PackageProvider != null)
                {
                    domain.Plugin.Logger.Info("Found a package provider! Exporting package...");
                    domain.PackageProvider.Export(Path.Combine(Bridge.PackagePath, domain.PackageProvider.Name));
                    AddPackage(domain.PackageProvider.Name);
                    domain.Plugin.Logger.Info("Package {NAME} successfully provided!", domain.PackageProvider.Name);
                }

                domainCache.Add(domain);
            }

            if (reloadAfter)
            {
                Reload();
                return;
            }

            File.WriteAllText(Path.Combine(Bridge.ServerPath, "server_config.json"),
                              Bridge.ServerConfig.ToString(Formatting.Indented));

            PrioritizedList list = new PrioritizedList(domainCache);

            foreach (PluginDomain handle in domainCache)
            {
                if (handle.Plugin.Meta.Dependencies.Length > 0)
                {
                    foreach (string parent in handle.Plugin.Meta.Dependencies)
                    {
                        list.Increment(handle, list.GetRise(parent));
                    }
                }
            }

            domainCache = list.Convert();
            Domains     = new List <PluginDomain>();
            foreach (PluginDomain domain in domainCache)
            {
                if (domain.Plugin.Meta.Id == "_global" || domain.Plugin.Meta.Name == "_global")
                {
                    Bridge.Logger.Fatal(
                        "Could not load plugin {ID} on path \"{PATH}\" because either the id or the name has is a blacklisted word!",
                        domain.Plugin.Meta.Id, domain.Path);
                    return;
                }

                Plugin otherPlugin = GetPlugin(domain.Plugin.Meta.Id);
                if (otherPlugin != null)
                {
                    Bridge.Logger.Warn(
                        "Could not loading plugin {ID} on path \"{PATH}\" because the id is already occupied by the plugin {ID2} on the path {PATH2}!",
                        domain.Plugin.Meta.Id, domain.Path, otherPlugin.Meta.Id, otherPlugin.FilePath);
                    continue;
                }

                Domains.Add(domain);
                domain.Start();
            }
        }