2018-06-09 23:27:15 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|
|
|
|
public abstract class Overtaker<T> : AModul<T>, IDisposable {
|
|
|
|
|
protected readonly Dictionary<String, Dictionary<String, String>> events = new Dictionary<String, Dictionary<String, String>>();
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
public Overtaker(T lib, InIReader settings) : base(lib, settings) {
|
|
|
|
|
this.ParseIni();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Overtakerfunctions
|
|
|
|
|
protected void ParseIni() {
|
2018-10-02 16:53:59 +02:00
|
|
|
|
this.RemoveLibraryUpdateHooks();
|
2018-06-09 23:27:15 +02:00
|
|
|
|
foreach (KeyValuePair<String, Dictionary<String, String>> item in this.config) {
|
|
|
|
|
if (item.Value.ContainsKey("from")) {
|
|
|
|
|
String from = item.Value["from"];
|
|
|
|
|
String[] source = from.Split(':');
|
|
|
|
|
this.events.Add(source[0], item.Value);
|
2018-10-02 16:53:59 +02:00
|
|
|
|
this.AddLibraryUpdateHook(source[0]);
|
2018-06-09 23:27:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void SetValues(Object sender, String name, Dictionary<String, String> dictionary) {
|
|
|
|
|
String from = dictionary["from"];
|
|
|
|
|
String[] source = from.Split(':');
|
|
|
|
|
if (source.Length != 2) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String source_value;
|
|
|
|
|
if (sender.HasProperty(source[1])) {
|
|
|
|
|
source_value = sender.GetProperty(source[1]).ToString();
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (dictionary.ContainsKey("convert")) {
|
|
|
|
|
foreach (String tuple in dictionary["convert"].Split(';')) {
|
|
|
|
|
String[] item = tuple.Split('-');
|
|
|
|
|
if (source_value == item[0]) {
|
|
|
|
|
source_value = item[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (dictionary.ContainsKey("to")) {
|
|
|
|
|
foreach (String to in dictionary["to"].Split(';')) {
|
|
|
|
|
String[] target = to.Split(':');
|
|
|
|
|
if (target.Length == 2) {
|
|
|
|
|
this.SetValueHook(target[0], target[1], source_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 16:53:59 +02:00
|
|
|
|
protected abstract void AddLibraryUpdateHook(String id);
|
|
|
|
|
|
|
|
|
|
protected abstract void RemoveLibraryUpdateHooks();
|
2018-06-09 23:27:15 +02:00
|
|
|
|
|
|
|
|
|
protected abstract void SetValueHook(String id, String prop, String value);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region AModul
|
2018-06-10 21:48:23 +02:00
|
|
|
|
public override void Interconnect(Dictionary<String, AModul<T>> moduls) { }
|
2018-06-09 23:27:15 +02:00
|
|
|
|
protected override void UpdateConfig() {
|
|
|
|
|
this.ParseIni();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IDisposable Support
|
|
|
|
|
private Boolean disposedValue = false;
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(Boolean disposing) {
|
|
|
|
|
if (!this.disposedValue) {
|
|
|
|
|
if (disposing) {
|
|
|
|
|
}
|
|
|
|
|
this.disposedValue = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Dispose() {
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|