[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;
|
using BlubbFish.Utils.IoT.Bots.Interfaces;
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots {
|
namespace BlubbFish.Utils.IoT.Bots {
|
||||||
public abstract class Bot {
|
public abstract class Bot<T> {
|
||||||
private Thread sig_thread;
|
private Thread sig_thread;
|
||||||
private Boolean RunningProcess = true;
|
private Boolean RunningProcess = true;
|
||||||
protected ProgramLogger logger = new ProgramLogger();
|
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() {
|
protected void WaitForShutdown() {
|
||||||
if (Type.GetType("Mono.Runtime") != null) {
|
if (Type.GetType("Mono.Runtime") != null) {
|
||||||
@ -44,9 +44,9 @@ namespace BlubbFish.Utils.IoT.Bots {
|
|||||||
this.RunningProcess = false;
|
this.RunningProcess = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ModulDispose<T>() {
|
protected void ModulDispose() {
|
||||||
foreach (KeyValuePair<String, Object> item in this.moduls) {
|
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
||||||
((AModul<T>)item.Value).Dispose();
|
item.Value.Dispose();
|
||||||
Console.WriteLine("Modul entladen: " + item.Key);
|
Console.WriteLine("Modul entladen: " + item.Key);
|
||||||
}
|
}
|
||||||
if (this.sig_thread != null && this.sig_thread.IsAlive) {
|
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();
|
Assembly asm = Assembly.GetEntryAssembly();
|
||||||
foreach (Type item in asm.GetTypes()) {
|
foreach (Type item in asm.GetTypes()) {
|
||||||
if (item.Namespace == @namespace) {
|
if (item.Namespace == @namespace) {
|
||||||
@ -71,15 +71,15 @@ namespace BlubbFish.Utils.IoT.Bots {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ModulInterconnect<T>() {
|
protected void ModulInterconnect() {
|
||||||
foreach (KeyValuePair<String, Object> item in this.moduls) {
|
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
||||||
((AModul<T>)item.Value).Interconnect(this.moduls);
|
item.Value.Interconnect(this.moduls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ModulEvents<T>() {
|
protected void ModulEvents() {
|
||||||
foreach (KeyValuePair<String, Object> item in this.moduls) {
|
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
||||||
((AModul<T>)item.Value).Update += this.ModulUpdate;
|
item.Value.Update += this.ModulUpdate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|||||||
return new Dictionary<String, Dictionary<String, String>>();
|
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) { }
|
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 {
|
public abstract class Mqtt<T> : AModul<T>, IDisposable {
|
||||||
protected readonly Thread connectionWatcher;
|
protected readonly Thread connectionWatcher;
|
||||||
protected ABackend mqtt;
|
protected ABackend mqtt;
|
||||||
protected Dictionary<String, Object> modules;
|
protected Dictionary<String, AModul<T>> modules;
|
||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
public Mqtt(T lib, InIReader settings) : base(lib, settings) {
|
public Mqtt(T lib, InIReader settings) : base(lib, settings) {
|
||||||
@ -45,7 +45,7 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AModul
|
#region AModul
|
||||||
public override void Interconnect(Dictionary<String, Object> moduls) {
|
public override void Interconnect(Dictionary<String, AModul<T>> moduls) {
|
||||||
this.modules = moduls;
|
this.modules = moduls;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,9 +61,9 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|||||||
return new Tuple<Boolean, MqttEvent>(false, null);
|
return new Tuple<Boolean, MqttEvent>(false, null);
|
||||||
}
|
}
|
||||||
AModul<T> modul = 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) {
|
if (item.Key.ToLower() == m.Groups[1].Value) {
|
||||||
modul = ((AModul<T>)item.Value);
|
modul = item.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (modul == null) {
|
if (modul == null) {
|
||||||
|
@ -59,7 +59,7 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AModul
|
#region AModul
|
||||||
public override void Interconnect(Dictionary<String, Object> moduls) { }
|
public override void Interconnect(Dictionary<String, AModul<T>> moduls) { }
|
||||||
protected override void UpdateConfig() {
|
protected override void UpdateConfig() {
|
||||||
this.ParseIni();
|
this.ParseIni();
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@ namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AModul
|
#region AModul
|
||||||
public override void Interconnect(Dictionary<String, Object> moduls) {
|
public override void Interconnect(Dictionary<String, AModul<T>> moduls) {
|
||||||
foreach (KeyValuePair<String, Object> item in moduls) {
|
foreach (KeyValuePair<String, AModul<T>> item in moduls) {
|
||||||
if (item.Value is CronJob<T>) {
|
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) {
|
if (this.config.Count != 0) {
|
||||||
foreach (KeyValuePair<String, Dictionary<String, String>> section in this.config) {
|
foreach (KeyValuePair<String, Dictionary<String, String>> section in this.config) {
|
||||||
if (section.Value.ContainsKey("cron") && section.Value.ContainsKey("devices")) {
|
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