[NF] Refactoring Hue-Bot
[NF] Now Running as Service
This commit is contained in:
parent
444c9914c4
commit
0ecf7c24cc
24
Bot.cs
24
Bot.cs
@ -7,11 +7,11 @@ using BlubbFish.Utils.IoT.Bots.Events;
|
||||
using BlubbFish.Utils.IoT.Bots.Interfaces;
|
||||
|
||||
namespace BlubbFish.Utils.IoT.Bots {
|
||||
public abstract class Bot {
|
||||
public abstract class Bot<T> {
|
||||
private Thread sig_thread;
|
||||
private Boolean RunningProcess = true;
|
||||
protected ProgramLogger logger = new ProgramLogger();
|
||||
protected readonly Dictionary<String, Object> moduls = new Dictionary<String, Object>();
|
||||
protected readonly Dictionary<String, AModul<T>> moduls = new Dictionary<String, AModul<T>>();
|
||||
|
||||
protected void WaitForShutdown() {
|
||||
if (Type.GetType("Mono.Runtime") != null) {
|
||||
@ -44,9 +44,9 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
this.RunningProcess = false;
|
||||
}
|
||||
|
||||
protected void ModulDispose<T>() {
|
||||
foreach (KeyValuePair<String, Object> item in this.moduls) {
|
||||
((AModul<T>)item.Value).Dispose();
|
||||
protected void ModulDispose() {
|
||||
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
||||
item.Value.Dispose();
|
||||
Console.WriteLine("Modul entladen: " + item.Key);
|
||||
}
|
||||
if (this.sig_thread != null && this.sig_thread.IsAlive) {
|
||||
@ -54,7 +54,7 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
}
|
||||
}
|
||||
|
||||
protected void ModulLoader<T>(String @namespace, Object library) {
|
||||
protected void ModulLoader(String @namespace, Object library) {
|
||||
Assembly asm = Assembly.GetEntryAssembly();
|
||||
foreach (Type item in asm.GetTypes()) {
|
||||
if (item.Namespace == @namespace) {
|
||||
@ -71,15 +71,15 @@ namespace BlubbFish.Utils.IoT.Bots {
|
||||
}
|
||||
}
|
||||
|
||||
protected void ModulInterconnect<T>() {
|
||||
foreach (KeyValuePair<String, Object> item in this.moduls) {
|
||||
((AModul<T>)item.Value).Interconnect(this.moduls);
|
||||
protected void ModulInterconnect() {
|
||||
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
||||
item.Value.Interconnect(this.moduls);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ModulEvents<T>() {
|
||||
foreach (KeyValuePair<String, Object> item in this.moduls) {
|
||||
((AModul<T>)item.Value).Update += this.ModulUpdate;
|
||||
protected void ModulEvents() {
|
||||
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
||||
item.Value.Update += this.ModulUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
||||
return new Dictionary<String, Dictionary<String, String>>();
|
||||
}
|
||||
|
||||
public virtual void Interconnect(Dictionary<String, Object> moduls) { }
|
||||
public virtual void Interconnect(Dictionary<String, AModul<T>> moduls) { }
|
||||
|
||||
public virtual void SetInterconnection(String param, Action<Object> hook, Object data) { }
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
||||
public abstract class Mqtt<T> : AModul<T>, IDisposable {
|
||||
protected readonly Thread connectionWatcher;
|
||||
protected ABackend mqtt;
|
||||
protected Dictionary<String, Object> modules;
|
||||
protected Dictionary<String, AModul<T>> modules;
|
||||
|
||||
#region Constructor
|
||||
public Mqtt(T lib, InIReader settings) : base(lib, settings) {
|
||||
@ -45,7 +45,7 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
||||
#endregion
|
||||
|
||||
#region AModul
|
||||
public override void Interconnect(Dictionary<String, Object> moduls) {
|
||||
public override void Interconnect(Dictionary<String, AModul<T>> moduls) {
|
||||
this.modules = moduls;
|
||||
}
|
||||
|
||||
@ -61,9 +61,9 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
||||
return new Tuple<Boolean, MqttEvent>(false, null);
|
||||
}
|
||||
AModul<T> modul = null;
|
||||
foreach (KeyValuePair<String, Object> item in this.modules) {
|
||||
foreach (KeyValuePair<String, AModul<T>> item in this.modules) {
|
||||
if (item.Key.ToLower() == m.Groups[1].Value) {
|
||||
modul = ((AModul<T>)item.Value);
|
||||
modul = item.Value;
|
||||
}
|
||||
}
|
||||
if (modul == null) {
|
||||
|
@ -59,7 +59,7 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
||||
#endregion
|
||||
|
||||
#region AModul
|
||||
public override void Interconnect(Dictionary<String, Object> moduls) { }
|
||||
public override void Interconnect(Dictionary<String, AModul<T>> moduls) { }
|
||||
protected override void UpdateConfig() {
|
||||
this.ParseIni();
|
||||
}
|
||||
|
@ -16,14 +16,14 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
||||
#endregion
|
||||
|
||||
#region AModul
|
||||
public override void Interconnect(Dictionary<String, Object> moduls) {
|
||||
foreach (KeyValuePair<String, Object> item in moduls) {
|
||||
public override void Interconnect(Dictionary<String, AModul<T>> moduls) {
|
||||
foreach (KeyValuePair<String, AModul<T>> item in moduls) {
|
||||
if (item.Value is CronJob<T>) {
|
||||
((AModul<T>)item.Value).SetInterconnection("0 0 * * *", new Action<Object>(this.PollAll), null);
|
||||
item.Value.SetInterconnection("0 0 * * *", new Action<Object>(this.PollAll), null);
|
||||
if (this.config.Count != 0) {
|
||||
foreach (KeyValuePair<String, Dictionary<String, String>> section in this.config) {
|
||||
if (section.Value.ContainsKey("cron") && section.Value.ContainsKey("devices")) {
|
||||
((AModul<T>)item.Value).SetInterconnection(section.Value["cron"], new Action<Object>(this.PollSpecific), section.Value["devices"]);
|
||||
item.Value.SetInterconnection(section.Value["cron"], new Action<Object>(this.PollSpecific), section.Value["devices"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user