using System; using System.Collections.Generic; using BlubbFish.Utils.IoT.Bots.Events; namespace BlubbFish.Utils.IoT.Bots.Moduls { public abstract class AModul { protected T library; private readonly InIReader settings; protected Dictionary> config = new Dictionary>(); public Boolean HasConfig { get; private set; } public Boolean ConfigPublic { get; private set; } public delegate void ModulEvent(Object sender, ModulEventArgs e); public abstract event ModulEvent Update; public AModul(T lib, InIReader settings) { this.HasConfig = false; this.ConfigPublic = false; this.library = lib; this.settings = settings; this.ParseConfig(); } private void ParseConfig() { if (this.settings != null) { this.HasConfig = true; foreach (String item in this.settings.GetSections(false)) { this.config.Add(item, this.settings.GetSection(item)); } if (this.config.ContainsKey("modul")) { this.ConfigPublic = this.config["modul"].ContainsKey("config") && this.config["modul"]["config"].ToLower() == "public"; } } } public Dictionary> GetConfig() { if (this.HasConfig && this.ConfigPublic) { Dictionary> ret = new Dictionary>(this.config); if (ret.ContainsKey("modul")) { ret.Remove("modul"); } return ret; } return new Dictionary>(); } public virtual void Interconnect(Dictionary> moduls) { } public virtual void SetInterconnection(String param, Action hook, Object data) { } public abstract void Dispose(); public void SetConfig(Dictionary> newconf) { if (this.HasConfig && this.ConfigPublic) { if (newconf.ContainsKey("modul")) { newconf.Remove("modul"); } if (this.config.ContainsKey("modul")) { newconf.Add("modul", this.config["modul"]); } this.config = newconf; this.settings.SetSections(this.config); this.UpdateConfig(); } } protected abstract void UpdateConfig(); } }