Compare commits
52
Commits
1cee75a20b
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1512aaadd8 | ||
|
|
4da5d08d2e | ||
|
|
543a0ead60 | ||
|
|
0a8f8564f5 | ||
|
|
1219212726 | ||
|
|
cfbfd53015 | ||
|
|
eea28bb0fb | ||
|
|
cbf79b8ec9 | ||
|
|
02b04760ac | ||
|
|
1d8a1b93c9 | ||
|
|
a6a0da2b93 | ||
|
|
0f5e7b5c01 | ||
|
|
0c359fa896 | ||
|
|
e325e28bcb | ||
|
|
4a5d427835 | ||
|
|
8a19394d72 | ||
|
|
f3b87d9b38 | ||
|
|
3e791e2543 | ||
|
|
f100cf0965 | ||
|
|
d3cea9a5f5 | ||
|
|
d4fdefb04f | ||
|
|
e582ef551a | ||
|
|
6eca000f44 | ||
|
|
ec4e1b7992 | ||
|
|
d31d0dde2e | ||
|
|
56cc4c39d6 | ||
|
|
07a4464202 | ||
|
|
d53cfc4fb7 | ||
|
|
2cf80e31d4 | ||
|
|
033b187876 | ||
|
|
179e39110e | ||
|
|
4a57a0f2d2 | ||
|
|
2976e32ade | ||
|
|
885df8059c | ||
|
|
8c0a61cf03 | ||
|
|
475fd71652 | ||
|
|
d9c42999ff | ||
|
|
7d826c033a | ||
|
|
eeece2a050 | ||
|
|
2d4d4e28ea | ||
|
|
29897bd0fe | ||
|
|
baf26b291d | ||
|
|
aab157a652 | ||
|
|
fb5cce7c06 | ||
|
|
9f404f69a1 | ||
|
|
be9a8b640b | ||
|
|
cc8ae919fd | ||
|
|
0a638484e1 | ||
|
|
28b7ff4d00 | ||
|
|
b5c31cff84 | ||
|
|
975b96d945 | ||
|
|
178937160b |
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/.vs
|
||||||
|
/Utils/obj
|
||||||
|
/Bot-Utils/obj
|
||||||
|
/Bot-Utils/bin
|
||||||
|
/IoT/.vs
|
||||||
|
/IoT/Connector/Data/Mosquitto/obj
|
||||||
|
/IoT/Connector/Data/Mosquitto/bin
|
||||||
|
/IoT/Connector/Data/Mqtt/.vs
|
||||||
|
/IoT/Connector/Data/Mqtt/bin
|
||||||
|
/IoT/Connector/Data/Mqtt/obj
|
||||||
|
/IoT/Connector/User/Telegram/obj
|
||||||
|
/IoT/Connector/User/Telegram/bin
|
||||||
|
/IoT/Interfaces/bin
|
||||||
|
/IoT/Interfaces/obj
|
||||||
|
/IoT/obj
|
||||||
|
/IoT/bin
|
||||||
|
/packages
|
||||||
|
/Utils/bin
|
||||||
|
/Bot-Utils/.vs
|
||||||
|
/Bot-Utils/Bot-Utils/obj
|
||||||
|
/Bot-Utils/Bot-Utils/bin
|
||||||
|
/Bot-Utils/Bot-Utils/.vs
|
||||||
|
/Utils-IoT/Utils-IoT/bin
|
||||||
|
/Utils-IoT/Utils-IoT/obj
|
||||||
|
/Utils/Utils/bin
|
||||||
|
/Utils/Utils/obj
|
||||||
|
/ConnectorDataMosquitto/ConnectorDataMosquitto/.vs
|
||||||
|
/ConnectorDataMosquitto/ConnectorDataMosquitto/bin
|
||||||
|
/ConnectorDataMosquitto/ConnectorDataMosquitto/obj
|
||||||
|
/ConnectorDataMosquitto/.vs
|
||||||
|
/ConnectorDataMqtt/ConnectorDataMqtt/.vs
|
||||||
|
/ConnectorDataMqtt/ConnectorDataMqtt/bin
|
||||||
|
/ConnectorDataMqtt/ConnectorDataMqtt/obj
|
||||||
|
/ConnectorDataMqtt/.vs
|
||||||
|
/ConnectorUserTelegram/ConnectorUserTelegram/obj
|
||||||
|
/ConnectorUserTelegram/ConnectorUserTelegram/.vs
|
||||||
|
/ConnectorUserTelegram/ConnectorUserTelegram/bin
|
||||||
|
/ConnectorUserTelegram/.vs
|
||||||
|
/Iot-Interfaces/Iot-Interfaces/.vs
|
||||||
|
/Iot-Interfaces/Iot-Interfaces/bin
|
||||||
|
/Iot-Interfaces/Iot-Interfaces/obj
|
||||||
|
/Iot-Interfaces/.vs
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
[submodule "Bot-Utils"]
|
||||||
|
path = Bot-Utils
|
||||||
|
url = http://git.blubbfish.net/vs_utils/Bot-Utils.git
|
||||||
|
[submodule "ConnectorDataMosquitto"]
|
||||||
|
path = ConnectorDataMosquitto
|
||||||
|
url = http://git.blubbfish.net/vs_utils/ConnectorDataMosquitto.git
|
||||||
|
[submodule "ConnectorDataMqtt"]
|
||||||
|
path = ConnectorDataMqtt
|
||||||
|
url = http://git.blubbfish.net/vs_utils/ConnectorDataMqtt.git
|
||||||
|
[submodule "ConnectorUserTelegram"]
|
||||||
|
path = ConnectorUserTelegram
|
||||||
|
url = http://git.blubbfish.net/vs_utils/ConnectorUserTelegram.git
|
||||||
|
[submodule "Iot-Interfaces"]
|
||||||
|
path = Iot-Interfaces
|
||||||
|
url = http://git.blubbfish.net/vs_utils/Iot-Interfaces.git
|
||||||
|
[submodule "Utils"]
|
||||||
|
path = Utils
|
||||||
|
url = http://git.blubbfish.net/vs_utils/Utils.git
|
||||||
|
[submodule "Utils-IoT"]
|
||||||
|
path = Utils-IoT
|
||||||
|
url = http://git.blubbfish.net/vs_utils/Utils-IoT.git
|
||||||
|
[submodule "ConnectorDataGpsd"]
|
||||||
|
path = ConnectorDataGpsd
|
||||||
|
url = https://git.blubbfish.net/vs_utils/ConnectorDataGpsd.git
|
||||||
|
[submodule "ConnectorDbMysql"]
|
||||||
|
path = ConnectorDbMysql
|
||||||
|
url = https://git.blubbfish.net/vs_utils/ConnectorDbMysql.git
|
||||||
|
[submodule "ConnectorStorageInflux"]
|
||||||
|
path = ConnectorStorageInflux
|
||||||
|
url = https://git.blubbfish.net/vs_utils/ConnectorStorageInflux.git
|
||||||
|
[submodule "ConnectorStorageJson"]
|
||||||
|
path = ConnectorStorageJson
|
||||||
|
url = https://git.blubbfish.net/vs_utils/ConnectorStorageJson.git
|
||||||
Submodule
+1
Submodule Bot-Utils added at 21662a367e
@@ -1,82 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>BlubbFish.Utils.IoT.Bots</RootNamespace>
|
|
||||||
<AssemblyName>Bot-Utils</AssemblyName>
|
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<NuGetPackageImportStamp>
|
|
||||||
</NuGetPackageImportStamp>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup>
|
|
||||||
<StartupObject />
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Mono.Posix">
|
|
||||||
<HintPath>..\..\Zway-Bot\packages\Mono.Posix.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Bot.cs" />
|
|
||||||
<Compile Include="Events\CronEvent.cs" />
|
|
||||||
<Compile Include="Events\ModulEventArgs.cs" />
|
|
||||||
<Compile Include="Events\SenmlEvent.cs" />
|
|
||||||
<Compile Include="Events\MqttEvent.cs" />
|
|
||||||
<Compile Include="Events\OvertakerEvent.cs" />
|
|
||||||
<Compile Include="Events\StatusPollingEvent.cs" />
|
|
||||||
<Compile Include="Interfaces\IForceLoad.cs" />
|
|
||||||
<Compile Include="Moduls\AModul.cs" />
|
|
||||||
<Compile Include="Moduls\CronJob.cs" />
|
|
||||||
<Compile Include="Moduls\Mqtt.cs" />
|
|
||||||
<Compile Include="Moduls\Overtaker.cs" />
|
|
||||||
<Compile Include="Moduls\Statuspolling.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="Webserver.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj">
|
|
||||||
<Project>{91a14cd2-2940-4500-8193-56d37edddbaa}</Project>
|
|
||||||
<Name>litjson_4.7.1</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\IoT\Utils-IoT.csproj">
|
|
||||||
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
|
|
||||||
<Name>Utils-IoT</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\Utils\Utils.csproj">
|
|
||||||
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
|
|
||||||
<Name>Utils</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading;
|
|
||||||
using BlubbFish.Utils.IoT.Bots.Moduls;
|
|
||||||
using BlubbFish.Utils.IoT.Bots.Events;
|
|
||||||
using BlubbFish.Utils.IoT.Bots.Interfaces;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots {
|
|
||||||
public abstract class Bot<T> {
|
|
||||||
private Thread sig_thread;
|
|
||||||
private Boolean RunningProcess = true;
|
|
||||||
protected ProgramLogger logger = new ProgramLogger();
|
|
||||||
protected readonly Dictionary<String, AModul<T>> moduls = new Dictionary<String, AModul<T>>();
|
|
||||||
|
|
||||||
protected void WaitForShutdown() {
|
|
||||||
if (Type.GetType("Mono.Runtime") != null) {
|
|
||||||
this.sig_thread = new Thread(delegate () {
|
|
||||||
Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] {
|
|
||||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
|
|
||||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGINT)
|
|
||||||
};
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono attached.");
|
|
||||||
while (true) {
|
|
||||||
Int32 i = Mono.Unix.UnixSignal.WaitAny(signals, -1);
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono INT recieved " + i + ".");
|
|
||||||
this.RunningProcess = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.sig_thread.Start();
|
|
||||||
} else {
|
|
||||||
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Windows attached.");
|
|
||||||
}
|
|
||||||
while (this.RunningProcess) {
|
|
||||||
Thread.Sleep(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
|
|
||||||
e.Cancel = true;
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved.");
|
|
||||||
this.RunningProcess = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ModulDispose() {
|
|
||||||
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
|
||||||
item.Value.Dispose();
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulDispose: Modul entladen: " + item.Key);
|
|
||||||
}
|
|
||||||
if (this.sig_thread != null && this.sig_thread.IsAlive) {
|
|
||||||
this.sig_thread.Abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ModulLoader(String @namespace, Object library) {
|
|
||||||
Assembly asm = Assembly.GetEntryAssembly();
|
|
||||||
foreach (Type item in asm.GetTypes()) {
|
|
||||||
if (item.Namespace == @namespace) {
|
|
||||||
Type t = item;
|
|
||||||
String name = t.Name;
|
|
||||||
try {
|
|
||||||
if (InIReader.ConfigExist(name.ToLower())) {
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulLoader: Load Modul " + name);
|
|
||||||
this.moduls.Add(name, (AModul<T>)t.GetConstructor(new Type[] { typeof(T), typeof(InIReader) }).Invoke(new Object[] { library, InIReader.GetInstance(name.ToLower()) }));
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulLoader: Loaded Modul " + name);
|
|
||||||
} else if (t.HasInterface(typeof(IForceLoad))) {
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulLoader: Load Modul Forced " + name);
|
|
||||||
this.moduls.Add(name, (AModul<T>)t.GetConstructor(new Type[] { typeof(T), typeof(InIReader) }).Invoke(new Object[] { library, null }));
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulLoader: Loaded Modul Forced " + name);
|
|
||||||
}
|
|
||||||
} catch(Exception e) {
|
|
||||||
Helper.WriteError(e.InnerException.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ModulInterconnect() {
|
|
||||||
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
|
||||||
item.Value.Interconnect(this.moduls);
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulInterconnect: Interconnect Module " + item.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ModulEvents() {
|
|
||||||
foreach (KeyValuePair<String, AModul<T>> item in this.moduls) {
|
|
||||||
item.Value.EventLibSetter();
|
|
||||||
item.Value.Update += this.ModulUpdate;
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.ModulEvents: Attach Event " + item.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ModulUpdate(Object sender, ModulEventArgs e) {
|
|
||||||
Console.WriteLine(e.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Events {
|
|
||||||
public class CronEvent : ModulEventArgs {
|
|
||||||
|
|
||||||
public CronEvent() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public CronEvent(String addr, String prop, String value) {
|
|
||||||
this.Address = addr;
|
|
||||||
this.Property = prop;
|
|
||||||
this.Value = value;
|
|
||||||
this.Source = "Cronjob";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Events {
|
|
||||||
public class ModulEventArgs : EventArgs {
|
|
||||||
public ModulEventArgs() {
|
|
||||||
}
|
|
||||||
public ModulEventArgs(String addr, String prop, String val, String src) {
|
|
||||||
this.Address = addr;
|
|
||||||
this.Property = prop;
|
|
||||||
this.Value = val;
|
|
||||||
this.Source = src;
|
|
||||||
}
|
|
||||||
public String Address { get; protected set; }
|
|
||||||
public String Property { get; protected set; }
|
|
||||||
public String Value { get; protected set; }
|
|
||||||
public String Source { get; protected set; }
|
|
||||||
public override String ToString() {
|
|
||||||
return this.Source + ": " + this.Address + " set " + this.Property + " to " + this.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Events {
|
|
||||||
public class MqttEvent : ModulEventArgs {
|
|
||||||
public MqttEvent() {
|
|
||||||
}
|
|
||||||
public MqttEvent(String topic, String text) {
|
|
||||||
this.Address = topic;
|
|
||||||
this.Value = text;
|
|
||||||
this.Source = "MQTT";
|
|
||||||
}
|
|
||||||
public override String ToString() {
|
|
||||||
return this.Source + ": on " + this.Address + " set " + this.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Events {
|
|
||||||
public class OvertakerEvent : ModulEventArgs {
|
|
||||||
|
|
||||||
public OvertakerEvent() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public OvertakerEvent(String addr, String prop, String value) {
|
|
||||||
this.Address = addr;
|
|
||||||
this.Property = prop;
|
|
||||||
this.Value = value;
|
|
||||||
this.Source = "Overtaker";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Events {
|
|
||||||
public class SenmlEvent : ModulEventArgs {
|
|
||||||
public SenmlEvent() {
|
|
||||||
}
|
|
||||||
public SenmlEvent(String topic, String text) {
|
|
||||||
this.Address = topic;
|
|
||||||
this.Value = text;
|
|
||||||
this.Source = "Senml";
|
|
||||||
}
|
|
||||||
public override String ToString() {
|
|
||||||
return this.Source + ": on " + this.Address + " set " + this.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Events {
|
|
||||||
public class StatusPollingEvent : ModulEventArgs {
|
|
||||||
public StatusPollingEvent() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public StatusPollingEvent(String text, String node) {
|
|
||||||
this.Value = text;
|
|
||||||
this.Address = node;
|
|
||||||
this.Source = "POLLING";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override String ToString() {
|
|
||||||
return this.Source + ": " + this.Value + " on " + this.Address;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
namespace BlubbFish.Utils.IoT.Bots.Interfaces {
|
|
||||||
public interface IForceLoad {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using BlubbFish.Utils.IoT.Bots.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|
||||||
public abstract class AModul<T> {
|
|
||||||
protected T library;
|
|
||||||
private readonly InIReader settings;
|
|
||||||
protected Dictionary<String, Dictionary<String, String>> config = new Dictionary<String, Dictionary<String, String>>();
|
|
||||||
|
|
||||||
public Boolean HasConfig { get; private set; }
|
|
||||||
public Boolean ConfigPublic { get; private set; }
|
|
||||||
|
|
||||||
public delegate void ModulEvent(Object sender, ModulEventArgs e);
|
|
||||||
public abstract event ModulEvent Update;
|
|
||||||
|
|
||||||
public AModul(T lib, InIReader settings) {
|
|
||||||
this.HasConfig = false;
|
|
||||||
this.ConfigPublic = false;
|
|
||||||
this.library = lib;
|
|
||||||
this.settings = settings;
|
|
||||||
this.ParseConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseConfig() {
|
|
||||||
if (this.settings != null) {
|
|
||||||
this.HasConfig = true;
|
|
||||||
foreach (String item in this.settings.GetSections(false)) {
|
|
||||||
this.config.Add(item, this.settings.GetSection(item));
|
|
||||||
}
|
|
||||||
if (this.config.ContainsKey("modul")) {
|
|
||||||
this.ConfigPublic = this.config["modul"].ContainsKey("config") && this.config["modul"]["config"].ToLower() == "public";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dictionary<String, Dictionary<String, String>> GetConfig() {
|
|
||||||
if (this.HasConfig && this.ConfigPublic) {
|
|
||||||
Dictionary<String, Dictionary<String, String>> ret = new Dictionary<String, Dictionary<String, String>>(this.config);
|
|
||||||
if (ret.ContainsKey("modul")) {
|
|
||||||
ret.Remove("modul");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return new Dictionary<String, Dictionary<String, String>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Interconnect(Dictionary<String, AModul<T>> moduls) { }
|
|
||||||
|
|
||||||
public virtual void SetInterconnection(String param, Action<Object> hook, Object data) { }
|
|
||||||
|
|
||||||
public abstract void EventLibSetter();
|
|
||||||
|
|
||||||
protected abstract void LibUpadteThread(Object state);
|
|
||||||
|
|
||||||
protected void HandleLibUpdate(Object sender, EventArgs e) {
|
|
||||||
ThreadPool.QueueUserWorkItem(this.LibUpadteThread, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Dispose();
|
|
||||||
|
|
||||||
public void SetConfig(Dictionary<String, Dictionary<String, String>> newconf) {
|
|
||||||
if (this.HasConfig && this.ConfigPublic) {
|
|
||||||
if (newconf.ContainsKey("modul")) {
|
|
||||||
newconf.Remove("modul");
|
|
||||||
}
|
|
||||||
if (this.config.ContainsKey("modul")) {
|
|
||||||
newconf.Add("modul", this.config["modul"]);
|
|
||||||
}
|
|
||||||
this.config = newconf;
|
|
||||||
this.settings.SetSections(this.config);
|
|
||||||
this.UpdateConfig();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void UpdateConfig();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
|
||||||
using BlubbFish.Utils.IoT.Bots.Interfaces;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|
||||||
public abstract class CronJob<T> : AModul<T>, IDisposable, IForceLoad {
|
|
||||||
protected readonly List<Tuple<String, Action<Object>, Object>> internalCron = new List<Tuple<String, Action<Object>, Object>>();
|
|
||||||
protected Thread thread;
|
|
||||||
protected DateTime crontime;
|
|
||||||
|
|
||||||
protected readonly Dictionary<String, String> cron_named = new Dictionary<String, String> {
|
|
||||||
{ "@yearly", "0 0 1 1 *" },
|
|
||||||
{ "@annually", "0 0 1 1 *" },
|
|
||||||
{ "@monthly", "0 0 1 * *" },
|
|
||||||
{ "@weekly", "0 0 * * 0" },
|
|
||||||
{ "@daily", "0 0 * * *" },
|
|
||||||
{ "@hourly", "0 * * * *" }
|
|
||||||
};
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
public CronJob(T lib, InIReader settings) : base(lib, settings) {
|
|
||||||
this.crontime = DateTime.Now;
|
|
||||||
this.thread = new Thread(this.Runner);
|
|
||||||
this.thread.Start();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Cronjobrunner
|
|
||||||
protected void Runner() {
|
|
||||||
Thread.Sleep(DateTime.Now.AddMinutes(1).AddSeconds(DateTime.Now.Second * (-1)).AddMilliseconds(DateTime.Now.Millisecond * (-1)) - DateTime.Now);
|
|
||||||
while (true) {
|
|
||||||
if (this.crontime.Minute != DateTime.Now.Minute) {
|
|
||||||
this.crontime = DateTime.Now;
|
|
||||||
if (this.config.Count != 0) {
|
|
||||||
foreach (KeyValuePair<String, Dictionary<String, String>> item in this.config) {
|
|
||||||
if (item.Value.ContainsKey("cron") && item.Value.ContainsKey("set") && this.ParseCronString(item.Value["cron"])) {
|
|
||||||
this.SetValues(item.Value["set"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (Tuple<String, Action<Object>, Object> item in this.internalCron) {
|
|
||||||
if (this.ParseCronString(item.Item1)) {
|
|
||||||
item.Item2?.Invoke(item.Item3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Thread.Sleep(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void SetValues(String value);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region CronFunctions
|
|
||||||
protected Boolean ParseCronString(String cronstring) {
|
|
||||||
cronstring = cronstring.Trim();
|
|
||||||
if (this.cron_named.ContainsKey(cronstring)) {
|
|
||||||
cronstring = this.cron_named[cronstring];
|
|
||||||
}
|
|
||||||
String[] value = cronstring.Split(' ');
|
|
||||||
if (value.Length != 5) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!this.CheckDateStr(this.crontime.ToString("mm"), value[0], "0-59")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!this.CheckDateStr(this.crontime.ToString("HH"), value[1], "0-23")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!this.CheckDateStr(this.crontime.ToString("MM"), value[3], "1-12")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (value[2] != "*" && value[4] != "*") {
|
|
||||||
if (!this.CheckDateStr(this.crontime.ToString("dd"), value[2], "1-31") && !this.CheckDateStr(((Int32)this.crontime.DayOfWeek).ToString(), value[4], "0-7")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!this.CheckDateStr(this.crontime.ToString("dd"), value[2], "1-31")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!this.CheckDateStr(((Int32)this.crontime.DayOfWeek).ToString(), value[4], "0-7")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
protected Boolean CheckDateStr(String date, String cron, String limit) {
|
|
||||||
cron = cron.ToLower();
|
|
||||||
for (Int32 i = 0; i <= 6; i++) {
|
|
||||||
cron = cron.Replace(DateTime.Parse("2015-01-" + (4 + i) + "T00:00:00").ToString("ddd", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
|
||||||
cron = cron.Replace(DateTime.Parse("2015-01-" + (4 + i) + "T00:00:00").ToString("dddd", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
|
||||||
}
|
|
||||||
for (Int32 i = 1; i <= 12; i++) {
|
|
||||||
cron = cron.Replace(DateTime.Parse("2015-" + i + "-01T00:00:00").ToString("MMM", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
|
||||||
cron = cron.Replace(DateTime.Parse("2015-" + i + "-01T00:00:00").ToString("MMMM", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
|
||||||
}
|
|
||||||
if (cron.Contains("*")) {
|
|
||||||
cron = cron.Replace("*", limit);
|
|
||||||
}
|
|
||||||
if (cron.Contains("-")) {
|
|
||||||
MatchCollection m = new Regex("(\\d+)-(\\d+)").Matches(cron);
|
|
||||||
foreach (Match p in m) {
|
|
||||||
List<String> s = new List<String>();
|
|
||||||
for (Int32 i = Math.Min(Int32.Parse(p.Groups[1].Value), Int32.Parse(p.Groups[2].Value)); i <= Math.Max(Int32.Parse(p.Groups[1].Value), Int32.Parse(p.Groups[2].Value)); i++) {
|
|
||||||
s.Add(i.ToString());
|
|
||||||
}
|
|
||||||
cron = cron.Replace(p.Groups[0].Value, String.Join(",", s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Int32 match = 0;
|
|
||||||
if (cron.Contains("/")) {
|
|
||||||
Match m = new Regex("/(\\d+)").Match(cron);
|
|
||||||
cron = cron.Replace(m.Groups[0].Value, "");
|
|
||||||
match = Int32.Parse(m.Groups[1].Value);
|
|
||||||
}
|
|
||||||
Dictionary<Int32, String> ret = new Dictionary<Int32, String>();
|
|
||||||
if (!cron.Contains(",")) {
|
|
||||||
ret.Add(Int32.Parse(cron), "");
|
|
||||||
} else {
|
|
||||||
foreach (String item in cron.Split(',')) {
|
|
||||||
if (!ret.ContainsKey(Int32.Parse(item))) {
|
|
||||||
ret.Add(Int32.Parse(item), "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (match != 0) {
|
|
||||||
Dictionary<Int32, String> r = new Dictionary<Int32, String>();
|
|
||||||
foreach (KeyValuePair<Int32, String> item in ret) {
|
|
||||||
if (item.Key % match == 0) {
|
|
||||||
r.Add(item.Key, "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret = r;
|
|
||||||
}
|
|
||||||
return ret.ContainsKey(Int32.Parse(date));
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region AModul
|
|
||||||
public override void SetInterconnection(String cron, Action<Object> hook, Object data) {
|
|
||||||
this.internalCron.Add(new Tuple<String, Action<Object>, Object>(cron, hook, data));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void UpdateConfig() { }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
private Boolean disposedValue = false;
|
|
||||||
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
|
||||||
if (!this.disposedValue) {
|
|
||||||
if (disposing) {
|
|
||||||
if (this.thread != null) {
|
|
||||||
this.thread.Abort();
|
|
||||||
while (this.thread.ThreadState == ThreadState.Running) { Thread.Sleep(100); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.thread = null;
|
|
||||||
this.disposedValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
|
||||||
using BlubbFish.Utils.IoT.Bots.Events;
|
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
using LitJson;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|
||||||
public abstract class Mqtt<T> : AModul<T>, IDisposable {
|
|
||||||
protected readonly Thread connectionWatcher;
|
|
||||||
protected ABackend mqtt;
|
|
||||||
protected Dictionary<String, AModul<T>> modules;
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
public Mqtt(T lib, InIReader settings) : base(lib, settings) {
|
|
||||||
if (this.config.ContainsKey("settings")) {
|
|
||||||
this.connectionWatcher = new Thread(this.ConnectionWatcherRunner);
|
|
||||||
this.connectionWatcher.Start();
|
|
||||||
} else {
|
|
||||||
throw new ArgumentException("Setting section [settings] is missing!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Watcher
|
|
||||||
protected void ConnectionWatcherRunner() {
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
if (this.mqtt == null || !this.mqtt.IsConnected) {
|
|
||||||
this.Reconnect();
|
|
||||||
}
|
|
||||||
Thread.Sleep(10000);
|
|
||||||
} catch (Exception) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Reconnect() {
|
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Moduls.Mqtt.Reconnect()");
|
|
||||||
this.Disconnect();
|
|
||||||
this.Connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void Connect();
|
|
||||||
|
|
||||||
protected abstract void Disconnect();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region AModul
|
|
||||||
public override void Interconnect(Dictionary<String, AModul<T>> moduls) {
|
|
||||||
this.modules = moduls;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void UpdateConfig() {
|
|
||||||
this.Reconnect();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
protected Tuple<Boolean, MqttEvent> ChangeConfig(BackendEvent e, String topic) {
|
|
||||||
if (e.From.ToString().StartsWith(topic) && (e.From.ToString().EndsWith("/set") || e.From.ToString().EndsWith("/get"))) {
|
|
||||||
Match m = new Regex("^"+ topic + "(\\w+)/[gs]et$|").Match(e.From.ToString());
|
|
||||||
if (!m.Groups[1].Success) {
|
|
||||||
return new Tuple<Boolean, MqttEvent>(false, null);
|
|
||||||
}
|
|
||||||
AModul<T> modul = null;
|
|
||||||
foreach (KeyValuePair<String, AModul<T>> item in this.modules) {
|
|
||||||
if (item.Key.ToLower() == m.Groups[1].Value) {
|
|
||||||
modul = item.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (modul == null) {
|
|
||||||
return new Tuple<Boolean, MqttEvent>(false, null);
|
|
||||||
}
|
|
||||||
if (e.From.ToString().EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) {
|
|
||||||
String t = topic + m.Groups[1].Value;
|
|
||||||
String d = JsonMapper.ToJson(modul.GetConfig()).ToString();
|
|
||||||
((ADataBackend)this.mqtt).Send(t, d);
|
|
||||||
return new Tuple<Boolean, MqttEvent>(true, new MqttEvent(t, d));
|
|
||||||
} else if (e.From.ToString().EndsWith("/set") && modul.HasConfig && modul.ConfigPublic) {
|
|
||||||
try {
|
|
||||||
JsonData a = JsonMapper.ToObject(e.Message);
|
|
||||||
Dictionary<String, Dictionary<String, String>> newconf = new Dictionary<String, Dictionary<String, String>>();
|
|
||||||
foreach (String section in a.Keys) {
|
|
||||||
Dictionary<String, String> sectiondata = new Dictionary<String, String>();
|
|
||||||
foreach (String item in a[section].Keys) {
|
|
||||||
sectiondata.Add(item, a[section][item].ToString());
|
|
||||||
}
|
|
||||||
newconf.Add(section, sectiondata);
|
|
||||||
}
|
|
||||||
modul.SetConfig(newconf);
|
|
||||||
return new Tuple<Boolean, MqttEvent>(true, new MqttEvent("New Config", "Write"));
|
|
||||||
} catch (Exception) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Tuple<Boolean, MqttEvent>(false, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
private Boolean disposedValue = false;
|
|
||||||
|
|
||||||
protected void Dispose(Boolean disposing) {
|
|
||||||
if (!this.disposedValue) {
|
|
||||||
if (disposing) {
|
|
||||||
this.connectionWatcher.Abort();
|
|
||||||
while (this.connectionWatcher.ThreadState == ThreadState.Running) { Thread.Sleep(10); }
|
|
||||||
this.Disconnect();
|
|
||||||
}
|
|
||||||
this.disposedValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|
||||||
public abstract class Overtaker<T> : AModul<T>, IDisposable {
|
|
||||||
protected readonly Dictionary<String, Dictionary<String, String>> events = new Dictionary<String, Dictionary<String, String>>();
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
public Overtaker(T lib, InIReader settings) : base(lib, settings) {
|
|
||||||
this.ParseIni();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Overtakerfunctions
|
|
||||||
protected void ParseIni() {
|
|
||||||
this.RemoveLibraryUpdateHooks();
|
|
||||||
foreach (KeyValuePair<String, Dictionary<String, String>> item in this.config) {
|
|
||||||
if (item.Value.ContainsKey("from")) {
|
|
||||||
String from = item.Value["from"];
|
|
||||||
String[] source = from.Split(':');
|
|
||||||
this.events.Add(source[0], item.Value);
|
|
||||||
this.AddLibraryUpdateHook(source[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void SetValues(Object sender, String name, Dictionary<String, String> dictionary) {
|
|
||||||
String from = dictionary["from"];
|
|
||||||
String[] source = from.Split(':');
|
|
||||||
if (source.Length != 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String source_value;
|
|
||||||
if (sender.HasProperty(source[1])) {
|
|
||||||
source_value = sender.GetProperty(source[1]).ToString();
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (dictionary.ContainsKey("convert")) {
|
|
||||||
foreach (String tuple in dictionary["convert"].Split(';')) {
|
|
||||||
String[] item = tuple.Split('-');
|
|
||||||
if (source_value == item[0]) {
|
|
||||||
source_value = item[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dictionary.ContainsKey("to")) {
|
|
||||||
foreach (String to in dictionary["to"].Split(';')) {
|
|
||||||
String[] target = to.Split(':');
|
|
||||||
if (target.Length == 2) {
|
|
||||||
this.SetValueHook(target[0], target[1], source_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void AddLibraryUpdateHook(String id);
|
|
||||||
|
|
||||||
protected abstract void RemoveLibraryUpdateHooks();
|
|
||||||
|
|
||||||
protected abstract void SetValueHook(String id, String prop, String value);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region AModul
|
|
||||||
public override void Interconnect(Dictionary<String, AModul<T>> moduls) { }
|
|
||||||
protected override void UpdateConfig() {
|
|
||||||
this.ParseIni();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
private Boolean disposedValue = false;
|
|
||||||
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
|
||||||
if (!this.disposedValue) {
|
|
||||||
if (disposing) {
|
|
||||||
}
|
|
||||||
this.disposedValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using BlubbFish.Utils.IoT.Bots.Interfaces;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots.Moduls {
|
|
||||||
public abstract class Statuspolling<T> : AModul<T>, IDisposable, IForceLoad {
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
public Statuspolling(T lib, InIReader settings) : base(lib, settings) { }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Statuspollingfunctions
|
|
||||||
protected abstract void PollSpecific(Object obj);
|
|
||||||
|
|
||||||
protected abstract void PollAll(Object obj);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region AModul
|
|
||||||
public override void Interconnect(Dictionary<String, AModul<T>> moduls) {
|
|
||||||
foreach (KeyValuePair<String, AModul<T>> item in moduls) {
|
|
||||||
if (item.Value is CronJob<T>) {
|
|
||||||
item.Value.SetInterconnection("0 0 * * *", new Action<Object>(this.PollAll), null);
|
|
||||||
if (this.config.Count != 0) {
|
|
||||||
foreach (KeyValuePair<String, Dictionary<String, String>> section in this.config) {
|
|
||||||
if (section.Value.ContainsKey("cron") && section.Value.ContainsKey("devices")) {
|
|
||||||
item.Value.SetInterconnection(section.Value["cron"], new Action<Object>(this.PollSpecific), section.Value["devices"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected override void UpdateConfig() { }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
private Boolean disposedValue = false;
|
|
||||||
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
|
||||||
if (!this.disposedValue) {
|
|
||||||
if (disposing) {
|
|
||||||
}
|
|
||||||
this.disposedValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
|
||||||
// die einer Assembly zugeordnet sind.
|
|
||||||
[assembly: AssemblyTitle("Bot-Utils")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("Bot-Utils")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2018 - 02.10.2018")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
|
||||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
|
||||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
|
||||||
[assembly: Guid("bb7bfcb5-3db0-49e1-802a-3ce3eecc59f9")]
|
|
||||||
|
|
||||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
|
||||||
//
|
|
||||||
// Hauptversion
|
|
||||||
// Nebenversion
|
|
||||||
// Buildnummer
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
|
||||||
// indem Sie "*" wie unten gezeigt eingeben:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.1.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.1.0")]
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 1.1.0 Remove Helper from Bot-Utils
|
|
||||||
*/
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots
|
|
||||||
{
|
|
||||||
public abstract class Webserver
|
|
||||||
{
|
|
||||||
protected Dictionary<String, String> config;
|
|
||||||
protected InIReader requests;
|
|
||||||
protected HttpListener httplistener;
|
|
||||||
|
|
||||||
public Webserver(ABackend backend, Dictionary<String, String> settings, InIReader requests) {
|
|
||||||
this.config = settings;
|
|
||||||
this.requests = requests;
|
|
||||||
backend.MessageIncomming += this.Backend_MessageIncomming;
|
|
||||||
this.httplistener = new HttpListener();
|
|
||||||
this.httplistener.Prefixes.Add(this.config["prefix"]);
|
|
||||||
this.httplistener.Start();
|
|
||||||
ThreadPool.QueueUserWorkItem((o) => {
|
|
||||||
Console.WriteLine("Webserver is Running...");
|
|
||||||
try {
|
|
||||||
while (this.httplistener.IsListening) {
|
|
||||||
ThreadPool.QueueUserWorkItem((state) => {
|
|
||||||
HttpListenerContext httplistenercontext = state as HttpListenerContext;
|
|
||||||
try {
|
|
||||||
this.SendResponse(httplistenercontext);
|
|
||||||
} catch { } finally {
|
|
||||||
httplistenercontext.Response.OutputStream.Close();
|
|
||||||
}
|
|
||||||
}, this.httplistener.GetContext());
|
|
||||||
}
|
|
||||||
} catch { };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void SendResponse(HttpListenerContext cont) {
|
|
||||||
String restr = cont.Request.Url.PathAndQuery;
|
|
||||||
if (restr.StartsWith("/")) {
|
|
||||||
if(restr.IndexOf("?") != -1) {
|
|
||||||
restr = restr.Substring(1, restr.IndexOf("?")-1);
|
|
||||||
} else {
|
|
||||||
restr = restr.Substring(1);
|
|
||||||
}
|
|
||||||
if(restr == "") {
|
|
||||||
restr = "index.html";
|
|
||||||
}
|
|
||||||
String end = restr.IndexOf('.') != -1 ? restr.Substring(restr.IndexOf('.')+1) : "";
|
|
||||||
if (File.Exists("resources/"+ restr)) {
|
|
||||||
try {
|
|
||||||
if (end == "png" || end == ".jpg" || end == ".jpeg" || end == ".ico") {
|
|
||||||
Byte[] output = File.ReadAllBytes("resources/" + restr);
|
|
||||||
cont.Response.OutputStream.Write(output, 0, output.Length);
|
|
||||||
cont.Response.ContentType = "image/"+end;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
String file = File.ReadAllText("resources/" + restr);
|
|
||||||
if (this.requests.GetSections(false).Contains(restr)) {
|
|
||||||
Dictionary<String, String> vars = this.requests.GetSection(restr);
|
|
||||||
foreach (KeyValuePair<String, String> item in vars) {
|
|
||||||
file = file.Replace("{%" + item.Key.ToUpper() + "%}", item.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file = file.Replace("{%REQUEST_URL_HOST%}", cont.Request.Url.Host);
|
|
||||||
Byte[] buf = Encoding.UTF8.GetBytes(file);
|
|
||||||
cont.Response.ContentLength64 = buf.Length;
|
|
||||||
cont.Response.OutputStream.Write(buf, 0, buf.Length);
|
|
||||||
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch(Exception e) {
|
|
||||||
Helper.WriteError("500 - " + e.Message);
|
|
||||||
cont.Response.StatusCode = 500;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Helper.WriteError("404 - " + cont.Request.Url.PathAndQuery + " not found!");
|
|
||||||
cont.Response.StatusCode = 404;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
this.httplistener.Stop();
|
|
||||||
this.httplistener.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void Backend_MessageIncomming(Object sender, BackendEvent e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
Submodule
+1
Submodule ConnectorDataGpsd added at 4dff73eb68
Submodule
+1
Submodule ConnectorDataMosquitto added at c29ea883a4
Submodule
+1
Submodule ConnectorDataMqtt added at 5357b57489
Submodule
+1
Submodule ConnectorDbMysql added at dde495e2ff
Submodule
+1
Submodule ConnectorStorageInflux added at a890cbae9b
Submodule
+1
Submodule ConnectorStorageJson added at da0d3614a3
Submodule
+1
Submodule ConnectorUserTelegram added at 75f53ca419
@@ -1,55 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio 15
|
|
||||||
VisualStudioVersion = 15.0.27004.2010
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMosquitto", "IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj", "{39235FAD-BA9D-4B51-82FC-6969967BEAE9}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorUserTelegram", "IoT\Connector\User\Telegram\ConnectorUserTelegram.csproj", "{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt", "..\Librarys\mqtt\M2Mqtt\M2Mqtt.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {844D8F60-6DE1-4C48-976D-F71450E9707B}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Connector {
|
|
||||||
public abstract class ABackend {
|
|
||||||
public enum BackendType {
|
|
||||||
Data,
|
|
||||||
User
|
|
||||||
}
|
|
||||||
public event BackendMessage MessageIncomming;
|
|
||||||
public event BackendMessage MessageSending;
|
|
||||||
public delegate void BackendMessage(Object sender, BackendEvent e);
|
|
||||||
|
|
||||||
protected Dictionary<String, String> settings;
|
|
||||||
|
|
||||||
public abstract Boolean IsConnected { get; }
|
|
||||||
|
|
||||||
public ABackend(Dictionary<String, String> settings) {
|
|
||||||
this.settings = settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ABackend GetInstance(Dictionary<String, String> settings, BackendType ty) {
|
|
||||||
if (settings.Count == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String object_sensor = "BlubbFish.Utils.IoT.Connector." + ty.ToString() + "." + settings["type"].ToUpperLower() + ", " + "Connector" + ty.ToString() + settings["type"].ToUpperLower();
|
|
||||||
Type t = null;
|
|
||||||
try {
|
|
||||||
t = Type.GetType(object_sensor, true);
|
|
||||||
} catch (TypeLoadException) {
|
|
||||||
Console.Error.WriteLine("Configuration: " + settings["type"] + " is not a " + ty.ToString() + "Backend");
|
|
||||||
return null;
|
|
||||||
} catch (System.IO.FileNotFoundException) {
|
|
||||||
Console.Error.WriteLine("Driver " + object_sensor + " could not load!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (ABackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void NotifyClientIncomming(BackendEvent value) {
|
|
||||||
this.MessageIncomming?.Invoke(this, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void NotifyClientSending(BackendEvent value) {
|
|
||||||
this.MessageSending?.Invoke(this, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Connector {
|
|
||||||
public abstract class ADataBackend : ABackend {
|
|
||||||
public ADataBackend(Dictionary<String, String> settings) : base(settings) { }
|
|
||||||
public abstract void Send(String topic, String data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Connector {
|
|
||||||
public abstract class AUserBackend : ABackend {
|
|
||||||
public AUserBackend(Dictionary<String, String> settings) : base(settings) {}
|
|
||||||
public abstract void Send(String message);
|
|
||||||
public abstract void Send(String message, String[] buttons);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{39235FAD-BA9D-4B51-82FC-6969967BEAE9}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace>
|
|
||||||
<AssemblyName>ConnectorDataMosquitto</AssemblyName>
|
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<TargetFrameworkProfile />
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Mosquitto.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\..\Utils-IoT.csproj">
|
|
||||||
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
|
|
||||||
<Name>Utils-IoT</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Connector.Data {
|
|
||||||
public class Mosquitto : ADataBackend, IDisposable {
|
|
||||||
private Process p;
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
public override event MqttMessage MessageIncomming;
|
|
||||||
public override event MqttMessage MessageSending;
|
|
||||||
|
|
||||||
public Mosquitto(Dictionary<String, String> mqtt_settings) {
|
|
||||||
this.settings = mqtt_settings;
|
|
||||||
//mosquitto_sub --cafile ca.pem --cert cert.pem --key cert.key -h swb.broker.flex4grid.eu -p 8883 -t "#" -v -d
|
|
||||||
this.message = "";
|
|
||||||
this.p = new Process();
|
|
||||||
this.p.StartInfo.FileName = "mosquitto_sub";
|
|
||||||
String topic = "#";
|
|
||||||
String args = "-h " + this.settings["server"]+" ";
|
|
||||||
if(this.settings.ContainsKey("port")) {
|
|
||||||
args += "-p "+ this.settings["port"]+" ";
|
|
||||||
}
|
|
||||||
if (this.settings.ContainsKey("cafile")) {
|
|
||||||
args += "--cafile " + this.settings["cafile"] + " ";
|
|
||||||
}
|
|
||||||
if (this.settings.ContainsKey("cert")) {
|
|
||||||
args += "--cert " + this.settings["cert"] + " ";
|
|
||||||
}
|
|
||||||
if (this.settings.ContainsKey("key")) {
|
|
||||||
args += "--key " + this.settings["key"] + " ";
|
|
||||||
}
|
|
||||||
if(this.settings.ContainsKey("topic")) {
|
|
||||||
topic = this.settings["topic"];
|
|
||||||
}
|
|
||||||
this.p.StartInfo.Arguments = args+"-t \""+ topic + "\" -v -d";
|
|
||||||
this.p.StartInfo.CreateNoWindow = true;
|
|
||||||
this.p.StartInfo.UseShellExecute = false;
|
|
||||||
this.p.StartInfo.RedirectStandardOutput = true;
|
|
||||||
this.p.StartInfo.RedirectStandardError = true;
|
|
||||||
this.p.OutputDataReceived += this.P_OutputDataReceived;
|
|
||||||
this.p.ErrorDataReceived += this.P_ErrorDataReceived;
|
|
||||||
this.p.Start();
|
|
||||||
this.p.BeginOutputReadLine();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Send(String topic, String data) {
|
|
||||||
Process send = new Process();
|
|
||||||
send.StartInfo.FileName = "mosquitto_pub";
|
|
||||||
String args = "-h " + this.settings["server"] + " ";
|
|
||||||
if (this.settings.ContainsKey("port")) {
|
|
||||||
args += "-p " + this.settings["port"] + " ";
|
|
||||||
}
|
|
||||||
if (this.settings.ContainsKey("cafile")) {
|
|
||||||
args += "--cafile " + this.settings["cafile"] + " ";
|
|
||||||
}
|
|
||||||
if (this.settings.ContainsKey("cert")) {
|
|
||||||
args += "--cert " + this.settings["cert"] + " ";
|
|
||||||
}
|
|
||||||
if (this.settings.ContainsKey("key")) {
|
|
||||||
args += "--key " + this.settings["key"] + " ";
|
|
||||||
}
|
|
||||||
send.StartInfo.Arguments = args + "-m \""+data.Replace("\"","\\\"")+"\" -t \""+topic+"\" -d";
|
|
||||||
send.StartInfo.CreateNoWindow = true;
|
|
||||||
send.StartInfo.UseShellExecute = false;
|
|
||||||
send.StartInfo.RedirectStandardOutput = true;
|
|
||||||
send.StartInfo.RedirectStandardError = true;
|
|
||||||
send.Start();
|
|
||||||
send.WaitForExit();
|
|
||||||
MessageSending?.Invoke(this, new MqttEventArgs(data, topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void P_ErrorDataReceived(Object sender, DataReceivedEventArgs e) {
|
|
||||||
if (e.Data != null) {
|
|
||||||
throw new NotImplementedException(e.Data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void P_OutputDataReceived(Object sender, DataReceivedEventArgs e) {
|
|
||||||
if (e.Data != null) {
|
|
||||||
if (e.Data.StartsWith("Client mosqsub")) {
|
|
||||||
if (this.message != "" && this.message.IndexOf(" received PUBLISH ") > 0) {
|
|
||||||
MatchCollection matches = (new Regex("^Client mosqsub[\\|/].*received PUBLISH \\(.*,.*,.*,.*, '(.*)'.*\\)\\)\n[^ ]* (.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline)).Matches(this.message);
|
|
||||||
String topic = matches[0].Groups[1].Value;
|
|
||||||
String message = matches[0].Groups[2].Value.Trim();
|
|
||||||
this.MessageIncomming?.Invoke(this, new MqttEventArgs(message, topic));
|
|
||||||
}
|
|
||||||
this.message = e.Data + "\n";
|
|
||||||
} else {
|
|
||||||
this.message += e.Data + "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
private Boolean disposedValue = false; // Dient zur Erkennung redundanter Aufrufe.
|
|
||||||
private readonly Dictionary<String, String> settings;
|
|
||||||
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
|
||||||
if (!this.disposedValue) {
|
|
||||||
if (disposing) {
|
|
||||||
this.p.CancelOutputRead();
|
|
||||||
if (!this.p.HasExited) {
|
|
||||||
this.p.Kill();
|
|
||||||
}
|
|
||||||
this.p.Close();
|
|
||||||
}
|
|
||||||
this.p = null;
|
|
||||||
this.disposedValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~Mosquitto() {
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
|
||||||
// die einer Assembly zugeordnet sind.
|
|
||||||
[assembly: AssemblyTitle("ConnectorDataMosquitto")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("ConnectorDataMosquitto")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
|
||||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
|
||||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
|
||||||
[assembly: Guid("39235fad-ba9d-4b51-82fc-6969967beae9")]
|
|
||||||
|
|
||||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
|
||||||
//
|
|
||||||
// Hauptversion
|
|
||||||
// Nebenversion
|
|
||||||
// Buildnummer
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
|
||||||
// indem Sie "*" wie unten gezeigt eingeben:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,51 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace>
|
|
||||||
<AssemblyName>ConnectorDataMqtt</AssemblyName>
|
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<TargetFrameworkProfile />
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Mqtt.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\..\..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj">
|
|
||||||
<Project>{a11aef5a-b246-4fe8-8330-06db73cc8074}</Project>
|
|
||||||
<Name>M2Mqtt_4.7.1</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\..\..\Utils-IoT.csproj">
|
|
||||||
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
|
|
||||||
<Name>Utils-IoT</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
using uPLibrary.Networking.M2Mqtt;
|
|
||||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Connector.Data {
|
|
||||||
public class Mqtt : ADataBackend, IDisposable {
|
|
||||||
private MqttClient client;
|
|
||||||
|
|
||||||
public Mqtt(Dictionary<String, String> settings) : base(settings) {
|
|
||||||
Int32 port = 1883;
|
|
||||||
if(this.settings.ContainsKey("port")) {
|
|
||||||
port = Int32.Parse(this.settings["port"]);
|
|
||||||
}
|
|
||||||
this.client = new MqttClient(this.settings["server"], port, false, null, null, MqttSslProtocols.None);
|
|
||||||
Connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Connect() {
|
|
||||||
this.client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived;
|
|
||||||
if (this.settings.ContainsKey("user") && this.settings.ContainsKey("pass")) {
|
|
||||||
this.client.Connect(Guid.NewGuid().ToString(), this.settings["user"], this.settings["pass"]);
|
|
||||||
} else {
|
|
||||||
this.client.Connect(Guid.NewGuid().ToString());
|
|
||||||
}
|
|
||||||
if (this.settings.ContainsKey("topic")) {
|
|
||||||
Int32 l = this.settings["topic"].Split(';').Length;
|
|
||||||
Byte[] qos = new Byte[l];
|
|
||||||
for (Int32 i = 0; i < qos.Length; i++) {
|
|
||||||
qos[i] = MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE;
|
|
||||||
}
|
|
||||||
this.client.Subscribe(this.settings["topic"].Split(';'), qos);
|
|
||||||
} else {
|
|
||||||
this.client.Subscribe(new String[] { "#" }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Client_MqttMsgPublishReceived(Object sender, MqttMsgPublishEventArgs e) {
|
|
||||||
this.NotifyClientIncomming(new DataEvent(Encoding.UTF8.GetString(e.Message), e.Topic, DateTime.Now));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Send(String topic, String data) {
|
|
||||||
this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
|
|
||||||
this.NotifyClientSending(new DataEvent(data, topic, DateTime.Now));
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
private Boolean disposedValue = false;
|
|
||||||
|
|
||||||
public override Boolean IsConnected {
|
|
||||||
get {
|
|
||||||
if(this.client != null) {
|
|
||||||
return this.client.IsConnected;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
|
||||||
if(!this.disposedValue) {
|
|
||||||
if(disposing) {try {
|
|
||||||
this.client.MqttMsgPublishReceived -= this.Client_MqttMsgPublishReceived;
|
|
||||||
this.client.Unsubscribe(new String[] { "#" });
|
|
||||||
this.client.Disconnect();
|
|
||||||
} catch (Exception) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.client = null;
|
|
||||||
|
|
||||||
this.disposedValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
|
||||||
// die einer Assembly zugeordnet sind.
|
|
||||||
[assembly: AssemblyTitle("ConnectorDataMqtt")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("ConnectorDataMqtt")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
|
||||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
|
||||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
|
||||||
[assembly: Guid("ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2")]
|
|
||||||
|
|
||||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
|
||||||
//
|
|
||||||
// Hauptversion
|
|
||||||
// Nebenversion
|
|
||||||
// Buildnummer
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
|
||||||
// indem Sie "*" wie unten gezeigt eingeben:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
Binary file not shown.
@@ -1,26 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Connector {
|
|
||||||
public class UserMessageEventArgs : EventArgs {
|
|
||||||
public UserMessageEventArgs() : base() { }
|
|
||||||
public UserMessageEventArgs(String message, Int64 UserId, DateTime date) {
|
|
||||||
this.UserId = UserId;
|
|
||||||
this.Message = message;
|
|
||||||
this.Date = date;
|
|
||||||
}
|
|
||||||
public Int64 UserId { get; private set; }
|
|
||||||
public String Message { get; private set; }
|
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
}
|
|
||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>BlubbFish.Utils.IoT.Connector.User</RootNamespace>
|
|
||||||
<AssemblyName>ConnectorUserTelegram</AssemblyName>
|
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<TargetFrameworkProfile />
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.ComponentModel.Composition" />
|
|
||||||
<Reference Include="System.Console, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Globalization.Calendars, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.IO.Compression.FileSystem" />
|
|
||||||
<Reference Include="System.IO.Compression.ZipFile, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Numerics" />
|
|
||||||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
<Reference Include="System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Telegram.Bot, Version=13.2.1.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\..\..\packages\Telegram.Bot.13.2.1\lib\netstandard1.1\Telegram.Bot.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="Telegram.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\..\Utils-IoT.csproj">
|
|
||||||
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
|
|
||||||
<Name>Utils-IoT</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="app.config" />
|
|
||||||
<None Include="packages.config" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
|
||||||
// die einer Assembly zugeordnet sind.
|
|
||||||
[assembly: AssemblyTitle("ConnectorUserTelegram")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("ConnectorUserTelegram")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
|
||||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
|
||||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
|
||||||
[assembly: Guid("e66a57dd-858a-40e4-8a2f-bea5129c31f7")]
|
|
||||||
|
|
||||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
|
||||||
//
|
|
||||||
// Hauptversion
|
|
||||||
// Nebenversion
|
|
||||||
// Buildnummer
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
|
||||||
// indem Sie "*" wie unten gezeigt eingeben:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Args;
|
|
||||||
using Telegram.Bot.Exceptions;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegram.Bot.Types.Enums;
|
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Connector.User {
|
|
||||||
public class Telegram : AUserBackend {
|
|
||||||
private TelegramBotClient bot;
|
|
||||||
private ChatId chat;
|
|
||||||
|
|
||||||
public override event TelegramMessage MessageIncomming;
|
|
||||||
public override event TelegramMessage MessageSending;
|
|
||||||
|
|
||||||
public Telegram(Dictionary<String, String> settings) : base(settings) {
|
|
||||||
this.bot = new TelegramBotClient(settings["telegram-key"]);
|
|
||||||
this.bot.OnMessage += this.Bot_OnMessage;
|
|
||||||
this.Connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Bot_OnMessage(Object sender, MessageEventArgs e) {
|
|
||||||
this.MessageIncomming?.Invoke(this, new UserMessageEventArgs(e.Message.Text, e.Message.Chat.Id, e.Message.Date));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Connect() {
|
|
||||||
this.bot.StartReceiving();
|
|
||||||
this.chat = new ChatId(this.settings["chatid"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async override void Send(String message) {
|
|
||||||
try {
|
|
||||||
Message x = await this.bot.SendTextMessageAsync(this.chat, message, ParseMode.Default, false, false, 0, new ReplyKeyboardRemove());
|
|
||||||
this.MessageSending?.Invoke(this, new UserMessageEventArgs(x.Text, x.Chat.Id, x.Date));
|
|
||||||
} catch(ApiRequestException e) {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
|
||||||
Console.WriteLine(e.Message+" "+e.ErrorCode+" "+e.Parameters);
|
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose() {
|
|
||||||
this.bot.StopReceiving();
|
|
||||||
this.bot = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async override void Send(String message, String[] buttons) {
|
|
||||||
try {
|
|
||||||
KeyboardButton[][] button = new KeyboardButton[(Int32)Math.Ceiling(((Double)buttons.Length)/2)][];
|
|
||||||
for(Int32 i = 0; i < buttons.Length; i++) {
|
|
||||||
Int32 j = (Int32)Math.Floor(((Double)i) / 2);
|
|
||||||
if (i % 2 == 0) {
|
|
||||||
button[j] = new KeyboardButton[(j == button.Length - 1) ? ((buttons.Length % 2 == 0) ? 2 : buttons.Length % 2) : 2];
|
|
||||||
}
|
|
||||||
button[j][i % 2] = new KeyboardButton(buttons[i]);
|
|
||||||
}
|
|
||||||
Message x = await this.bot.SendTextMessageAsync(this.chat, message, ParseMode.Default, false, false, 0, new ReplyKeyboardMarkup(button,true,true));
|
|
||||||
this.MessageSending?.Invoke(this, new UserMessageEventArgs(x.Text, x.Chat.Id, x.Date));
|
|
||||||
} catch (ApiRequestException e) {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
|
||||||
Console.WriteLine(e.Message + " " + e.ErrorCode + " " + e.Parameters);
|
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<runtime>
|
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0"/>
|
|
||||||
</dependentAssembly>
|
|
||||||
</assemblyBinding>
|
|
||||||
</runtime>
|
|
||||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/></startup></configuration>
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,51 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" />
|
|
||||||
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="NETStandard.Library" version="1.6.1" targetFramework="net461" />
|
|
||||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
|
|
||||||
<package id="System.AppContext" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Collections" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Console" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Diagnostics.DiagnosticSource" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Globalization" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.IO" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.IO.Compression" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.IO.FileSystem" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Linq" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Net.Http" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Net.Primitives" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Net.Sockets" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.ObjectModel" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Reflection" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Runtime" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Runtime.Handles" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
|
|
||||||
<package id="System.Threading" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net461" />
|
|
||||||
<package id="Telegram.Bot" version="13.2.1" targetFramework="net461" />
|
|
||||||
</packages>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Events {
|
|
||||||
public class BackendEvent : EventArgs {
|
|
||||||
public BackendEvent() : base() { }
|
|
||||||
public BackendEvent(String message, Object from, DateTime date, String label) {
|
|
||||||
this.From = from;
|
|
||||||
this.Message = message;
|
|
||||||
this.Date = date;
|
|
||||||
this.Label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object From { get; private set; }
|
|
||||||
public String Message { get; private set; }
|
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
public String Label { get; private set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Events {
|
|
||||||
public class DataEvent : BackendEvent {
|
|
||||||
public DataEvent(String data) : base() { }
|
|
||||||
public DataEvent(String message, String topic, DateTime date) : base(message, topic, date, "Data") { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Events {
|
|
||||||
public class UserEvent : BackendEvent {
|
|
||||||
public UserEvent() : base() { }
|
|
||||||
public UserEvent(String message, Int64 UserId, DateTime date) : base(message, UserId, date, "User") { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT {
|
|
||||||
static class Helper {
|
|
||||||
internal static String ToUpperLower(this String s) {
|
|
||||||
if (s.Length == 0) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (s.Length == 1) {
|
|
||||||
return s.ToUpper();
|
|
||||||
}
|
|
||||||
return s[0].ToString().ToUpper() + s.Substring(1).ToLower();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Interfaces {
|
|
||||||
public interface IMqtt {
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt einen JSON-String der Eigenschaften eines Objekts zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>JSON-String</returns>
|
|
||||||
String ToJson();
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt das MQTT-Topic als String zurück unter dem die Daten des Objekts Publiziert werden sollen
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>MQTT-Topic</returns>
|
|
||||||
String MqttTopic();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Interfaces {
|
|
||||||
public interface ISenml {
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt einen Senml-JSON-String der Eigenschaften eines Objekts zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Senml-JSON-String</returns>
|
|
||||||
String ToSenml();
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt das Senml-Topic als String zurück unter dem die Daten des Objekts Publiziert werden sollen
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Senml-Topic</returns>
|
|
||||||
String SenmlTopic();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{4DAADA29-C600-4CF3-8AD3-9C97C8D7F632}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>BlubbFish.Utils.IoT.Interfaces</RootNamespace>
|
|
||||||
<AssemblyName>Iot-Interfaces</AssemblyName>
|
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<TargetFrameworkProfile />
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="ISenml.cs" />
|
|
||||||
<Compile Include="IMqtt.cs" />
|
|
||||||
<Compile Include="Language\Senml.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Interfaces.Language {
|
|
||||||
public abstract class Senml {
|
|
||||||
#pragma warning disable IDE1006 // Benennungsstile
|
|
||||||
public String n { get; }
|
|
||||||
public String u { get; }
|
|
||||||
public Int32 t { get; }
|
|
||||||
#pragma warning restore IDE1006 // Benennungsstile
|
|
||||||
|
|
||||||
public enum Units {
|
|
||||||
[Description("%")]
|
|
||||||
Percent,
|
|
||||||
[Description("count")]
|
|
||||||
CounterValue,
|
|
||||||
[Description("W")]
|
|
||||||
Watt,
|
|
||||||
[Description("J")]
|
|
||||||
Joule,
|
|
||||||
[Description("Cel")]
|
|
||||||
Celsius,
|
|
||||||
[Description("lx")]
|
|
||||||
Lux
|
|
||||||
}
|
|
||||||
|
|
||||||
public Senml(String name, Units unit) {
|
|
||||||
this.n = name;
|
|
||||||
this.u = this.GetEnumDescription(unit);
|
|
||||||
this.t = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String GetEnumDescription(Enum value) {
|
|
||||||
FieldInfo fi = value.GetType().GetField(value.ToString());
|
|
||||||
|
|
||||||
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|
||||||
|
|
||||||
if (attributes != null && attributes.Length > 0) {
|
|
||||||
return attributes[0].Description;
|
|
||||||
} else {
|
|
||||||
return value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class SenmlBool : Senml {
|
|
||||||
#pragma warning disable IDE1006 // Benennungsstile
|
|
||||||
public Boolean bv { get; }
|
|
||||||
#pragma warning restore IDE1006 // Benennungsstile
|
|
||||||
public SenmlBool(String name, Units unit, Boolean level) : base(name, unit) {
|
|
||||||
this.bv = level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class SenmlDouble : Senml {
|
|
||||||
#pragma warning disable IDE1006 // Benennungsstile
|
|
||||||
public Double v { get; }
|
|
||||||
#pragma warning restore IDE1006 // Benennungsstile
|
|
||||||
public SenmlDouble(String name, Units unit, Double level) : base(name, unit) {
|
|
||||||
this.v = level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
|
||||||
// die einer Assembly zugeordnet sind.
|
|
||||||
[assembly: AssemblyTitle("Iot-Interfaces")]
|
|
||||||
[assembly: AssemblyDescription("Interfaces for IoT-Stuff")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("BlubbFish")]
|
|
||||||
[assembly: AssemblyProduct("Iot-Interfaces")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2018 - 02.05.2018")]
|
|
||||||
[assembly: AssemblyTrademark("BlubbFish")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
|
||||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
|
||||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
|
||||||
[assembly: Guid("4daada29-c600-4cf3-8ad3-9c97c8d7f632")]
|
|
||||||
|
|
||||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
|
||||||
//
|
|
||||||
// Hauptversion
|
|
||||||
// Nebenversion
|
|
||||||
// Buildnummer
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
|
||||||
// indem Sie "*" wie unten gezeigt eingeben:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
Binary file not shown.
@@ -1,129 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.JsonSensor {
|
|
||||||
public abstract class AJsonSensor : IDisposable {
|
|
||||||
protected String topic;
|
|
||||||
protected Int32 pollcount;
|
|
||||||
protected Dictionary<String, String> settings;
|
|
||||||
protected ABackend backend;
|
|
||||||
private Thread pollingThread;
|
|
||||||
private Boolean pollEnabled = false;
|
|
||||||
|
|
||||||
public AJsonSensor(Dictionary<String, String> settings, String name, ABackend backend) {
|
|
||||||
this.GetBool = true;
|
|
||||||
this.GetFloat = 0.0f;
|
|
||||||
this.GetInt = 0;
|
|
||||||
this.topic = (settings.Keys.Contains("topic")) ? settings["topic"] : "";
|
|
||||||
this.settings = settings;
|
|
||||||
this.Title = (settings.Keys.Contains("title")) ? settings["title"] : "";
|
|
||||||
this.Name = name;
|
|
||||||
this.backend = backend;
|
|
||||||
this.backend.MessageIncomming += this.IncommingMqttMessage;
|
|
||||||
if (settings.Keys.Contains("polling")) {
|
|
||||||
this.pollEnabled = true;
|
|
||||||
this.Polling = Int32.Parse(settings["polling"]);
|
|
||||||
this.pollcount = this.Polling;
|
|
||||||
this.pollingThread = new Thread(this.SensorPolling);
|
|
||||||
this.pollingThread.Start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SensorPolling() {
|
|
||||||
while(this.pollEnabled) {
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
this.Poll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void IncommingMqttMessage(Object sender, BackendEvent e) {
|
|
||||||
if(Regex.Match(e.From.ToString(), this.topic).Success) {
|
|
||||||
if (this.UpdateValue(e)) {
|
|
||||||
this.Timestamp = DateTime.Now;
|
|
||||||
this.Update?.Invoke(this, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AJsonSensor GetInstance(Dictionary<String, ABackend> backends, Dictionary<String, String> settings, String name) {
|
|
||||||
String object_sensor = "BlubbFish.Utils.IoT.JsonSensor." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
|
|
||||||
Type t = null;
|
|
||||||
try {
|
|
||||||
t = Type.GetType(object_sensor, true);
|
|
||||||
} catch(TypeLoadException) {
|
|
||||||
throw new ArgumentException("Sensor: " + object_sensor + " is not a Sensor");
|
|
||||||
}
|
|
||||||
if(!settings.ContainsKey("backend") || !backends.ContainsKey(settings["backend"])) {
|
|
||||||
throw new ArgumentException("Backend not specified!");
|
|
||||||
}
|
|
||||||
return (AJsonSensor)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(String), typeof(ABackend) }).Invoke(new Object[] { settings, name, backends[settings["backend"]] });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Poll() {
|
|
||||||
if(this.pollcount++ >= this.Polling) {
|
|
||||||
this.pollcount = 1;
|
|
||||||
if (this.backend is ADataBackend) {
|
|
||||||
((ADataBackend)this.backend).Send(this.topic + "/get", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void SetBool(Boolean v) {
|
|
||||||
if (this.backend is ADataBackend) {
|
|
||||||
((ADataBackend)this.backend).Send(this.topic + "/set", v ? "on" : "off");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Boolean UpdateValue(BackendEvent e);
|
|
||||||
|
|
||||||
public Single GetFloat { get; protected set; }
|
|
||||||
public Boolean GetBool { get; protected set; }
|
|
||||||
public Int32 GetInt { get; protected set; }
|
|
||||||
public Types Datatypes { get; protected set; }
|
|
||||||
public DateTime Timestamp { get; protected set; }
|
|
||||||
public Int32 Polling { get; private set; }
|
|
||||||
public String Title { get; protected set; }
|
|
||||||
public String Name { get; internal set; }
|
|
||||||
|
|
||||||
public enum Types {
|
|
||||||
Bool,
|
|
||||||
Int,
|
|
||||||
Float
|
|
||||||
}
|
|
||||||
public delegate void UpdatedValue(Object sender, EventArgs e);
|
|
||||||
public event UpdatedValue Update;
|
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
private Boolean disposedValue = false;
|
|
||||||
|
|
||||||
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
|
||||||
if(!this.disposedValue) {
|
|
||||||
if(disposing) {
|
|
||||||
this.pollEnabled = false;
|
|
||||||
if (this.pollingThread != null && this.pollingThread.ThreadState == ThreadState.Running) {
|
|
||||||
this.pollingThread.Abort();
|
|
||||||
while (this.pollingThread.ThreadState != ThreadState.Aborted) { }
|
|
||||||
}
|
|
||||||
this.backend.MessageIncomming -= this.IncommingMqttMessage;
|
|
||||||
}
|
|
||||||
this.settings = null;
|
|
||||||
this.pollingThread = null;
|
|
||||||
this.disposedValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
~AJsonSensor() {
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
public void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
using LitJson;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.JsonSensor {
|
|
||||||
class Bosmon : AJsonSensor {
|
|
||||||
public Bosmon(Dictionary<String, String> settings, String name, ABackend backend) : base(settings, name, backend) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public String Ric { get; private set; }
|
|
||||||
public String Message { get; private set; }
|
|
||||||
public String Func { get; private set; }
|
|
||||||
public DateTime Time { get; private set; }
|
|
||||||
|
|
||||||
protected override Boolean UpdateValue(BackendEvent e) {
|
|
||||||
try {
|
|
||||||
JsonData json = JsonMapper.ToObject(e.Message);
|
|
||||||
if(json.ContainsKey("TYPE_POCSAG")) {
|
|
||||||
if(this.settings["rics"].Split(';').ToList().Contains(json["Address"].ToString())) {
|
|
||||||
this.Ric = json["Address"].ToString();
|
|
||||||
this.Message = json["Msg"].ToString();
|
|
||||||
this.Func = json["Func"].ToString();
|
|
||||||
this.Time = new DateTime(Int64.Parse(json["Timestamp"].ToString()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(Exception) { }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.JsonSensor {
|
|
||||||
class Luminanz : AJsonSensor {
|
|
||||||
public Luminanz(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
|
||||||
this.GetBool = true;
|
|
||||||
this.GetFloat = 0.0f;
|
|
||||||
this.GetInt = 0;
|
|
||||||
this.Datatypes = Types.Int;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Boolean UpdateValue(BackendEvent e) {
|
|
||||||
this.GetInt = Int32.Parse(e.Message, new CultureInfo("en-US"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.JsonSensor {
|
|
||||||
class Pir : AJsonSensor {
|
|
||||||
public Pir(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
|
||||||
this.Datatypes = Types.Bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Boolean UpdateValue(BackendEvent e) {
|
|
||||||
this.GetBool = (e.Message.ToLower() == "on") ? true : false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.JsonSensor {
|
|
||||||
class Power : AJsonSensor {
|
|
||||||
public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
|
||||||
this.GetBool = true;
|
|
||||||
this.GetFloat = 0.0f;
|
|
||||||
this.GetInt = 0;
|
|
||||||
this.Datatypes = Types.Float;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Boolean UpdateValue(BackendEvent e) {
|
|
||||||
this.GetFloat = Single.Parse(e.Message, new CultureInfo("en-US"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.JsonSensor {
|
|
||||||
class Switch : AJsonSensor {
|
|
||||||
public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
|
||||||
this.Datatypes = Types.Bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Boolean UpdateValue(BackendEvent e) {
|
|
||||||
this.GetBool = (e.Message.ToLower() == "on") ? true : false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
|
||||||
using BlubbFish.Utils.IoT.Events;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.JsonSensor {
|
|
||||||
class Temperatur : AJsonSensor {
|
|
||||||
public Temperatur(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
|
||||||
this.GetBool = true;
|
|
||||||
this.GetFloat = 0.0f;
|
|
||||||
this.GetInt = 0;
|
|
||||||
this.Datatypes = Types.Float;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Boolean UpdateValue(BackendEvent e) {
|
|
||||||
this.GetFloat = Single.Parse(e.Message, new CultureInfo("en-US"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
|
||||||
// die einer Assembly zugeordnet sind.
|
|
||||||
[assembly: AssemblyTitle("IoT")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("IoT")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
|
||||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
|
||||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
|
||||||
[assembly: Guid("b870e4d5-6806-4a0b-b233-8907eedc5afc")]
|
|
||||||
|
|
||||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
|
||||||
//
|
|
||||||
// Hauptversion
|
|
||||||
// Nebenversion
|
|
||||||
// Buildnummer
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
|
||||||
// indem Sie "*" wie unten gezeigt eingeben:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>BlubbFish.Utils.IoT</RootNamespace>
|
|
||||||
<AssemblyName>Utils-IoT</AssemblyName>
|
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<TargetFrameworkProfile />
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Connector\ABackend.cs" />
|
|
||||||
<Compile Include="Connector\ADataBackend.cs" />
|
|
||||||
<Compile Include="Connector\AUserBackend.cs" />
|
|
||||||
<Compile Include="Events\BackendEvent.cs" />
|
|
||||||
<Compile Include="Events\DataEvent.cs" />
|
|
||||||
<Compile Include="Events\UserEvent.cs" />
|
|
||||||
<Compile Include="Helper.cs" />
|
|
||||||
<Compile Include="JsonSensor\Bosmon.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="JsonSensor\AJsonSensor.cs" />
|
|
||||||
<Compile Include="JsonSensor\Luminanz.cs" />
|
|
||||||
<Compile Include="JsonSensor\Pir.cs" />
|
|
||||||
<Compile Include="JsonSensor\Power.cs" />
|
|
||||||
<Compile Include="JsonSensor\Switch.cs" />
|
|
||||||
<Compile Include="JsonSensor\Temperatur.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj">
|
|
||||||
<Project>{91a14cd2-2940-4500-8193-56d37edddbaa}</Project>
|
|
||||||
<Name>litjson_4.7.1</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
|
||||||
Binary file not shown.
Submodule
+1
Submodule Iot-Interfaces added at 39525791cb
Submodule
+1
Submodule Utils added at 7f3f3a7b89
Submodule
+1
Submodule Utils-IoT added at 8348185272
@@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio 2012
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils
|
|
||||||
{
|
|
||||||
public class CmdArgs
|
|
||||||
{
|
|
||||||
public enum ArgLength
|
|
||||||
{
|
|
||||||
Single,
|
|
||||||
Touple
|
|
||||||
}
|
|
||||||
#region Classes
|
|
||||||
public struct VaildArguments
|
|
||||||
{
|
|
||||||
public VaildArguments(ArgLength length, Boolean required)
|
|
||||||
{
|
|
||||||
this.Required = required;
|
|
||||||
this.Length = length;
|
|
||||||
}
|
|
||||||
public VaildArguments(ArgLength length)
|
|
||||||
{
|
|
||||||
this.Required = false;
|
|
||||||
this.Length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArgLength Length { get; private set; }
|
|
||||||
public Boolean Required { get; private set; }
|
|
||||||
}
|
|
||||||
private struct ArgTouple
|
|
||||||
{
|
|
||||||
public ArgTouple(String type, String data)
|
|
||||||
{
|
|
||||||
this.Type = type;
|
|
||||||
this.Data = data;
|
|
||||||
}
|
|
||||||
public ArgTouple(String type)
|
|
||||||
{
|
|
||||||
this.Type = type;
|
|
||||||
this.Data = null;
|
|
||||||
}
|
|
||||||
public String Type { get; private set; }
|
|
||||||
public String Data { get; private set; }
|
|
||||||
|
|
||||||
internal void SetData(String data)
|
|
||||||
{
|
|
||||||
if (data != "") {
|
|
||||||
this.Data = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
private String[] args;
|
|
||||||
private List<ArgTouple> argList;
|
|
||||||
private Dictionary<String, VaildArguments> argsPosible = new Dictionary<String, VaildArguments>();
|
|
||||||
private static CmdArgs instances = null;
|
|
||||||
private Boolean isSetArguments = false;
|
|
||||||
|
|
||||||
private CmdArgs()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt eine Instanz der Klasse zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Klasse</returns>
|
|
||||||
public static CmdArgs Instance
|
|
||||||
{
|
|
||||||
get {
|
|
||||||
if (instances == null) {
|
|
||||||
instances = new CmdArgs();
|
|
||||||
}
|
|
||||||
return instances;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Übernimmt die Argumente für die Klasse
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="arguments">Mögliche Komandozeilenargumente</param>
|
|
||||||
/// <param name="args">Tatsächliche Komandozeilenargumente</param>
|
|
||||||
public void SetArguments(Dictionary<String, VaildArguments> arguments, String[] args)
|
|
||||||
{
|
|
||||||
this.args = args;
|
|
||||||
if (!this.isSetArguments) {
|
|
||||||
this.isSetArguments = true;
|
|
||||||
this.argsPosible = arguments;
|
|
||||||
this.Init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Init()
|
|
||||||
{
|
|
||||||
this.argList = new List<ArgTouple>();
|
|
||||||
for (Int32 i = 0; i < this.args.Length; i++) {
|
|
||||||
if (this.argsPosible.Keys.Contains(this.args[i])) {
|
|
||||||
ArgTouple arg = new ArgTouple(this.args[i]);
|
|
||||||
if (this.argsPosible[this.args[i]].Length == ArgLength.Touple) {
|
|
||||||
if (this.args.Length > i + 1) {
|
|
||||||
arg.SetData(this.args[++i]);
|
|
||||||
} else {
|
|
||||||
Console.WriteLine(this.GetUsageList(""));
|
|
||||||
throw new ArgumentException("Argument: "+this.args[i]+" missing second argument.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.argList.Add(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Menge der angegebenen Komandozeilen-Argumente
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Menge</returns>
|
|
||||||
public Int32 GetArgsLength()
|
|
||||||
{
|
|
||||||
return this.argList.Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt zurück ob ein Argument angegeben wurde
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Name des Arguments</param>
|
|
||||||
/// <returns>true wenn angegeben</returns>
|
|
||||||
public Boolean HasArgumentType(String name)
|
|
||||||
{
|
|
||||||
foreach (ArgTouple t in this.argList) {
|
|
||||||
if (t.Type == name) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt den Inhalt des angegeben Arguments zurück, nur bei zweiteiligen Argumenten möglich
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Name des Arguments</param>
|
|
||||||
/// <returns>Inhalt des Arguments oder ArgumentNullException</returns>
|
|
||||||
public String GetArgumentData(String name)
|
|
||||||
{
|
|
||||||
foreach (ArgTouple t in this.argList) {
|
|
||||||
if (t.Type == name && t.Data != null) {
|
|
||||||
return t.Data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new ArgumentNullException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean HasAllRequiredArguments()
|
|
||||||
{
|
|
||||||
foreach (KeyValuePair<String, VaildArguments> item in this.argsPosible) {
|
|
||||||
if (item.Value.Required && !this.HasArgumentType(item.Key)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String GetUsageList(String name)
|
|
||||||
{
|
|
||||||
String ret = "Usage: " + name + " Parameter\nParameter:\n";
|
|
||||||
String req = "";
|
|
||||||
String opt = "";
|
|
||||||
foreach (KeyValuePair<String, VaildArguments> item in this.argsPosible) {
|
|
||||||
if (item.Value.Required) {
|
|
||||||
req += item.Key + " " + ((item.Value.Length == ArgLength.Touple) ? " [data]\n" : "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (req != "") {
|
|
||||||
ret += "Benötigte Parameter:\n" + req;
|
|
||||||
}
|
|
||||||
foreach (KeyValuePair<String, VaildArguments> item in this.argsPosible) {
|
|
||||||
if (!item.Value.Required) {
|
|
||||||
opt += item.Key + " " + ((item.Value.Length == ArgLength.Touple) ? " [data]\n" : "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (opt != "") {
|
|
||||||
ret += "Optionale Parameter:\n" + opt;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils {
|
|
||||||
public class UpdaterEventArgs : EventArgs {
|
|
||||||
public UpdaterEventArgs(Boolean hasUpdates, String message) {
|
|
||||||
this.HasUpdates = hasUpdates;
|
|
||||||
this.Message = message;
|
|
||||||
}
|
|
||||||
public String Message { get; private set; }
|
|
||||||
public Boolean HasUpdates { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class UpdaterFailEventArgs : EventArgs {
|
|
||||||
public UpdaterFailEventArgs(Exception e) {
|
|
||||||
this.Except = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Exception Except { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LogEventArgs : EventArgs {
|
|
||||||
public LogEventArgs(String location, String message, OwnObject.LogLevel level, DateTime date) {
|
|
||||||
this.Location = location;
|
|
||||||
this.Message = message;
|
|
||||||
this.Level = level;
|
|
||||||
this.Date = date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String Location { get; private set; }
|
|
||||||
public String Message { get; private set; }
|
|
||||||
public OwnObject.LogLevel Level { get; private set; }
|
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils
|
|
||||||
{
|
|
||||||
public class FileLogger
|
|
||||||
{
|
|
||||||
private static Dictionary<String, FileLogger> instances = new Dictionary<String, FileLogger>();
|
|
||||||
private static String logDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
|
|
||||||
private readonly StreamWriter file;
|
|
||||||
private FileLogger(String filename, Boolean append)
|
|
||||||
{
|
|
||||||
filename = logDir + filename;
|
|
||||||
if (!File.Exists(filename)) {
|
|
||||||
String folder = Path.GetDirectoryName(Path.GetFullPath(filename));
|
|
||||||
if (!Directory.Exists(folder)) {
|
|
||||||
Directory.CreateDirectory(folder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.file = new StreamWriter(filename, append, Encoding.UTF8) {
|
|
||||||
AutoFlush = true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public static FileLogger GetInstance(String filename, Boolean append)
|
|
||||||
{
|
|
||||||
if (!instances.Keys.Contains(filename)) {
|
|
||||||
instances.Add(filename, new FileLogger(filename, append));
|
|
||||||
}
|
|
||||||
return instances[filename];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetLogDir(String v)
|
|
||||||
{
|
|
||||||
v = v.Replace("..", "");
|
|
||||||
v = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + v;
|
|
||||||
if (Directory.Exists(v)) {
|
|
||||||
logDir = v;
|
|
||||||
} else {
|
|
||||||
Directory.CreateDirectory(v);
|
|
||||||
logDir = v;
|
|
||||||
}
|
|
||||||
if (logDir.Substring(logDir.Length - 1) != Path.DirectorySeparatorChar.ToString()) {
|
|
||||||
logDir = logDir + Path.DirectorySeparatorChar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetArray(String[] text)
|
|
||||||
{
|
|
||||||
this.file.Write(String.Join(this.file.NewLine, text) + this.file.NewLine);
|
|
||||||
this.file.Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetLine(String text)
|
|
||||||
{
|
|
||||||
this.file.WriteLine(text);
|
|
||||||
this.file.Flush();
|
|
||||||
}
|
|
||||||
public void SetLine(String text, DateTime d)
|
|
||||||
{
|
|
||||||
this.SetLine(d.ToString("[yyyy-MM-dd HH:mm:ss.ffff] ") + text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils
|
|
||||||
{
|
|
||||||
public class FileMutex : IDisposable
|
|
||||||
{
|
|
||||||
private static FileMutex instance;
|
|
||||||
private String filename;
|
|
||||||
private StreamWriter file;
|
|
||||||
private FileMutex() { }
|
|
||||||
|
|
||||||
public static FileMutex Instance
|
|
||||||
{
|
|
||||||
get {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new FileMutex();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetName(String name)
|
|
||||||
{
|
|
||||||
String path = AppDomain.CurrentDomain.BaseDirectory;
|
|
||||||
this.filename = path + String.Join(String.Empty, Array.ConvertAll(new SHA512Managed().ComputeHash(Encoding.UTF8.GetBytes(name)), b => b.ToString("X2"))) + ".lock.txt";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean Create()
|
|
||||||
{
|
|
||||||
if (File.Exists(this.filename)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.file = new StreamWriter(this.filename);
|
|
||||||
InitFile();
|
|
||||||
return File.Exists(this.filename) && this.file != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitFile()
|
|
||||||
{
|
|
||||||
this.file.Write("Created: " + DateTime.Now.ToUniversalTime() + "\n");
|
|
||||||
this.file.Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean Delete()
|
|
||||||
{
|
|
||||||
if(this.file != null) {
|
|
||||||
this.file.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
File.Delete(this.filename);
|
|
||||||
return !File.Exists(this.filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
|
||||||
if (disposing) {
|
|
||||||
if(this.file != null) {
|
|
||||||
this.file.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils {
|
|
||||||
public static class Helper {
|
|
||||||
#region PropertyHelper
|
|
||||||
public static Boolean HasProperty(this Object o, String type) {
|
|
||||||
Type t = o.GetType();
|
|
||||||
foreach (PropertyInfo item in t.GetProperties()) {
|
|
||||||
if (item.Name == type) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object GetProperty(this Object o, String name) {
|
|
||||||
PropertyInfo prop = o.GetType().GetProperty(name);
|
|
||||||
if (prop.CanRead) {
|
|
||||||
return prop.GetValue(o);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetProperty(this Object o, String name, String value) {
|
|
||||||
PropertyInfo prop = o.GetType().GetProperty(name);
|
|
||||||
if (prop.CanWrite) {
|
|
||||||
if (prop.PropertyType == typeof(Boolean) && Boolean.TryParse(value, out Boolean vb)) {
|
|
||||||
prop.SetValue(o, vb);
|
|
||||||
} else if (prop.PropertyType == typeof(Byte) && Byte.TryParse(value, out Byte v8)) {
|
|
||||||
prop.SetValue(o, v8);
|
|
||||||
} else if (prop.PropertyType == typeof(Int32) && Int32.TryParse(value, out Int32 v32)) {
|
|
||||||
prop.SetValue(o, v32);
|
|
||||||
} else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) {
|
|
||||||
prop.SetValue(o, vs);
|
|
||||||
} else if (prop.PropertyType == typeof(Double) && Double.TryParse(value, out Double vd)) {
|
|
||||||
prop.SetValue(o, vd);
|
|
||||||
} else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) {
|
|
||||||
prop.SetValue(o, v64);
|
|
||||||
} else if (prop.PropertyType.BaseType == typeof(Enum)) {
|
|
||||||
try {
|
|
||||||
prop.SetValue(o, Enum.Parse(prop.PropertyType, value));
|
|
||||||
} catch (Exception) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region InterfaceHelper
|
|
||||||
public static Boolean HasInterface(this Type o, Type interf) {
|
|
||||||
foreach (Type item in o.GetInterfaces()) {
|
|
||||||
if (item == interf) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Boolean HasAbstract(this Type o, Type type) {
|
|
||||||
if (o.BaseType == type) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region StringHelper
|
|
||||||
public static String GetEnumDescription(Enum value) {
|
|
||||||
FieldInfo fi = value.GetType().GetField(value.ToString());
|
|
||||||
|
|
||||||
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|
||||||
|
|
||||||
if (attributes != null && attributes.Length > 0) {
|
|
||||||
return attributes[0].Description;
|
|
||||||
} else {
|
|
||||||
return value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String ToUpperLower(this String s) {
|
|
||||||
if (s.Length == 0) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (s.Length == 1) {
|
|
||||||
return s.ToUpper();
|
|
||||||
}
|
|
||||||
return s[0].ToString().ToUpper() + s.Substring(1).ToLower();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void WriteError(String text) {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
|
||||||
Console.Error.WriteLine("ERROR: " + text);
|
|
||||||
Console.ResetColor();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,276 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils {
|
|
||||||
public class InIReader : IDisposable
|
|
||||||
{
|
|
||||||
private Dictionary<String, Dictionary<String, String>> inifile;
|
|
||||||
private readonly FileSystemWatcher k;
|
|
||||||
private readonly String filename;
|
|
||||||
private static List<String> search_path = new List<String>() {
|
|
||||||
Directory.GetCurrentDirectory()
|
|
||||||
};
|
|
||||||
|
|
||||||
private static Dictionary<String, InIReader> instances = new Dictionary<String, InIReader>();
|
|
||||||
|
|
||||||
public static void SetSearchPath(List<String> directorys) {
|
|
||||||
search_path.AddRange(directorys);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Boolean ConfigExist(String filename) {
|
|
||||||
foreach (String path in search_path) {
|
|
||||||
if (File.Exists(path + Path.DirectorySeparatorChar + filename)) {
|
|
||||||
return true;
|
|
||||||
} else if (File.Exists(path + Path.DirectorySeparatorChar + filename + ".ini")) {
|
|
||||||
return true;
|
|
||||||
} else if (File.Exists(path + Path.DirectorySeparatorChar + filename + ".conf")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private InIReader(String filename)
|
|
||||||
{
|
|
||||||
foreach (String path in search_path) {
|
|
||||||
if (File.Exists(path + Path.DirectorySeparatorChar + filename)) {
|
|
||||||
this.filename = path + Path.DirectorySeparatorChar + filename;
|
|
||||||
this.k = new FileSystemWatcher(path, filename);
|
|
||||||
break;
|
|
||||||
} else if (File.Exists(path + Path.DirectorySeparatorChar + filename + ".ini")) {
|
|
||||||
this.filename = path + Path.DirectorySeparatorChar + filename + ".ini";
|
|
||||||
this.k = new FileSystemWatcher(path, filename + ".ini");
|
|
||||||
break;
|
|
||||||
} else if(File.Exists(path + Path.DirectorySeparatorChar + filename + ".conf")) {
|
|
||||||
this.filename = path + Path.DirectorySeparatorChar + filename + ".conf";
|
|
||||||
this.k = new FileSystemWatcher(path, filename + ".conf");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(this.filename == null) {
|
|
||||||
throw new ArgumentException(filename + " not found!");
|
|
||||||
}
|
|
||||||
this.k.Changed += new FileSystemEventHandler(this.ReadAgain);
|
|
||||||
LoadFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt eine InIReader-Instanz zu einer Datei zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Dateiname</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static InIReader GetInstance(String filename)
|
|
||||||
{
|
|
||||||
if (!instances.Keys.Contains(filename)) {
|
|
||||||
instances.Add(filename, new InIReader(filename));
|
|
||||||
}
|
|
||||||
return instances[filename];
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReadAgain(Object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
this.LoadFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadFile()
|
|
||||||
{
|
|
||||||
this.inifile = new Dictionary<String, Dictionary<String, String>>();
|
|
||||||
StreamReader file = new StreamReader(this.filename);
|
|
||||||
List<String> buf = new List<String>();
|
|
||||||
String fline = "";
|
|
||||||
while (fline != null) {
|
|
||||||
fline = file.ReadLine();
|
|
||||||
if (fline != null && fline.Length > 0 && fline.Substring(0, 1) != ";") {
|
|
||||||
buf.Add(fline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.Close();
|
|
||||||
Dictionary<String, String> sub = new Dictionary<String, String>();
|
|
||||||
String cap = "";
|
|
||||||
foreach (String line in buf) {
|
|
||||||
Match match = Regex.Match(line, @"^\[[a-zA-ZäöüÄÖÜ0-9\-\._/ ]+\]\w*$", RegexOptions.IgnoreCase);
|
|
||||||
if (match.Success) {
|
|
||||||
if (sub.Count != 0 && cap != "") {
|
|
||||||
this.inifile.Add(cap, sub);
|
|
||||||
}
|
|
||||||
cap = line;
|
|
||||||
sub = new Dictionary<String, String>();
|
|
||||||
} else {
|
|
||||||
if (line != "" && cap != "") {
|
|
||||||
String key = line.Substring(0, line.IndexOf('='));
|
|
||||||
String value = line.Substring(line.IndexOf('=') + 1);
|
|
||||||
sub.Add(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sub.Count != 0 && cap != "") {
|
|
||||||
this.inifile.Add(cap, sub);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt eine Liste an Sektionen zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="withBrackets">Default = true; false, wenn die Liste ohne Klammern sein soll.</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<String> GetSections(Boolean withBrackets = true)
|
|
||||||
{
|
|
||||||
if(withBrackets) {
|
|
||||||
return this.inifile.Keys.ToList();
|
|
||||||
} else {
|
|
||||||
List<String> ret = new List<String>();
|
|
||||||
foreach (String item in this.inifile.Keys) {
|
|
||||||
ret.Add(item.Substring(1, item.Length - 2));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Überschreibt eine InI-Datei mit der Kompletten neuen Configuration
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="config">Neue Konfiguration</param>
|
|
||||||
public void SetSections(Dictionary<String, Dictionary<String, String>> config) {
|
|
||||||
this.inifile.Clear();
|
|
||||||
foreach (KeyValuePair<String, Dictionary<String, String>> item in config) {
|
|
||||||
String key = item.Key;
|
|
||||||
if(!key.StartsWith("[")) {
|
|
||||||
key = "[" + key + "]";
|
|
||||||
}
|
|
||||||
if (Regex.Match(key, @"^\[[a-zA-ZäöüÄÖÜ0-9\-\._/ ]+\]\w*$", RegexOptions.IgnoreCase).Success) {
|
|
||||||
this.inifile.Add(key, item.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dictionary<String, String> GetSection(String section) {
|
|
||||||
if(this.inifile.Keys.Contains(section)) {
|
|
||||||
return this.inifile[section];
|
|
||||||
}
|
|
||||||
if(this.inifile.Keys.Contains("["+section+"]")) {
|
|
||||||
return this.inifile["[" + section + "]"];
|
|
||||||
}
|
|
||||||
return new Dictionary<String, String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt einen einzelnen Wert zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="section">Name der Sektion</param>
|
|
||||||
/// <param name="key">Name des Wertes</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public String GetValue(String section, String key)
|
|
||||||
{
|
|
||||||
if (!section.StartsWith("[")) {
|
|
||||||
section = "[" + section + "]";
|
|
||||||
}
|
|
||||||
if (this.inifile.Keys.Contains(section)) {
|
|
||||||
if (this.inifile[section].Keys.Contains(key)) {
|
|
||||||
return this.inifile[section][key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Setzt einen Wert in einer Sektion
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="section">Name der Sektion</param>
|
|
||||||
/// <param name="key">Name des Wertes</param>
|
|
||||||
/// <param name="value">Wert</param>
|
|
||||||
public void SetValue(String section, String key, String value)
|
|
||||||
{
|
|
||||||
if (!section.StartsWith("[")) {
|
|
||||||
section = "[" + section + "]";
|
|
||||||
}
|
|
||||||
if (this.inifile.Keys.Contains(section)) {
|
|
||||||
if (this.inifile[section].Keys.Contains(key)) {
|
|
||||||
this.inifile[section][key] = value;
|
|
||||||
} else {
|
|
||||||
this.inifile[section].Add(key, value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Dictionary<String, String> sub = new Dictionary<String, String> {
|
|
||||||
{ key, value }
|
|
||||||
};
|
|
||||||
this.inifile.Add(section, sub);
|
|
||||||
}
|
|
||||||
this.Changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Changed()
|
|
||||||
{
|
|
||||||
this.k.Changed -= null;
|
|
||||||
SaveSettings();
|
|
||||||
LoadFile();
|
|
||||||
this.k.Changed += new FileSystemEventHandler(this.ReadAgain);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SaveSettings()
|
|
||||||
{
|
|
||||||
StreamWriter file = new StreamWriter(this.filename);
|
|
||||||
file.BaseStream.SetLength(0);
|
|
||||||
file.BaseStream.Flush();
|
|
||||||
file.BaseStream.Seek(0, SeekOrigin.Begin);
|
|
||||||
foreach (KeyValuePair<String, Dictionary<String, String>> cap in this.inifile) {
|
|
||||||
file.WriteLine(cap.Key);
|
|
||||||
foreach (KeyValuePair<String, String> sub in cap.Value) {
|
|
||||||
file.WriteLine(sub.Key + "=" + sub.Value);
|
|
||||||
}
|
|
||||||
file.WriteLine();
|
|
||||||
}
|
|
||||||
file.Flush();
|
|
||||||
file.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Fügt eine neue Sektion in der Ini-Datei ein.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Sektionsname</param>
|
|
||||||
/// <returns>true if added, false if error</returns>
|
|
||||||
public Boolean AddSection(String name)
|
|
||||||
{
|
|
||||||
if (!name.StartsWith("[")) {
|
|
||||||
name = "[" + name + "]";
|
|
||||||
}
|
|
||||||
if (this.inifile.Keys.Contains(name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.inifile.Add(name, new Dictionary<String, String>());
|
|
||||||
this.Changed();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Löscht eine Sektion inklusive Unterpunkte aus der Ini-Datei.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Sektionsname</param>
|
|
||||||
/// <returns>true if removed, false if error</returns>
|
|
||||||
public Boolean RemoveSection(String name)
|
|
||||||
{
|
|
||||||
if (!name.StartsWith("[")) {
|
|
||||||
name = "[" + name + "]";
|
|
||||||
}
|
|
||||||
if (!this.inifile.Keys.Contains(name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.inifile.Remove(name);
|
|
||||||
this.Changed();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
|
||||||
if (disposing) {
|
|
||||||
this.k.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace BlubbFish.Utils
|
|
||||||
{
|
|
||||||
public abstract class OwnController
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Führt den Controller aus.
|
|
||||||
/// </summary>
|
|
||||||
public void Execute()
|
|
||||||
{
|
|
||||||
this.Init();
|
|
||||||
}
|
|
||||||
abstract protected void Init();
|
|
||||||
abstract public void Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user