[NF] v1.1.2 Now complete Emulation of F4G Node

[NF] Possibility to attach internal cron events
This commit is contained in:
BlubbFish 2017-12-08 19:30:29 +00:00
parent 74027d705d
commit 5fa97ea82b
10 changed files with 57 additions and 7 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using BlubbFish.IoT.Zway;
using BlubbFish.Utils;
@ -16,5 +17,12 @@ namespace ZwayBot {
public abstract event ModulEvent Update;
public abstract void Dispose();
public virtual void Interconnect(Dictionary<String, AModul> moduls) {
}
public virtual void SetInterconnection(String param, Action hook) {
}
}
}

View File

@ -11,6 +11,7 @@ namespace ZwayBot.Moduls {
internal class CronJob : AModul, IDisposable {
private DateTime crontime;
private Thread thread;
private List<Tuple<String, Action>> internalCron = new List<Tuple<String, Action>>();
public override event ModulEvent Update;
@ -35,10 +36,15 @@ namespace ZwayBot.Moduls {
if(this.crontime.Minute != DateTime.Now.Minute) {
this.crontime = DateTime.Now;
foreach (String item in this.ini.GetSections()) {
if(ParseCronString(this.ini.GetValue(item, "cron"))) {
if(this.ParseCronString(this.ini.GetValue(item, "cron"))) {
this.SetValues(this.ini.GetValue(item, "set"));
}
}
foreach (Tuple<String, Action> item in this.internalCron) {
if(this.ParseCronString(item.Item1)) {
item.Item2?.Invoke();
}
}
}
Thread.Sleep(100);
}
@ -156,6 +162,10 @@ namespace ZwayBot.Moduls {
return ret.ContainsKey(Int32.Parse(date));
}
public override void SetInterconnection(String cron, Action hook) {
this.internalCron.Add(new Tuple<String, Action>(cron, hook));
}
#region IDisposable Support
private Boolean disposedValue = false;

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Devices;
using BlubbFish.IoT.Zway.Devices.CommandClasses;
@ -13,6 +14,7 @@ namespace ZwayBot.Moduls {
class Flex4Grid : AModul, IDisposable {
private ADataBackend mqtt;
private String household = "";
private Object requestalivelock = new Object();
public override event ModulEvent Update;
@ -114,6 +116,25 @@ namespace ZwayBot.Moduls {
}
}
private void RequestAlive() {
lock (this.requestalivelock) {
HttpWebRequest request = WebRequest.CreateHttp(this.ini.GetValue("f4g", "ping"));
try {
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {}
} catch(Exception) { }
}
}
public override void Interconnect(Dictionary<String, AModul> moduls) {
if (this.ini.GetValue("f4g", "ping") != null) {
foreach (KeyValuePair<String, AModul> item in moduls) {
if (item.Value is CronJob) {
item.Value.SetInterconnection("10,40 * * * *", this.RequestAlive);
}
}
}
}
#region IDisposable Support
private Boolean disposedValue = false;
@ -134,6 +155,8 @@ namespace ZwayBot.Moduls {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -27,11 +27,18 @@ namespace ZwayBot {
this.zw = new ZwayController(InIReader.GetInstance("settings.ini").GetSection("zway"), names, false);
this.zw.Update += this.ZwayDataUpate;
this.ModulLoader();
this.ModulInterconnect();
this.ModulEvents();
this.WaitForShutdown();
this.ModulDispose();
}
private void ModulInterconnect() {
foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Interconnect(this.moduls);
}
}
private void WaitForShutdown() {
while (true) {
System.Threading.Thread.Sleep(100);

View File

@ -1,4 +1,5 @@
using System.Reflection;
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -6,12 +7,12 @@ using System.Runtime.InteropServices;
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("Zway-Bot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Is a Bot for Zwave Devices")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("BlubbFish")]
[assembly: AssemblyProduct("Zway-Bot")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyTrademark("BlubbFish")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
@ -32,7 +33,8 @@ using System.Runtime.InteropServices;
// 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: AssemblyVersion("1.1.2.0")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: NeutralResourcesLanguage("de-DE")]
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.