public void InitializeAddons() { // Note: We assume all cores have already been loaded, so just ship them in with the addon initialization // First initialize the independent addons foreach (var addon in AddonList.Where(addon => addon.AddonDependencies.Count == 0)) { var baseaddon = addon as Addons.Base.AddonBase; ComponentList componentList = new Bot.ComponentList(AddonList.Where(a => addon.AddonDependencies.Exists(depName => depName == a.Name)) as IEnumerable <IComponentBase>); componentList.AddRange(new CoreList(CoreList.Where(a => addon.CoreDependencies.GetEverything || addon.CoreDependencies.Exists(depName => depName == a.Name))).Cast <IComponentBase>()); baseaddon.Initialize(componentList); } // Then initialize the ones with dependencies already initialized.. Rinse and repeat until we can't go further bool Change; do { Change = false; foreach (var addon in AddonList.Where(zeAddon => zeAddon.IsInitialized == false && zeAddon.AddonDependencies.All(y => AddonList.Any(z => z.Name == y && z.IsInitialized == true)))) { Change = true; var baseaddon = addon as Addons.Base.AddonBase; ComponentList componentList = new Bot.ComponentList(AddonList.Where(a => addon.AddonDependencies.Exists(depName => depName == a.Name)) as IEnumerable <IComponentBase>); componentList.AddRange(new CoreList(CoreList.Where(a => addon.CoreDependencies.GetEverything || addon.CoreDependencies.Exists(depName => depName == a.Name))).Cast <IComponentBase>()); baseaddon.Initialize(componentList); } }while (AddonList.Count(core => core.IsInitialized) < AddonList.Count && Change); // The last addons who ultimate require each other.. Let's go a little crazy, but at least try to load the ones with the "most" addons already loaded Change = false; do { Change = false; foreach (var addon in AddonList.Where(addon => addon.IsInitialized == false).OrderByDescending(_addon => _addon.AddonDependencies.Count(__addon => AddonList.Exists(___addon => ___addon.Name == __addon && ___addon.IsInitialized == true)))) { try { Change = true; var baseaddon = addon as Addons.Base.AddonBase; ComponentList componentList = new Bot.ComponentList(AddonList.Where(a => addon.AddonDependencies.Exists(depName => depName == a.Name)) as IEnumerable <IComponentBase>); componentList.AddRange(new CoreList(CoreList.Where(a => addon.CoreDependencies.GetEverything || addon.CoreDependencies.Exists(depName => depName == a.Name))).Cast <IComponentBase>()); baseaddon.Initialize(componentList); } catch (Exception ex) { // Didn't work :-( Try next? } } }while (AddonList.Count(addon => addon.IsInitialized) < AddonList.Count && Change); }
public void Initialize(Bot.ComponentList ComponentList) { try { var core = this as IAddon; core.UserInitialize(ComponentList); this.IsInitialized = true; logger.Debug(this.Name + " initialized successfully."); } catch (Exception) { } }
public void UserInitialize(Bot.ComponentList ComponentList) { // Hello this.Name = this.GetType().Name; ModelCustomizer.AddModelCustomization(Hooks.ModelCustomizer.OnModelCreating); this.ServerQueryConnection = ComponentList[typeof(Core.ServerQueryConnection.ServerQueryConnection).Name] as Core.ServerQueryConnection.ServerQueryConnection; this.ServerQueryAddon = ComponentList[typeof(Core.ServerQueryShell.ServerQueryShell).Name] as Core.ServerQueryShell.ServerQueryShell; this.testAddon = ComponentList[typeof(TestAddon).Name] as TestAddon; // Native serverquery events are in queryRunner object. this.ServerQueryConnection.BotCommandAttempt += ServerQueryConnection_BotCommandReceived; this.ServerQueryConnection.QueryRunner.Notifications.ClientMoved += Notifications_ClientMoved; }
public void UserInitialize(Bot.ComponentList ComponentList) { // Hello this.Name = this.GetType().Name; ModelCustomizer.AddModelCustomization(Hooks.ModelCustomizer.OnModelCreating); this.ServerQueryConnection = ComponentList[typeof(Core.ServerQueryConnection.ServerQueryConnection).Name] as Core.ServerQueryConnection.ServerQueryConnection; this.testAddon = ComponentList[typeof(TestAddon.TestAddon).Name] as TestAddon.TestAddon; // Native serverquery events are in queryRunner object. this.ServerQueryConnection.QueryRunner.Notifications.ClientMoved += Notifications_ClientMoved; this.ServerQueryConnection.QueryRunner.Notifications.ClientJoined += onClientConnect; BotHasReturnedMessage(); //Tell everyone you're back }