Skip to content

Commit

Permalink
fixed pattern and input delete crashing app, added "/blink1/logging" …
Browse files Browse the repository at this point in the history
…option to turn on/off logging
  • Loading branch information
todbot committed Jun 11, 2013
1 parent 5b4d4b3 commit a732347
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion windows/Blink1Control/Blink1Control/Blink1Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static string getContentsOfUrl(string url)
}
catch (WebException we) {
// WebException.Status holds useful information
Blink1Server.Log("we:"+we.Message); // + "\n" + we.Status.ToString()); // FIXME:
Blink1Server.Log("webex:"+we.Message); // + "\n" + we.Status.ToString()); // FIXME:
/*
Stream receiveStream = we.Response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
Expand Down
40 changes: 32 additions & 8 deletions windows/Blink1Control/Blink1Control/Blink1Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void saveSettings()
Properties.Settings.Default["inputs"] = JsonConvert.SerializeObject(inputs, Formatting.Indented, jsonSerializerSettings);
Properties.Settings.Default["patterns"] = JsonConvert.SerializeObject(patterns, Formatting.Indented, jsonSerializerSettings);
Properties.Settings.Default["startMinimized"] = startMinimized;
Properties.Settings.Default["logToScreen"] = logToScreen;
Properties.Settings.Default.Save();
}

Expand Down Expand Up @@ -183,6 +184,9 @@ public Blink1Server()
lastColor.GetStringResponse = Ublink1LastColor;
blink1dir.AddFile(lastColor);

Blink1JSONFile logging = new Blink1JSONFile("logging", blink1dir, this);
logging.GetStringResponse = Ublink1Logging;
blink1dir.AddFile(logging);

Blink1JSONFile pattern = new Blink1JSONFile("patterns", blink1dir, this);
pattern.GetStringResponse = Ublink1Pattern;
Expand Down Expand Up @@ -398,6 +402,24 @@ static string Ublink1LastColor(HttpRequest request, Blink1Server blink1Server)
return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
}

// /blink1/logging -- Set logging level (or turn it off)
static string Ublink1Logging(HttpRequest request, Blink1Server blink1Server)
{
string loglevelstr = request.Query.Get("loglevel");
int loglevel = (logToScreen) ? 1 : 0;
if (loglevelstr != null) {
loglevel = int.Parse(loglevelstr, CultureInfo.InvariantCulture);
logToScreen = (loglevel >= 1);
blink1Server.saveSettings();
}
Log("loglevel: " + loglevel);

Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", "logging");
result.Add("loglevel", loglevel);
return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
}

// -----------------------------------------------------------------------------------------------
// color patterns url handling
//
Expand Down Expand Up @@ -447,10 +469,11 @@ static string Ublink1PatternDel(HttpRequest request, Blink1Server blink1Server)
string statusstr = "no pattern by that name";
Blink1Pattern patt = null;
if (pname != null) {
patt = blink1Server.patterns[pname];
patt.stop();
blink1Server.patterns.Remove(pname);
statusstr = "pattern '" + pname + "' removed";
if( blink1Server.patterns.TryGetValue(pname, out patt) ) {
patt.stop();
blink1Server.patterns.Remove(pname);
statusstr = "pattern '" + pname + "' removed";
}
}
blink1Server.saveSettings();

Expand Down Expand Up @@ -539,10 +562,11 @@ static string Ublink1InputDel(HttpRequest request, Blink1Server blink1Server)
string statusstr = "no input by that name";
Blink1Input input = null;
if (iname != null) {
input = blink1Server.inputs[iname];
input.stop();
blink1Server.inputs.Remove(iname);
statusstr = "input '" + iname + "' removed";
if (blink1Server.inputs.TryGetValue(iname, out input)) {
input.stop();
blink1Server.inputs.Remove(iname);
statusstr = "input '" + iname + "' removed";
}
}

blink1Server.saveSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("0.9.7.0")]
[assembly: AssemblyFileVersion("0.9.8.0")]

0 comments on commit a732347

Please sign in to comment.