Permalink
Browse files

win app: url parsing (and thus file & script parsing) looks to be don…

…e, still havent figured out settings with data structs
  • Loading branch information...
1 parent 7184914 commit f7165a6477a26e0005f8d440b5b820f23c94a17f @todbot committed Jan 4, 2013
@@ -5,9 +5,6 @@
<section name="Blink1Control.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
- <startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
- </startup>
<userSettings>
<Blink1Control.Properties.Settings>
<setting name="SomeSettings" serializeAs="String">
@@ -16,6 +13,9 @@
<setting name="hostId" serializeAs="String">
<value>00000000</value>
</setting>
+ <setting name="todtest" serializeAs="String">
+ <value>hello</value>
+ </setting>
</Blink1Control.Properties.Settings>
</userSettings>
</configuration>
@@ -55,6 +55,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
+ <Compile Include="MySettings.cs" />
<Compile Include="Settings.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
@@ -3,11 +3,11 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using System.Runtime.Serialization;
+//using System.Runtime.Serialization;
namespace Blink1Control
{
- [Serializable]
+// [Serializable]
public class Blink1Input
{
/// <summary>
@@ -46,5 +46,17 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
this["hostId"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("hello")]
+ public string todtest {
+ get {
+ return ((string)(this["todtest"]));
+ }
+ set {
+ this["todtest"] = value;
+ }
+ }
}
}
@@ -8,5 +8,8 @@
<Setting Name="hostId" Type="System.String" Scope="User">
<Value Profile="(Default)">00000000</Value>
</Setting>
+ <Setting Name="todtest" Type="System.String" Scope="User">
+ <Value Profile="(Default)">hello</Value>
+ </Setting>
</Settings>
</SettingsFile>
@@ -16,14 +16,19 @@
using Newtonsoft.Json;
using Blink1Lib;
using System.Collections.ObjectModel;
+using System.Text.RegularExpressions;
namespace Blink1Control
{
-
class Blink1Server
{
- HttpWebServer bhI = new HttpWebServer(8934);
+ static int httpPortDefault = 8934;
+ static string iftttEventUrl = "http://api.thingm.com/blink1/events";
+ static float iftttUpdateInterval = 15.0F;
+ static float urlUpdateInterval = 15.0F;
+
+ HttpWebServer bhI = new HttpWebServer( httpPortDefault );
//JTokenWriter jtw = new JTokenWriter();
Blink1 blink1 = new Blink1();
@@ -40,7 +45,20 @@ public Blink1Server()
blink1.regenerateBlink1Id();
-
+ //MySettings.Instance.Parameters["foo"] = "bar";
+ //MySettings.Instance.Save();
+ //MySettings.Instance.Reload();
+
+ //MySettings mysettings = new MySettings();
+ //Blink1Input ainput = new Blink1Input("foobee", "url", "http://shut.up/now", null, null);
+ //ainput.pname = "gosh!";
+ //inputs["golly"] = ainput; // NOTE: this replaces input if already exists
+ //mysettings.Parameters["todgod"] = "jorby";
+ //MySettings.saveSettings(mysettings);
+
+ //string todid = (string) Properties.Settings.Default["todId"];
+ //if (todid != null) {
+ //}
/*
if (Properties.Settings.Default.TheInputs == null) {
Console.WriteLine("*** New Settings! ****\n");
@@ -130,7 +148,6 @@ public Blink1Server()
id2.GetStringResponse = blink1Id2;
blink1dir.AddFile(id2); //add a virtual file for each json method
*/
-
root.AddDirectory(blink1dir);
bhI.Root = root;
@@ -393,15 +410,17 @@ static string blink1InputUrl(HttpRequest request, Blink1Server blink1Server)
{
string pname = request.Query.Get("pname");
string iname = request.Query.Get("iname");
- string url = request.Query.Get("url");
+ string url = request.Query.Get("arg1");
string test = request.Query.Get("test");
- if (iname == null) iname = pname;
- Boolean testmode = (test.Equals("on") || test.Equals("true"));
+ if (pname == null) pname = iname;
+ Boolean testmode = (test==null) ? false : (test.Equals("on") || test.Equals("true"));
string statusstr = "must specifiy 'iname' and 'arg1' (url)";
+ Blink1Input input = null;
if( url != null && iname != null ) {
- Blink1Input input = new Blink1Input(iname, "url", url, null, null);
+ statusstr = "input url";
+ input = new Blink1Input(iname, "url", url, null, null);
input.pname = pname;
blink1Server.updateUrlInput(input);
if (!testmode) {
@@ -411,6 +430,7 @@ static string blink1InputUrl(HttpRequest request, Blink1Server blink1Server)
Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", statusstr);
+ result.Add("input", input);
return JsonConvert.SerializeObject(result, Formatting.Indented);
}
@@ -421,7 +441,8 @@ static string blink1InputIfttt(HttpRequest request, Blink1Server blink1Server)
string iname = request.Query.Get("iname");
string url = request.Query.Get("url");
string test = request.Query.Get("test");
- if (iname == null) iname = pname;
+ if (pname == null) pname = iname;
+ Boolean testmode = (test == null) ? false : (test.Equals("on") || test.Equals("true"));
// FIXME: insert magic here
@@ -470,6 +491,7 @@ public void updateUrlInput(Blink1Input input)
return;
}
string patternstr = parsePatternOrColorString(resp);
+
if (patternstr != null && !patternstr.Equals(input.lastVal)) {
input.lastVal = patternstr;
playPattern(patternstr);
@@ -535,7 +557,21 @@ public Boolean playPattern(string pname)
/// <returns></returns>
public string parsePatternOrColorString(string str)
{
- return str;
+ // read color pattern, can be of form: pattern: "my pattern"
+ Regex patternregex = new Regex(@"\""*pattern\""*:\s*\""(.+?)\""");
+ Match matchp = patternregex.Match(str);
+ if( matchp.Success ) {
+ return matchp.Groups[1].Value;
+ }
+ //
+ Regex hexcoderegex = new Regex(@"(#[A-Fa-f0-9]{6})");
+ Match matchc = hexcoderegex.Match(str.ToUpper());
+ if( matchc.Success ) {
+ return matchc.Groups[1].Value;
+ }
+
+ //Color c = ColorTranslator.FromHtml(str);
+ return null;
}
/// <summary>

0 comments on commit f7165a6

Please sign in to comment.