72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BlubbFish.IoT.Zway;
|
|
using BlubbFish.Utils;
|
|
|
|
namespace ZwayBot {
|
|
abstract class AModul {
|
|
protected ZwayController zw;
|
|
private InIReader settings;
|
|
protected Dictionary<String, Dictionary<String, String>> config = new Dictionary<String, Dictionary<String, String>>();
|
|
|
|
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(ZwayController zway, InIReader settings) {
|
|
this.HasConfig = false;
|
|
this.ConfigPublic = false;
|
|
this.zw = zway;
|
|
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<String, Dictionary<String, String>> GetConfig() {
|
|
if (this.HasConfig && this.ConfigPublic) {
|
|
Dictionary<String, Dictionary<String, String>> ret = new Dictionary<String, Dictionary<String, String>>(this.config);
|
|
if(ret.ContainsKey("modul")) {
|
|
ret.Remove("modul");
|
|
}
|
|
return ret;
|
|
}
|
|
return new Dictionary<String, Dictionary<String, String>>();
|
|
}
|
|
|
|
public virtual void Interconnect(Dictionary<String, AModul> moduls) { }
|
|
|
|
public virtual void SetInterconnection(String param, Action<Object> hook, Object data) { }
|
|
|
|
public abstract void Dispose();
|
|
|
|
internal void SetConfig(Dictionary<String, Dictionary<String, String>> 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();
|
|
}
|
|
}
|