2017-09-26 21:44:41 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2017-10-02 00:49:44 +02:00
|
|
|
|
namespace IoTBot.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 00:49:44 +02:00
|
|
|
|
public delegate void MqttMessage(ADataBackend sender, MqttEventArgs e);
|
2017-09-26 21:44:41 +02:00
|
|
|
|
|
|
|
|
|
public static ADataBackend GetInstance(Dictionary<String, String> dictionary) {
|
2017-10-02 00:49:44 +02:00
|
|
|
|
String object_sensor = "IoTBot.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
2017-09-26 21:44:41 +02:00
|
|
|
|
Type t = null;
|
|
|
|
|
try {
|
|
|
|
|
t = Type.GetType(object_sensor, true);
|
|
|
|
|
} catch (TypeLoadException) {
|
|
|
|
|
throw new ArgumentException("settings.ini: " + dictionary["type"] + " is not a Connector");
|
|
|
|
|
}
|
|
|
|
|
return (ADataBackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { dictionary });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void Send(String topic, String data);
|
|
|
|
|
|
|
|
|
|
public abstract void Dispose();
|
|
|
|
|
}
|
|
|
|
|
public class MqttEventArgs : EventArgs {
|
|
|
|
|
public MqttEventArgs() : base() { }
|
|
|
|
|
public MqttEventArgs(String message, String topic) {
|
|
|
|
|
this.Topic = topic;
|
|
|
|
|
this.Message = message;
|
|
|
|
|
this.Date = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String Topic { get; private set; }
|
|
|
|
|
public String Message { get; private set; }
|
|
|
|
|
public DateTime Date { get; private set; }
|
|
|
|
|
}
|
|
|
|
|
}
|