[NF] Hue-Lib fertig
[DW] Hue-Bot beginn Arbeit
This commit is contained in:
commit
bc694f2fd9
55
Hue-Bot.sln
Normal file
55
Hue-Bot.sln
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
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}") = "Hue-Bot", "Hue-Bot\Hue-Bot.csproj", "{4C2F9593-4CF6-47DC-85D3-2D098C404C70}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hue", "..\Hue\Hue\Hue.csproj", "{738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}"
|
||||
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}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4C2F9593-4CF6-47DC-85D3-2D098C404C70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4C2F9593-4CF6-47DC-85D3-2D098C404C70}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4C2F9593-4CF6-47DC-85D3-2D098C404C70}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4C2F9593-4CF6-47DC-85D3-2D098C404C70}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}.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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {15702E91-23B8-44F6-9544-A0C8E506A91E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
124
Hue-Bot/Hue-Bot.csproj
Normal file
124
Hue-Bot/Hue-Bot.csproj
Normal file
@ -0,0 +1,124 @@
|
||||
<?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>{4C2F9593-4CF6-47DC-85D3-2D098C404C70}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>BlubbFish.IoT.Bot.HueBot</RootNamespace>
|
||||
<AssemblyName>Hue-Bot</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<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' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<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="lib\Events.cs" />
|
||||
<Compile Include="lib\Helper.cs" />
|
||||
<Compile Include="Interfaces\AModul.cs" />
|
||||
<Compile Include="Moduls\Mqtt.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\Icon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Hue\Hue\Hue.csproj">
|
||||
<Project>{738a6137-8fca-4ce1-bd1c-042b21b6b5f2}</Project>
|
||||
<Name>Hue</Name>
|
||||
</ProjectReference>
|
||||
<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="..\..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj">
|
||||
<Project>{ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2}</Project>
|
||||
<Name>ConnectorDataMqtt</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Utils\IoT\Utils-IoT.csproj">
|
||||
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
|
||||
<Name>Utils-IoT</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
|
||||
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 und x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
13
Hue-Bot/Hue-Bot.csproj.user
Normal file
13
Hue-Bot/Hue-Bot.csproj.user
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishUrlHistory>publish\</PublishUrlHistory>
|
||||
<InstallUrlHistory />
|
||||
<SupportUrlHistory />
|
||||
<UpdateUrlHistory />
|
||||
<BootstrapperUrlHistory />
|
||||
<ErrorReportUrlHistory />
|
||||
<FallbackCulture>de-DE</FallbackCulture>
|
||||
<VerifyUploadedFiles>false</VerifyUploadedFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
72
Hue-Bot/Interfaces/AModul.cs
Normal file
72
Hue-Bot/Interfaces/AModul.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.IoT.Bot.HueBot.lib;
|
||||
using BlubbFish.IoT.Hue;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace BlubbFish.IoT.Bot.HueBot.Interfaces {
|
||||
abstract class AModul {
|
||||
protected HueController hue;
|
||||
private 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(HueController huec, InIReader settings) {
|
||||
this.HasConfig = false;
|
||||
this.ConfigPublic = false;
|
||||
this.hue = huec;
|
||||
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> moduls) { }
|
||||
|
||||
public virtual void SetInterconnection(String param, Action<Object> hook, Object data) { }
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
internal 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();
|
||||
}
|
||||
}
|
139
Hue-Bot/Moduls/Mqtt.cs
Normal file
139
Hue-Bot/Moduls/Mqtt.cs
Normal file
@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using BlubbFish.IoT.Bot.HueBot.Interfaces;
|
||||
using BlubbFish.IoT.Bot.HueBot.lib;
|
||||
using BlubbFish.IoT.Hue;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Bot.HueBot.Moduls {
|
||||
class Mqtt : AModul, IDisposable {
|
||||
private ADataBackend mqtt;
|
||||
private Dictionary<String, AModul> modules;
|
||||
|
||||
public override event ModulEvent Update;
|
||||
|
||||
public Mqtt(HueController hue, InIReader settings) : base(hue, settings) {
|
||||
if (this.config.ContainsKey("settings")) {
|
||||
this.mqtt = ADataBackend.GetInstance(this.config["settings"]);
|
||||
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
|
||||
this.hue.Update += this.ZwayEvent;
|
||||
}
|
||||
}
|
||||
|
||||
private void ZwayEvent(Object sender, AllUpdateEvent e) {
|
||||
String topic = "";
|
||||
String data = "";
|
||||
if (e.Parent.GetType().HasInterface("IMqtt")) {
|
||||
IMqtt sensor = (IMqtt)e.Parent;
|
||||
topic = "/hue/" + sensor.MqttTopic();
|
||||
data = sensor.ToJson();
|
||||
}
|
||||
if (topic != "" && data != "") {
|
||||
this.mqtt.Send(topic, data);
|
||||
this.Update?.Invoke(this, new MqttEvent(topic, data));
|
||||
}
|
||||
}
|
||||
|
||||
private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) {
|
||||
if (e.Topic.StartsWith("/hue/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) {
|
||||
/*Match m = new Regex("^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/[gs]et$|^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/(\\d+)/[gs]et$").Match(e.Topic);
|
||||
String id = "";
|
||||
if (m.Groups[1].Success) {
|
||||
id = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value;
|
||||
}
|
||||
if (m.Groups[4].Success) {
|
||||
id = m.Groups[4].Value + "-" + m.Groups[5].Value + "-" + m.Groups[6].Value + "-" + m.Groups[7].Value;
|
||||
}
|
||||
ACommandClass c = this.zw.GetCommandClass(id);
|
||||
if (c == null) {
|
||||
return;
|
||||
}
|
||||
if (e.Topic.EndsWith("/set")) {
|
||||
try {
|
||||
JsonData a = JsonMapper.ToObject(e.Message);
|
||||
foreach (String item in a.Keys) {
|
||||
String key = item.ToUpperLower();
|
||||
if (c.HasProperty(key)) {
|
||||
c.SetProperty(key, a[item].ToString());
|
||||
this.Update?.Invoke(this, new MqttEvent(c.Id, a[item].ToString()));
|
||||
}
|
||||
}
|
||||
} catch (Exception) { }
|
||||
} else if (e.Topic.EndsWith("/get")) {
|
||||
c.PollOnce = true;
|
||||
this.mqtt.Send("/zwavebot/devices/" + c.MqttTopic(), c.ToJson());
|
||||
this.Update?.Invoke(this, new MqttEvent(e.Topic, "Dataget"));
|
||||
}*/
|
||||
}
|
||||
if (e.Topic.StartsWith("/hue/config/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) {
|
||||
Match m = new Regex("^/hue/config/(\\w+)/[gs]et$|").Match(e.Topic);
|
||||
if (!m.Groups[1].Success) {
|
||||
return;
|
||||
}
|
||||
AModul modul = null;
|
||||
foreach (KeyValuePair<String, AModul> item in this.modules) {
|
||||
if (item.Key.ToLower() == m.Groups[1].Value) {
|
||||
modul = item.Value;
|
||||
}
|
||||
}
|
||||
if (modul == null) {
|
||||
return;
|
||||
}
|
||||
if (e.Topic.EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) {
|
||||
String topic = "/hue/config/" + m.Groups[1].Value;
|
||||
String data = JsonMapper.ToJson(modul.GetConfig()).ToString();
|
||||
this.mqtt.Send(topic, data);
|
||||
this.Update?.Invoke(this, new MqttEvent(topic, data));
|
||||
}
|
||||
if (e.Topic.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);
|
||||
this.Update?.Invoke(this, new MqttEvent("New Config", "Write"));
|
||||
} catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Interconnect(Dictionary<String, AModul> moduls) {
|
||||
this.modules = moduls;
|
||||
}
|
||||
|
||||
protected override void UpdateConfig() { }
|
||||
|
||||
#region IDisposable Support
|
||||
private Boolean disposedValue = false;
|
||||
|
||||
protected virtual void Dispose(Boolean disposing) {
|
||||
if (!this.disposedValue) {
|
||||
if (disposing) {
|
||||
this.mqtt.Dispose();
|
||||
}
|
||||
this.disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
~Mqtt() {
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
88
Hue-Bot/Program.cs
Normal file
88
Hue-Bot/Program.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using BlubbFish.IoT.Bot.HueBot.Interfaces;
|
||||
using BlubbFish.IoT.Bot.HueBot.lib;
|
||||
using BlubbFish.IoT.Hue;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace BlubbFish.IoT.Bot.HueBot {
|
||||
class Program {
|
||||
static void Main(String[] args) => new Program(args);
|
||||
|
||||
private HueController hue;
|
||||
private Dictionary<String, AModul> moduls = new Dictionary<String, AModul>();
|
||||
public Program(String[] args) {
|
||||
if (!File.Exists("settings.ini")) {
|
||||
Helper.WriteError("No settings.ini found. Abord!");
|
||||
return;
|
||||
}
|
||||
this.hue = new HueController(InIReader.GetInstance("settings.ini").GetSection("hue"));
|
||||
this.hue.Update += this.HueDataUpdate;
|
||||
this.ModulLoader();
|
||||
this.ModulInterconnect();
|
||||
this.ModulEvents();
|
||||
this.WaitForShutdown();
|
||||
this.ModulDispose();
|
||||
}
|
||||
|
||||
private void ModulLoader() {
|
||||
Assembly asm = Assembly.GetExecutingAssembly();
|
||||
foreach (Type item in asm.GetTypes()) {
|
||||
if (item.Namespace == "BlubbFish.IoT.Bot.HueBot.Moduls") {
|
||||
Type t = item;
|
||||
String name = t.Name;
|
||||
if (File.Exists(name.ToLower() + ".ini")) {
|
||||
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(HueController), typeof(InIReader) }).Invoke(new Object[] { this.hue, InIReader.GetInstance(name.ToLower() + ".ini") }));
|
||||
Console.WriteLine("Load Modul " + name);
|
||||
} else if (t.HasInterface("IForceLoad")) {
|
||||
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(HueController), typeof(InIReader) }).Invoke(new Object[] { this.hue, null }));
|
||||
Console.WriteLine("Load Modul Forced " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ModulInterconnect() {
|
||||
foreach (KeyValuePair<String, AModul> item in this.moduls) {
|
||||
item.Value.Interconnect(this.moduls);
|
||||
}
|
||||
}
|
||||
|
||||
private void ModulEvents() {
|
||||
foreach (KeyValuePair<String, AModul> item in this.moduls) {
|
||||
item.Value.Update += this.ModulUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void WaitForShutdown() {
|
||||
while (true) {
|
||||
System.Threading.Thread.Sleep(100);
|
||||
if (Console.KeyAvailable) {
|
||||
ConsoleKeyInfo key = Console.ReadKey(false);
|
||||
if (key.Key == ConsoleKey.Escape) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ModulDispose() {
|
||||
foreach (KeyValuePair<String, AModul> item in this.moduls) {
|
||||
item.Value.Dispose();
|
||||
Console.WriteLine("Modul entladen: " + item.Key);
|
||||
}
|
||||
this.hue.Dispose();
|
||||
}
|
||||
|
||||
private void HueDataUpdate(Object sender, AllUpdateEvent e) {
|
||||
Console.WriteLine("-> Hue [" + e.UpdateTime + "]: " + e.Parent.ToString());
|
||||
}
|
||||
|
||||
private void ModulUpdate(Object sender, ModulEventArgs e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
39
Hue-Bot/Properties/AssemblyInfo.cs
Normal file
39
Hue-Bot/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Resources;
|
||||
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("Hue-Bot")]
|
||||
[assembly: AssemblyDescription("Is a Bot for Hue Devices")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("Hue-Bot")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018 - 15.04.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("4c2f9593-4cf6-47dc-85d3-2d098c404c70")]
|
||||
|
||||
// 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,
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: NeutralResourcesLanguage("de-DE")]
|
||||
|
73
Hue-Bot/Properties/Resources.Designer.cs
generated
Normal file
73
Hue-Bot/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,73 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Dieser Code wurde von einem Tool generiert.
|
||||
// Laufzeitversion:4.0.30319.42000
|
||||
//
|
||||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
// der Code erneut generiert wird.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace BlubbFish.IoT.Bot.HueBot.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
/// </summary>
|
||||
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
|
||||
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
|
||||
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
|
||||
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BlubbFish.IoT.Bot.HueBot.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon Icon {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("Icon", resourceCulture);
|
||||
return ((System.Drawing.Icon)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
124
Hue-Bot/Properties/Resources.resx
Normal file
124
Hue-Bot/Properties/Resources.resx
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="Icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
Hue-Bot/Resources/Icon.ico
Normal file
BIN
Hue-Bot/Resources/Icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 216 KiB |
BIN
Hue-Bot/Resources/Icon.png
Normal file
BIN
Hue-Bot/Resources/Icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 124 KiB |
BIN
Hue-Bot/bin/Release/ConnectorDataMqtt.dll
Normal file
BIN
Hue-Bot/bin/Release/ConnectorDataMqtt.dll
Normal file
Binary file not shown.
BIN
Hue-Bot/bin/Release/Hue-Bot.exe
Normal file
BIN
Hue-Bot/bin/Release/Hue-Bot.exe
Normal file
Binary file not shown.
BIN
Hue-Bot/bin/Release/Hue.dll
Normal file
BIN
Hue-Bot/bin/Release/Hue.dll
Normal file
Binary file not shown.
BIN
Hue-Bot/bin/Release/M2Mqtt.Net.dll
Normal file
BIN
Hue-Bot/bin/Release/M2Mqtt.Net.dll
Normal file
Binary file not shown.
BIN
Hue-Bot/bin/Release/Utils-IoT.dll
Normal file
BIN
Hue-Bot/bin/Release/Utils-IoT.dll
Normal file
Binary file not shown.
BIN
Hue-Bot/bin/Release/Utils.dll
Normal file
BIN
Hue-Bot/bin/Release/Utils.dll
Normal file
Binary file not shown.
BIN
Hue-Bot/bin/Release/litjson.dll
Normal file
BIN
Hue-Bot/bin/Release/litjson.dll
Normal file
Binary file not shown.
72
Hue-Bot/lib/Events.cs
Normal file
72
Hue-Bot/lib/Events.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlubbFish.IoT.Bot.HueBot.lib {
|
||||
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";
|
||||
}
|
||||
}
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public class ModulEventArgs : EventArgs {
|
||||
public ModulEventArgs() {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
73
Hue-Bot/lib/Helper.cs
Normal file
73
Hue-Bot/lib/Helper.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BlubbFish.IoT.Bot.HueBot.lib {
|
||||
static class Helper {
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal 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;
|
||||
}
|
||||
|
||||
internal static Object GetProperty(this Object o, String name) {
|
||||
PropertyInfo prop = o.GetType().GetProperty(name);
|
||||
if (prop.CanRead) {
|
||||
return prop.GetValue(o);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static Boolean HasAbstract(this Object o, Type type) {
|
||||
if (o.GetType().BaseType == type) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static Boolean HasInterface(this Type o, String type) {
|
||||
foreach (Type item in o.GetInterfaces()) {
|
||||
if (item.Name == type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static void WriteError(String text) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Error.WriteLine("ERROR: " + text);
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user