2017-09-26 21:44:41 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2017-10-02 18:32:06 +02:00
|
|
|
|
namespace BlubbFish.Utils.IoT.Connector {
|
2017-09-26 21:44:41 +02:00
|
|
|
|
public abstract class ADataBackend {
|
|
|
|
|
|
|
|
|
|
public abstract event MqttMessage MessageIncomming;
|
|
|
|
|
public abstract event MqttMessage MessageSending;
|
2017-10-02 18:32:06 +02:00
|
|
|
|
public delegate void MqttMessage(Object sender, MqttEventArgs e);
|
2017-09-26 21:44:41 +02:00
|
|
|
|
|
2017-10-03 00:55:04 +02:00
|
|
|
|
public static ADataBackend GetInstance(Dictionary<String, String> settings) {
|
2017-12-18 23:30:48 +01:00
|
|
|
|
if(settings.Count == 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String object_sensor = "BlubbFish.Utils.IoT.Connector.Data." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower()+", "+ "ConnectorData" + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
|
2017-09-26 21:44:41 +02:00
|
|
|
|
Type t = null;
|
|
|
|
|
try {
|
|
|
|
|
t = Type.GetType(object_sensor, true);
|
|
|
|
|
} catch (TypeLoadException) {
|
2017-10-03 00:55:04 +02:00
|
|
|
|
throw new ArgumentException("settings.ini: " + settings["type"] + " is not a DataBackend");
|
2017-09-26 21:44:41 +02:00
|
|
|
|
}
|
2017-10-03 00:55:04 +02:00
|
|
|
|
return (ADataBackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings });
|
2017-09-26 21:44:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void Send(String topic, String data);
|
|
|
|
|
|
|
|
|
|
public abstract void Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|