Beispiel #1
0
 public void Reload(IBot bot)
 {
     // Remove schedules from bot
     if (this.schedules.Length > 0)
     {
         bot.RemoveSchedules(this.schedules);
     }
     // Reset JSWrapper
     ResetJSWrapper();
     // Load JSON configs and create schedules
     DoReload();
     // Add schedules to bot
     if (this.schedules.Length > 0)
     {
         bot.AddSchedules(this.schedules);
     }
 }
Beispiel #2
0
        public void Load(IBot bot)
        {
            if (Loaded)
            {
                return;
            }
            var pNames       = Config.Instance.PluginConfig.PluginNames;
            var foundPlugins = new IPlugin[pNames.Length];
            var dllFiles     = GetDllPaths(Config.Instance.MainConfig.PluginDir);
            // load asm and check IPlugin classes
            IPlugin dummy = null;

            foreach (var f in dllFiles)
            {
                Assembly asm;
                var      file_ver = "UNKNOWN";
                var      prod_ver = "UNKNOWN";
                var      asm_ver  = "UNKNOWN";
                try {
                    var fv = FileVersionInfo.GetVersionInfo(f);
                    file_ver = fv.FileVersion;
                    prod_ver = fv.ProductVersion;
                    asm      = Assembly.LoadFrom(f);
                    asm_ver  = asm.GetName().Version.ToString();
                } catch (Exception) {
                    // TRANSLATORS: Log message. In PluginManager. {0} is dll file which could not load.
                    Logger.Log(T._("* Could not load [{0}].", f));
                    continue;
                }
                // TRANSLATORS: Log message. In PluginManager. {0} is dll file path.
                Logger.Log(T._("  - Load [{0}] ...", f));
                // Log versions
                Logger.DebugLog("    ProductVersion [" + prod_ver + "] FileVersion [" + file_ver + "] AssemblyVersion [" + asm_ver + "]");
                foreach (var t in asm.GetTypes())
                {
                    if (t.IsInterface)
                    {
                        continue;
                    }
                    dummy = null;
                    try {
                        dummy = Activator.CreateInstance(t) as IPlugin;
                    } catch (Exception) {}
                    if (dummy != null)
                    {
                        var idx = Array.IndexOf(pNames, dummy.Name);
                        if (idx >= 0)
                        {
                            foundPlugins[idx] = dummy;
                            // TRANSLATORS: Log message. In PluginManager. {0} is plugin name. {1} is plugin index.
                            Logger.Log(T._("    - {0} [{1}]", dummy.Name, idx));
                        }
                        else
                        {
                            // TRANSLATORS: Log message. In PluginManager. {0} is plugin name.
                            Logger.Log(T._("    - {0} (disabled)", dummy.Name));
                        }
                    }
                }
            }
            var ret = foundPlugins.Where(i => i != null).ToArray();

            this.Plugins      = ret.Select(p => { p.Initialize(this, ret); return(p); }).ToArray();
            bot.AnnounceLabel = this.AnnounceLabel;
            bot.SpeakLabel    = this.SpeakLabel;
            bot.AddSchedules(this.Schedules.ToArray());
            Loaded = true;
        }