[NF] AUserBackend hinzugefügt
This commit is contained in:
parent
086bc89c2d
commit
4545c506fc
@ -7,9 +7,13 @@ namespace IoTBot.Condition {
|
|||||||
abstract class ACondition {
|
abstract class ACondition {
|
||||||
protected ASensor sensor;
|
protected ASensor sensor;
|
||||||
protected Dictionary<String, String> settings;
|
protected Dictionary<String, String> settings;
|
||||||
|
protected ADataBackend data;
|
||||||
|
protected AUserBackend user;
|
||||||
|
|
||||||
public ACondition(Dictionary<String, String> settings, ADataBackend backend) {
|
public ACondition(Dictionary<String, String> settings, ADataBackend data, AUserBackend user) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
this.data = data;
|
||||||
|
this.user = user;
|
||||||
Dictionary<String, String> l = new Dictionary<String, String> {
|
Dictionary<String, String> l = new Dictionary<String, String> {
|
||||||
{ "topic", this.settings["sensor_topic"] },
|
{ "topic", this.settings["sensor_topic"] },
|
||||||
{ "type", this.settings["sensor"] }
|
{ "type", this.settings["sensor"] }
|
||||||
@ -17,13 +21,13 @@ namespace IoTBot.Condition {
|
|||||||
if(settings.ContainsKey("sensor_polling")) {
|
if(settings.ContainsKey("sensor_polling")) {
|
||||||
l.Add("polling", this.settings["sensor_polling"]);
|
l.Add("polling", this.settings["sensor_polling"]);
|
||||||
}
|
}
|
||||||
this.sensor = ASensor.GetInstance(backend, l, "testSensor");
|
this.sensor = ASensor.GetInstance(data, l, "testSensor");
|
||||||
this.sensor.Update += this.Sensor_Update;
|
this.sensor.Update += this.Sensor_Update;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void Sensor_Update(Object sender, EventArgs e);
|
protected abstract void Sensor_Update(Object sender, EventArgs e);
|
||||||
|
|
||||||
public static ACondition GetInstance(Dictionary<String, String> settings, ADataBackend backend) {
|
public static ACondition GetInstance(Dictionary<String, String> settings, ADataBackend data, AUserBackend user) {
|
||||||
String object_condition = "IoTBot.Condition." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
|
String object_condition = "IoTBot.Condition." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
|
||||||
Type t = null;
|
Type t = null;
|
||||||
try {
|
try {
|
||||||
@ -31,7 +35,7 @@ namespace IoTBot.Condition {
|
|||||||
} catch(TypeLoadException) {
|
} catch(TypeLoadException) {
|
||||||
throw new ArgumentException("condition.ini: " + settings["type"] + " is not a Sensor");
|
throw new ArgumentException("condition.ini: " + settings["type"] + " is not a Sensor");
|
||||||
}
|
}
|
||||||
return (ACondition)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(ADataBackend) }).Invoke(new Object[] { settings, backend });
|
return (ACondition)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(ADataBackend), typeof(AUserBackend) }).Invoke(new Object[] { settings, data, user });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,15 +7,13 @@ namespace IoTBot.Condition {
|
|||||||
class Edge : ACondition {
|
class Edge : ACondition {
|
||||||
private Boolean histBool;
|
private Boolean histBool;
|
||||||
|
|
||||||
public Edge(Dictionary<String, String> settings, ADataBackend backend) : base(settings, backend) {
|
public Edge(Dictionary<String, String> settings, ADataBackend data, AUserBackend user) : base(settings, data, user) { }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Sensor_Update(Object sender, EventArgs e) {
|
protected override void Sensor_Update(Object sender, EventArgs e) {
|
||||||
if(this.sensor.Datatypes == ASensor.Types.Bool) {
|
if(this.sensor.Datatypes == ASensor.Types.Bool) {
|
||||||
if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) {
|
if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) {
|
||||||
this.histBool = this.sensor.GetBool;
|
this.histBool = this.sensor.GetBool;
|
||||||
Telegram.Instance.Send("Jemand ist DA!");
|
this.user.Send("Jemand ist DA!");
|
||||||
} else {
|
} else {
|
||||||
this.histBool = this.sensor.GetBool;
|
this.histBool = this.sensor.GetBool;
|
||||||
}
|
}
|
||||||
|
@ -9,25 +9,23 @@ namespace IoTBot {
|
|||||||
private InIReader ini;
|
private InIReader ini;
|
||||||
private static ConditionWorker instance;
|
private static ConditionWorker instance;
|
||||||
private List<ACondition> conditions;
|
private List<ACondition> conditions;
|
||||||
private Telegram telegram;
|
|
||||||
|
|
||||||
public static ConditionWorker GetInstance(ADataBackend backend) {
|
public static ConditionWorker GetInstance(ADataBackend data, AUserBackend user) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new ConditionWorker(backend);
|
instance = new ConditionWorker(data, user);
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Run(Telegram telegram) {
|
internal void Run() {
|
||||||
this.telegram = telegram;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConditionWorker(ADataBackend backend) {
|
private ConditionWorker(ADataBackend data, AUserBackend user) {
|
||||||
this.ini = InIReader.GetInstance("condition.ini");
|
this.ini = InIReader.GetInstance("condition.ini");
|
||||||
this.conditions = new List<ACondition>();
|
this.conditions = new List<ACondition>();
|
||||||
List<String> sections = this.ini.GetSections();
|
List<String> sections = this.ini.GetSections();
|
||||||
foreach(String section in sections) {
|
foreach(String section in sections) {
|
||||||
this.conditions.Add(ACondition.GetInstance(this.ini.GetSection(section), backend));
|
this.conditions.Add(ACondition.GetInstance(this.ini.GetSection(section), data, user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,12 @@ namespace IoTBot {
|
|||||||
class Program {
|
class Program {
|
||||||
static void Main(String[] args) {
|
static void Main(String[] args) {
|
||||||
ADataBackend mqtt = ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
|
ADataBackend mqtt = ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
|
||||||
ConditionWorker.GetInstance(mqtt).Run(Telegram.Instance);
|
AUserBackend telegram = AUserBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("user"));
|
||||||
|
ConditionWorker.GetInstance(mqtt, telegram).Run();
|
||||||
mqtt.MessageIncomming += Mqtt_MessageIncomming;
|
mqtt.MessageIncomming += Mqtt_MessageIncomming;
|
||||||
mqtt.MessageSending += Mqtt_MessageSending;
|
mqtt.MessageSending += Mqtt_MessageSending;
|
||||||
Telegram.Instance.MessageIncomming += Telegram_MessageIncomming;
|
telegram.MessageIncomming += Telegram_MessageIncomming;
|
||||||
Telegram.Instance.MessageSending += Telegram_MessageSending;
|
telegram.MessageSending += Telegram_MessageSending;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
System.Threading.Thread.Sleep(100);
|
System.Threading.Thread.Sleep(100);
|
||||||
@ -21,11 +22,11 @@ namespace IoTBot {
|
|||||||
Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
|
Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Telegram_MessageSending(Object sender, TelegramEventArgs e) {
|
private static void Telegram_MessageSending(Object sender, UserMessageEventArgs e) {
|
||||||
Console.WriteLine("-> [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Message + " on " + e.UserId);
|
Console.WriteLine("-> [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Message + " on " + e.UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Telegram_MessageIncomming(Object sender, TelegramEventArgs e) {
|
private static void Telegram_MessageIncomming(Object sender, UserMessageEventArgs e) {
|
||||||
Console.WriteLine("<- [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Message + " on " + e.UserId);
|
Console.WriteLine("<- [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Message + " on " + e.UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
[general]
|
[user]
|
||||||
|
type=telegram
|
||||||
telegram-key=ABCDEFGH
|
telegram-key=ABCDEFGH
|
||||||
chatid=1234
|
chatid=1234
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user