2017-10-02 18:26:38 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace BlubbFish.Utils.IoT.Connector {
|
|
|
|
|
public abstract class ADataBackend {
|
|
|
|
|
|
|
|
|
|
public abstract event MqttMessage MessageIncomming;
|
|
|
|
|
public abstract event MqttMessage MessageSending;
|
|
|
|
|
public delegate void MqttMessage(Object sender, MqttEventArgs e);
|
|
|
|
|
|
2017-10-03 00:51:08 +02:00
|
|
|
|
public static ADataBackend GetInstance(Dictionary<String, String> settings) {
|
2017-10-29 20:32:18 +01:00
|
|
|
|
if(settings.Count == 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-12-03 12:23:19 +01:00
|
|
|
|
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-10-02 18:26:38 +02:00
|
|
|
|
Type t = null;
|
|
|
|
|
try {
|
|
|
|
|
t = Type.GetType(object_sensor, true);
|
|
|
|
|
} catch (TypeLoadException) {
|
2018-01-01 16:03:15 +01:00
|
|
|
|
Console.Error.WriteLine("settings.ini: " + settings["type"] + " is not a DataBackend");
|
|
|
|
|
return null;
|
|
|
|
|
} catch(System.IO.FileNotFoundException) {
|
|
|
|
|
Console.Error.WriteLine("Driver " + settings["type"] + " could not load!");
|
|
|
|
|
return null;
|
2017-10-02 18:26:38 +02:00
|
|
|
|
}
|
2017-10-03 00:51:08 +02:00
|
|
|
|
return (ADataBackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings });
|
2017-10-02 18:26:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void Send(String topic, String data);
|
|
|
|
|
|
|
|
|
|
public abstract void Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|