[NF] Ein paar verbesserungen
This commit is contained in:
parent
7f0de5503f
commit
ed92555d1e
@ -2,28 +2,26 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Dashboard.Connector {
|
namespace Dashboard.Connector {
|
||||||
abstract class ADataBackend {
|
public abstract class ADataBackend {
|
||||||
|
|
||||||
public abstract event MqttMessage MessageIncomming;
|
public abstract event MqttMessage MessageIncomming;
|
||||||
public abstract event MqttMessage MessageSending;
|
public abstract event MqttMessage MessageSending;
|
||||||
public delegate void MqttMessage(Object sender, MqttEventArgs e);
|
public delegate void MqttMessage(Object sender, MqttEventArgs e);
|
||||||
|
|
||||||
internal static void SetInstance(Dictionary<String, String> dictionary) {
|
public static ADataBackend GetInstance(Dictionary<String, String> dictionary) {
|
||||||
String object_sensor = "Dashboard.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1);
|
String object_sensor = "Dashboard.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||||
Type t = null;
|
Type t = null;
|
||||||
try {
|
try {
|
||||||
t = Type.GetType(object_sensor, true);
|
t = Type.GetType(object_sensor, true);
|
||||||
} catch (TypeLoadException) {
|
} catch (TypeLoadException) {
|
||||||
throw new ArgumentException("settings.ini: " + dictionary["type"] + " is not a Connector");
|
throw new ArgumentException("settings.ini: " + dictionary["type"] + " is not a Connector");
|
||||||
}
|
}
|
||||||
Instance = (ADataBackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { dictionary });
|
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 Send(String topic, String data);
|
||||||
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
|
|
||||||
public static ADataBackend Instance { get; private set; }
|
|
||||||
}
|
}
|
||||||
public class MqttEventArgs : EventArgs {
|
public class MqttEventArgs : EventArgs {
|
||||||
public MqttEventArgs() : base() { }
|
public MqttEventArgs() : base() { }
|
||||||
|
@ -11,6 +11,21 @@
|
|||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<PublishUrl>publish\</PublishUrl>
|
||||||
|
<Install>true</Install>
|
||||||
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
<UpdateEnabled>false</UpdateEnabled>
|
||||||
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
|
<UpdateInterval>7</UpdateInterval>
|
||||||
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
|
<UpdateRequired>false</UpdateRequired>
|
||||||
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@ -118,6 +133,17 @@
|
|||||||
<Name>Utils</Name>
|
<Name>Utils</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>Microsoft .NET Framework 4.5.2 %28x86 und x64%29</ProductName>
|
||||||
|
<Install>true</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||||
|
<Install>false</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -6,4 +6,14 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||||
<StartArguments>-debug</StartArguments>
|
<StartArguments>-debug</StartArguments>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<PublishUrlHistory />
|
||||||
|
<InstallUrlHistory />
|
||||||
|
<SupportUrlHistory />
|
||||||
|
<UpdateUrlHistory />
|
||||||
|
<BootstrapperUrlHistory />
|
||||||
|
<ErrorReportUrlHistory />
|
||||||
|
<FallbackCulture>de-DE</FallbackCulture>
|
||||||
|
<VerifyUploadedFiles>false</VerifyUploadedFiles>
|
||||||
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
@ -9,10 +9,11 @@ using Dashboard.Tracings;
|
|||||||
namespace Dashboard {
|
namespace Dashboard {
|
||||||
public partial class Dashboard : Form {
|
public partial class Dashboard : Form {
|
||||||
private Dictionary<String, ASensor> sensors = new Dictionary<String, ASensor>();
|
private Dictionary<String, ASensor> sensors = new Dictionary<String, ASensor>();
|
||||||
|
private ADataBackend mqtt;
|
||||||
|
|
||||||
public Dashboard(Boolean debug) {
|
public Dashboard(Boolean debug) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ADataBackend.SetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
|
this.mqtt = ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
|
||||||
|
|
||||||
this.GenerateSensors();
|
this.GenerateSensors();
|
||||||
this.GenerateForms();
|
this.GenerateForms();
|
||||||
@ -21,8 +22,8 @@ namespace Dashboard {
|
|||||||
this.SizeChanged += this.Dashboard_SizeChanged;
|
this.SizeChanged += this.Dashboard_SizeChanged;
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
ADataBackend.Instance.MessageIncomming += this.Instance_MessageIncomming;
|
this.mqtt.MessageIncomming += this.Instance_MessageIncomming;
|
||||||
ADataBackend.Instance.MessageSending += this.Instance_MessageSending;
|
this.mqtt.MessageSending += this.Instance_MessageSending;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,9 +33,9 @@ namespace Dashboard {
|
|||||||
|
|
||||||
private void GenerateSensors() {
|
private void GenerateSensors() {
|
||||||
InIReader ini = InIReader.GetInstance("sensor.ini");
|
InIReader ini = InIReader.GetInstance("sensor.ini");
|
||||||
List<String> sensorini = ini.GetSections();
|
List<String> sensorini = ini.GetSections(false);
|
||||||
foreach(String sensor in sensorini) {
|
foreach(String sensor in sensorini) {
|
||||||
this.sensors.Add(sensor.ToLower().Substring(1, sensor.Length - 2), ASensor.GetInstance(ini.GetValue(sensor, "type").ToLower(), ini.GetSection(sensor), sensor.Substring(1, sensor.Length - 2)));
|
this.sensors.Add(sensor.ToLower(), ASensor.GetInstance(this.mqtt, ini.GetSection(sensor), sensor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +55,9 @@ namespace Dashboard {
|
|||||||
item.Value.Dispose();
|
item.Value.Dispose();
|
||||||
}
|
}
|
||||||
this.sensors.Clear();
|
this.sensors.Clear();
|
||||||
ADataBackend.Instance.MessageIncomming -= this.Instance_MessageIncomming;
|
this.mqtt.MessageIncomming -= this.Instance_MessageIncomming;
|
||||||
ADataBackend.Instance.Dispose();
|
this.mqtt.MessageSending -= this.Instance_MessageSending;
|
||||||
|
this.mqtt.Dispose();
|
||||||
this.Dispose(true);
|
this.Dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,10 +10,9 @@ namespace Dashboard {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main(String[] args) {
|
static void Main(String[] args) {
|
||||||
Dictionary<String, CmdArgs.VaildArguments> pargs = new Dictionary<String, CmdArgs.VaildArguments> {
|
CmdArgs.Instance.SetArguments(new Dictionary<String, CmdArgs.VaildArguments> {
|
||||||
{ "-debug", new CmdArgs.VaildArguments(CmdArgs.ArgLength.Single) }
|
{ "-debug", new CmdArgs.VaildArguments(CmdArgs.ArgLength.Single) }
|
||||||
};
|
}, args);
|
||||||
CmdArgs.Instance.SetArguments(pargs, args);
|
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Boolean debug = false;
|
Boolean debug = false;
|
||||||
|
@ -10,10 +10,11 @@ namespace Dashboard.Sensor {
|
|||||||
protected String topic;
|
protected String topic;
|
||||||
protected Int32 pollcount;
|
protected Int32 pollcount;
|
||||||
private Dictionary<String, String> settings;
|
private Dictionary<String, String> settings;
|
||||||
|
protected ADataBackend backend;
|
||||||
private Thread updateThread;
|
private Thread updateThread;
|
||||||
private Boolean pollEnabled = false;
|
private Boolean pollEnabled = false;
|
||||||
|
|
||||||
public ASensor(Dictionary<String, String> settings, String name) {
|
public ASensor(Dictionary<String, String> settings, String name, ADataBackend backend) {
|
||||||
this.GetBool = true;
|
this.GetBool = true;
|
||||||
this.GetFloat = 0.0f;
|
this.GetFloat = 0.0f;
|
||||||
this.GetInt = 0;
|
this.GetInt = 0;
|
||||||
@ -21,7 +22,8 @@ namespace Dashboard.Sensor {
|
|||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.Title = (settings.Keys.Contains("title")) ? settings["title"] : "";
|
this.Title = (settings.Keys.Contains("title")) ? settings["title"] : "";
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
ADataBackend.Instance.MessageIncomming += this.IncommingMqttMessage;
|
this.backend = backend;
|
||||||
|
this.backend.MessageIncomming += this.IncommingMqttMessage;
|
||||||
if (settings.Keys.Contains("polling")) {
|
if (settings.Keys.Contains("polling")) {
|
||||||
this.pollEnabled = true;
|
this.pollEnabled = true;
|
||||||
this.Polling = Int32.Parse(settings["polling"]);
|
this.Polling = Int32.Parse(settings["polling"]);
|
||||||
@ -47,26 +49,26 @@ namespace Dashboard.Sensor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static ASensor GetInstance(String v, Dictionary<String, String> dictionary, String name) {
|
internal static ASensor GetInstance(ADataBackend backend, Dictionary<String, String> dictionary, String name) {
|
||||||
String object_sensor = "Dashboard.Sensor." + Char.ToUpper(v[0]) + v.Substring(1);
|
String object_sensor = "Dashboard.Sensor." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||||
Type t = null;
|
Type t = null;
|
||||||
try {
|
try {
|
||||||
t = Type.GetType(object_sensor, true);
|
t = Type.GetType(object_sensor, true);
|
||||||
} catch(TypeLoadException) {
|
} catch(TypeLoadException) {
|
||||||
throw new ArgumentException("sensor.ini: " + v + " is not a Sensor");
|
throw new ArgumentException("sensor.ini: " + dictionary["type"] + " is not a Sensor");
|
||||||
}
|
}
|
||||||
return (ASensor)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(String) }).Invoke(new Object[] { dictionary, name });
|
return (ASensor)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(String), typeof(ADataBackend) }).Invoke(new Object[] { dictionary, name, backend });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Poll() {
|
protected virtual void Poll() {
|
||||||
if(this.pollcount++ >= this.Polling) {
|
if(this.pollcount++ >= this.Polling) {
|
||||||
this.pollcount = 1;
|
this.pollcount = 1;
|
||||||
ADataBackend.Instance.Send(this.topic + "/status","");
|
this.backend.Send(this.topic + "/status","");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual void SetBool(Boolean v) {
|
internal virtual void SetBool(Boolean v) {
|
||||||
ADataBackend.Instance.Send(this.topic + "/set", v ? "on" : "off");
|
this.backend.Send(this.topic + "/set", v ? "on" : "off");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Boolean UpdateValue(MqttEventArgs e);
|
protected abstract Boolean UpdateValue(MqttEventArgs e);
|
||||||
@ -100,7 +102,7 @@ namespace Dashboard.Sensor {
|
|||||||
this.updateThread.Abort();
|
this.updateThread.Abort();
|
||||||
while (this.updateThread.ThreadState != ThreadState.Aborted) { }
|
while (this.updateThread.ThreadState != ThreadState.Aborted) { }
|
||||||
}
|
}
|
||||||
ADataBackend.Instance.MessageIncomming -= this.IncommingMqttMessage;
|
this.backend.MessageIncomming -= this.IncommingMqttMessage;
|
||||||
}
|
}
|
||||||
this.settings = null;
|
this.settings = null;
|
||||||
this.updateThread = null;
|
this.updateThread = null;
|
||||||
|
@ -9,7 +9,7 @@ namespace Dashboard.Sensor {
|
|||||||
class Flex4gridswitch : ASensor {
|
class Flex4gridswitch : ASensor {
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public Flex4gridswitch(Dictionary<String, String> settings, String name) : base(settings, name) {
|
public Flex4gridswitch(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||||
this.Datatypes = Types.Bool;
|
this.Datatypes = Types.Bool;
|
||||||
this.id = settings["id"];
|
this.id = settings["id"];
|
||||||
}
|
}
|
||||||
@ -40,13 +40,13 @@ namespace Dashboard.Sensor {
|
|||||||
if (this.pollcount++ >= this.Polling) {
|
if (this.pollcount++ >= this.Polling) {
|
||||||
this.pollcount = 1;
|
this.pollcount = 1;
|
||||||
String hid = Regex.Match(this.topic, "/flex4grid/v1/households/([^/]*)/device/state").Groups[1].Value;
|
String hid = Regex.Match(this.topic, "/flex4grid/v1/households/([^/]*)/device/state").Groups[1].Value;
|
||||||
ADataBackend.Instance.Send("/flex4grid/v1/households/" + hid + "/devices/state/request", "{\"timestamp\": \"" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") + "\"}");
|
this.backend.Send("/flex4grid/v1/households/" + hid + "/devices/state/request", "{\"timestamp\": \"" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") + "\"}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetBool(Boolean v) {
|
internal override void SetBool(Boolean v) {
|
||||||
String hid = Regex.Match(this.topic, "/flex4grid/v1/households/([^/]*)/device/state").Groups[1].Value;
|
String hid = Regex.Match(this.topic, "/flex4grid/v1/households/([^/]*)/device/state").Groups[1].Value;
|
||||||
ADataBackend.Instance.Send("/flex4grid/v1/households/" + hid + "/device/actuate", "{\"command\":\""+(v ? "ON" : "OFF") + "\",\"deviceId\":\""+ this.id + "\",\"timestamp\":\"" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") + "\"}");
|
this.backend.Send("/flex4grid/v1/households/" + hid + "/device/actuate", "{\"command\":\""+(v ? "ON" : "OFF") + "\",\"deviceId\":\""+ this.id + "\",\"timestamp\":\"" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") + "\"}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ namespace Dashboard.Sensor {
|
|||||||
class Flex4gridpower : ASensor {
|
class Flex4gridpower : ASensor {
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public Flex4gridpower(Dictionary<String, String> settings, String name) : base(settings, name) {
|
public Flex4gridpower(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||||
this.Datatypes = Types.Float;
|
this.Datatypes = Types.Float;
|
||||||
this.id = settings["id"];
|
this.id = settings["id"];
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ using Dashboard.Connector;
|
|||||||
|
|
||||||
namespace Dashboard.Sensor {
|
namespace Dashboard.Sensor {
|
||||||
class Power : ASensor {
|
class Power : ASensor {
|
||||||
public Power(Dictionary<String, String> settings, String name) : base(settings, name) {
|
public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||||
this.GetBool = true;
|
this.GetBool = true;
|
||||||
this.GetFloat = 0.0f;
|
this.GetFloat = 0.0f;
|
||||||
this.GetInt = 0;
|
this.GetInt = 0;
|
||||||
|
@ -4,7 +4,7 @@ using Dashboard.Connector;
|
|||||||
|
|
||||||
namespace Dashboard.Sensor {
|
namespace Dashboard.Sensor {
|
||||||
class Switch : ASensor {
|
class Switch : ASensor {
|
||||||
public Switch(Dictionary<System.String, System.String> settings, String name) : base(settings, name) {
|
public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||||
this.Datatypes = Types.Bool;
|
this.Datatypes = Types.Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user