Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

win app: made settings loading more robust hopefully, removed blink1s…

…erver from json properties
  • Loading branch information...
commit 8b971ff2504802cb32393ea2ad5aeaf6ba9d67b9 1 parent 59981f1
@todbot authored
View
6 windows/Blink1Control/Blink1Control/App.config
@@ -10,9 +10,6 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<userSettings>
<Blink1Control.Properties.Settings>
- <setting name="hostId" serializeAs="String">
- <value>00000000</value>
- </setting>
<setting name="inputs" serializeAs="String">
<value />
</setting>
@@ -22,6 +19,9 @@
<setting name="logToScreen" serializeAs="String">
<value>False</value>
</setting>
+ <setting name="hostId" serializeAs="String">
+ <value>00000000</value>
+ </setting>
</Blink1Control.Properties.Settings>
</userSettings>
</configuration>
View
35 windows/Blink1Control/Blink1Control/Blink1Input.cs
@@ -22,8 +22,11 @@ public class Blink1Input
public static string iftttEventUrl = "http://api.thingm.com/blink1/events";
//public static float iftttUpdateInterval = 15.0F;
//public static float urlUpdateInterval = 15.0F;
+ // FIXME: hacks
+ public static DateTime iftttLastTime;
+ public static int iftttUpdateInterval = 15;
+ public static string iftttLastContent;
- public Blink1Server blink1Server { private get; set; }
/// <summary>
/// Name of the input
/// </summary>
@@ -46,27 +49,19 @@ public class Blink1Input
private DateTime lastDateTime;
public string lastTime
{
- get
- {
- return ConvertToUnixTimestamp(lastDateTime).ToString();
- }
- set
- {
+ get { return ConvertToUnixTimestamp(lastDateTime).ToString(); }
+ set {
double v=0;
Double.TryParse(value, out v);
lastDateTime = ConvertFromUnixTimestamp(v);
}
}
- //private int updateInterval;
-
// holder of last valid response/content
private string lastContent;
- // FIXME: hacks
- public static DateTime iftttLastTime;
- public static int iftttUpdateInterval = 15;
- public static string iftttLastContent;
+ [JsonIgnore]
+ public Blink1Server blink1Server { private get; set; }
/// <summary>
/// Constructor
@@ -134,13 +129,16 @@ public Boolean update()
/// <returns>true if pattern was played from input match</returns>
public Boolean updateIftttInput()
{
- if (iftttLastContent==null) return false;
-
+ if (iftttLastContent==null ) {
+ lastVal = "could not connect";
+ return false;
+ }
+
string rulename = arg1;
IftttResponse iftttResponse = JsonConvert.DeserializeObject<IftttResponse>( iftttLastContent );
if (iftttResponse.event_count > 0) {
- long lastsecs = (long) ConvertToUnixTimestamp(lastDateTime);
+ long lastsecs = (long)ConvertToUnixTimestamp(lastDateTime);
foreach (IftttEvent ev in iftttResponse.events) {
long evdate = long.Parse(ev.date);
string evname = ev.name;
@@ -148,7 +146,7 @@ public Boolean updateIftttInput()
possibleVals = evname; // FIXME: should be array
//Blink1Server.Log("--ifttt ev.name:" + evname);
if (rulename.Equals(evname)) {
- Blink1Server.Log("---ifttt match: evdate:"+evdate+", lastsecs:"+lastsecs+", dt:"+(evdate-lastsecs));
+ Blink1Server.Log("---ifttt match: evdate:" + evdate + ", lastsecs:" + lastsecs + ", dt:" + (evdate - lastsecs));
lastDateTime = ConvertFromUnixTimestamp(evdate);
if (evdate > lastsecs) {
blink1Server.playPattern(pname);
@@ -157,6 +155,9 @@ public Boolean updateIftttInput()
}
}
}
+ else {
+ lastVal = "no IFTTT data";
+ }
return false;
}
View
3  windows/Blink1Control/Blink1Control/Blink1Pattern.cs
@@ -8,6 +8,8 @@
using System.Collections.Specialized;
using System.Drawing;
using System.Globalization;
+using Newtonsoft.Json;
+
using Blink1Lib;
@@ -57,6 +59,7 @@ public string pattern
}
}
+ [JsonIgnore]
public Blink1Server blink1Server { get; set; } //
public Blink1Pattern(string aName)
View
39 windows/Blink1Control/Blink1Control/Blink1Server.cs
@@ -41,7 +41,9 @@ public class Blink1Server
public Blink1 blink1 { get { return Blink1Server.Sblink1; } private set { } }
public static string blink1Id { get { return Blink1Server.Sblink1.blink1Id; } }
- /* // idea for removing Blink1Server property from Blink1Input instances
+ /*
+ // idea for removing Blink1Server property from Blink1Input instances
+ // this seems ugly but I want to exclude the blink1Server property from Blink1Pattern & Blink1Input
public static Blink1Server staticBlink1Server;
public static void setBlink1Server(Blink1Server b1s)
{ staticBlink1Server = b1s; }
@@ -49,7 +51,7 @@ public static Blink1Server getBlink1Server(Blink1Server b1s)
{ return staticBlink1Server; }
*/
- public static bool logToScreen;
+ public static bool logToScreen; // FIXME: this is the wrong (non-MS) way to do this
/// <summary>
/// Extremely simplistic logging system. one method only!
@@ -75,22 +77,28 @@ public void loadSettings()
// we assume hostId is always set, it defaults to "00000000" on fresh installation
// (or we could not set it in Properties and check for KeyNotFoundException)
- blink1.hostId = (string)Properties.Settings.Default["hostId"];
-
- logToScreen = (bool) Properties.Settings.Default["logToScreen"];
-
- String patternsstr = (string)Properties.Settings.Default["patterns"];
- String inputsstr = (string)Properties.Settings.Default["inputs"];
- Log("patterns: " + patternsstr);
- Log("inputs: " + inputsstr);
- patterns = JsonConvert.DeserializeObject<Dictionary<string, Blink1Pattern>>(patternsstr);
- inputs = JsonConvert.DeserializeObject<Dictionary<string, Blink1Input>>(inputsstr);
- if (patterns == null) {
+ try {
+ blink1.hostId = (string)Properties.Settings.Default["hostId"];
+ logToScreen = (bool)Properties.Settings.Default["logToScreen"];
+ String patternsstr = (string)Properties.Settings.Default["patterns"];
+ String inputsstr = (string)Properties.Settings.Default["inputs"];
+ Log("patterns: " + patternsstr);
+ Log("inputs: " + inputsstr);
+ patterns = JsonConvert.DeserializeObject<Dictionary<string, Blink1Pattern>>(patternsstr);
+ inputs = JsonConvert.DeserializeObject<Dictionary<string, Blink1Input>>(inputsstr);
+ if (patterns == null)
+ patterns = new Dictionary<string, Blink1Pattern>();
+ if (inputs == null)
+ inputs = new Dictionary<string, Blink1Input>();
+ }
+ catch (SettingsPropertyNotFoundException spnfe) {
+ Console.Write("Settings not found: " + spnfe.Message);
+ blink1.hostId = "00000000";
+ logToScreen = true;
patterns = new Dictionary<string, Blink1Pattern>();
- }
- if (inputs == null) {
inputs = new Dictionary<string, Blink1Input>();
}
+
foreach (KeyValuePair<string, Blink1Input> kvp in inputs) {
kvp.Value.blink1Server = this;
}
@@ -119,6 +127,7 @@ public void saveSettings()
public Blink1Server()
{
Log("Blink1Server!");
+ //Blink1Server.setBlink1Server(this);
blink1.open();
loadSettings();
View
24 windows/Blink1Control/Blink1Control/Properties/Settings.Designer.cs
@@ -25,18 +25,6 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("00000000")]
- public string hostId {
- get {
- return ((string)(this["hostId"]));
- }
- set {
- this["hostId"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string inputs {
get {
@@ -70,5 +58,17 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
this["logToScreen"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("00000000")]
+ public string hostId {
+ get {
+ return ((string)(this["hostId"]));
+ }
+ set {
+ this["hostId"] = value;
+ }
+ }
}
}
View
6 windows/Blink1Control/Blink1Control/Properties/Settings.settings
@@ -2,9 +2,6 @@
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Blink1Control.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
- <Setting Name="hostId" Type="System.String" Scope="User">
- <Value Profile="(Default)">00000000</Value>
- </Setting>
<Setting Name="inputs" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
@@ -14,5 +11,8 @@
<Setting Name="logToScreen" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
+ <Setting Name="hostId" Type="System.String" Scope="User">
+ <Value Profile="(Default)">00000000</Value>
+ </Setting>
</Settings>
</SettingsFile>
Please sign in to comment.
Something went wrong with that request. Please try again.