Permalink
Browse files

win app: pattern settings loading & saving looks to be working

  • Loading branch information...
1 parent a98460c commit 3515c76a9af177ffa588fe01f61c91e8fd17ab36 @todbot committed Jan 6, 2013
@@ -13,6 +13,12 @@
<setting name="hostId" serializeAs="String">
<value>00000000</value>
</setting>
+ <setting name="inputs" serializeAs="String">
+ <value />
+ </setting>
+ <setting name="patterns" serializeAs="String">
+ <value />
+ </setting>
</Blink1Control.Properties.Settings>
</userSettings>
</configuration>
@@ -33,6 +33,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
+ <PropertyGroup>
+ <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
+ </PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
@@ -120,7 +123,7 @@
</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
- <PostBuildEvent>xcopy /i /e /y $(SolutionDir)\..\..\libraries\html $(OutDir)\html</PostBuildEvent>
+ <PostBuildEvent>xcopy /i /e /y $(SolutionDir)\..\..\libraries\html html</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -51,6 +51,10 @@ public string pattern
}
return String.Join(",", sa);
}
+ set
+ {
+ parsePatternStr(value);
+ }
}
public Blink1Server blink1Server { get; set; } //
@@ -72,6 +76,40 @@ public Blink1Pattern(string aName)
/// <returns>true if parsing worked, false otherwise</returns>
public Boolean parsePatternStr(string patternstr)
{
+ List<string> values = patternstr.Split(',').ToList();
+ if ((values.Count() % 2) != 0) { // odd number of elements, so has repeats head value presumably
+ repeats = 0;
+ try { repeats = int.Parse(values[0]); }
+ catch (Exception e) { Console.WriteLine(e.ToString()); }
+ values.RemoveAt(0); // skip over used first element
+ }
+
+ for (int i = 0; i < values.Count(); i += 2) {
+ Color colr = Color.Black;
+ float secs = 0.1F;
+ try {
+ string rgbstr = values[i + 0];
+ string secstr = values[i + 1];
+ colr = ColorTranslator.FromHtml(rgbstr);
+ secs = float.Parse(secstr, CultureInfo.InvariantCulture);
+ }
+ catch (Exception e) {
+ Console.WriteLine(e.ToString());
+ return false;
+ }
+ colors.Add(colr);
+ times.Add(secs);
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Parse a pattern string, setting internal vars as needed
+ /// </summary>
+ /// <param name="patternstr">patternstr format "repeats,color1,color1time,color2,c2time,..."</param>
+ /// <returns>true if parsing worked, false otherwise</returns>
+ public Boolean parsePatternStrOrig(string patternstr)
+ {
string[] values = patternstr.Split(',');
repeats = 0;
try { repeats = int.Parse(values[0]); }
@@ -10,9 +10,9 @@
[assembly: AssemblyTitle("Blink1Control")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyCompany("ThingM")]
[assembly: AssemblyProduct("Blink1Control")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
+[assembly: AssemblyCopyright("Copyright © ThingM 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Oops, something went wrong.
@@ -8,5 +8,11 @@
<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>
+ <Setting Name="patterns" Type="System.String" Scope="User">
+ <Value Profile="(Default)" />
+ </Setting>
</Settings>
</SettingsFile>
@@ -36,55 +36,43 @@ public class Blink1Server
static Blink1 Sblink1 = new Blink1();
+ public Blink1 blink1 { get { return Blink1Server.Sblink1; } private set { } }
+ public static string blink1Id { get { return Blink1Server.Sblink1.blink1Id; } }
+
+ /// <summary>
+ ///
+ /// </summary>
public void loadSettings()
{
- // some notes:
+ // some notes on settings:
// http://stackoverflow.com/questions/1804302/where-is-the-data-for-properties-settings-default-saved
// http://stackoverflow.com/questions/4647796/c-how-to-make-sure-a-settings-variable-exists-before-attempting-to-use-it-from
+ // http://stackoverflow.com/questions/469742/where-are-user-mode-net-settings-stored
+ // On my Win7 box, the settings are stored at:
+ // /c/Users/biff/AppData/Local/ThingM/Blink1Control.vshost.exe_Url_0icskbpuzcclllscwtnuhj23qahf4mn1/1.0.0.0/
// 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"];
- Console.WriteLine("blink1.hostId:" + blink1.hostId);
+ String patternsstr = (string)Properties.Settings.Default["patterns"];
+ Console.WriteLine("patterns: " + patternsstr);
+ patterns = JsonConvert.DeserializeObject<Dictionary<string, Blink1Pattern>>(patternsstr);
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");
- Properties.Settings.Default.TheInputs = new ObservableCollection<Blink1Input>
- {
- new Blink1Input("bob","url",null,null,null),
- new Blink1Input("sue","file",null,null,null),
- new Blink1Input("joe","script",null,null,null)
- };
- Properties.Settings.Default.Save();
- }
- else {
- Console.WriteLine("****\n\n found TheInputs Settings!\n\n **********");
- Console.WriteLine(Properties.Settings.Default.TheInputs.Count.ToString());
- }
-*/
+ Console.WriteLine("blink1.hostId:" + blink1.hostId);
+ Console.WriteLine("blink1.blink1Id:" + blink1.blink1Id);
}
+ /// <summary>
+ ///
+ /// </summary>
public void saveSettings()
{
Properties.Settings.Default["hostId"] = blink1.hostId;
+ Properties.Settings.Default["inputs"] = JsonConvert.SerializeObject(inputs, Formatting.Indented, jsonSerializerSettings);
+ Properties.Settings.Default["patterns"] = JsonConvert.SerializeObject(patterns, Formatting.Indented, jsonSerializerSettings);
Properties.Settings.Default.Save();
}
@@ -94,9 +82,10 @@ public Blink1Server()
inputs = new Dictionary<string, Blink1Input>();
patterns = new Dictionary<string, Blink1Pattern>();
+ Console.WriteLine("Blink1Server!");
+
loadSettings();
- Console.WriteLine("Blink1Server!");
Console.WriteLine("Running on port " + httpPortDefault);
Console.WriteLine("blink1Id:" + blink1Id);
@@ -115,7 +104,7 @@ public Blink1Server()
VirtualDirectory inputdir = new VirtualDirectory("input", blink1dir);
VirtualDirectory patterndir = new VirtualDirectory("pattern", blink1dir);
- // FIXME: the below is completely gross, how to do HTTP routing in .NET?
+ // FIXME: the below is completely gross, how to do good HTTP routing with MiniHttpd?
Blink1JSONFile id = new Blink1JSONFile("id", blink1dir, this);
id.GetStringResponse = Ublink1Id;
blink1dir.AddFile(id); //add a virtual file for each json method
@@ -382,6 +371,7 @@ static string Ublink1PatternAdd(HttpRequest request, Blink1Server blink1Server)
else {
statusstr = "error: need 'pname' and 'pattern' (e.g. '2,#ff00ff,0.5,#00ff00,0.5') argument";
}
+ blink1Server.saveSettings();
Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", statusstr);
@@ -401,6 +391,7 @@ static string Ublink1PatternDel(HttpRequest request, Blink1Server blink1Server)
blink1Server.patterns.Remove(pname);
statusstr = "pattern '" + pname + "' removed";
}
+ blink1Server.saveSettings();
Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", statusstr);
@@ -412,6 +403,8 @@ static string Ublink1PatternDelAll(HttpRequest request, Blink1Server blink1Serve
{
blink1Server.stopAllPatterns();
blink1Server.patterns.Clear();
+ blink1Server.saveSettings();
+
Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", "all patterns removed");
return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
@@ -486,6 +479,8 @@ static string Ublink1InputDel(HttpRequest request, Blink1Server blink1Server)
statusstr = "input '" + iname + "' removed";
}
+ blink1Server.saveSettings();
+
Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", statusstr);
return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
@@ -498,6 +493,8 @@ static string Ublink1InputDelAll(HttpRequest request, Blink1Server blink1Server)
kvp.Value.stop();
}
blink1Server.patterns.Clear();
+ blink1Server.saveSettings();
+
Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", "all patterns removed");
return JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings);
@@ -528,6 +525,8 @@ static string Ublink1InputUrl(HttpRequest request, Blink1Server blink1Server)
}
}
+ blink1Server.saveSettings();
+
Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", statusstr);
result.Add("input", input);
@@ -565,6 +564,8 @@ static string Ublink1InputIfttt(HttpRequest request, Blink1Server blink1Server)
statusstr = "input ifttt";
}
+ blink1Server.saveSettings();
+
Dictionary<string, object> result = new Dictionary<string, object>();
result.Add("status", statusstr);
result.Add("input", input);
@@ -648,14 +649,12 @@ public void fadeToRGB(double secs, Color c)
blink1.close();
}
- public Blink1 blink1 { get { return Blink1Server.Sblink1; } private set { } }
- public static string blink1Id { get { return Blink1Server.Sblink1.blink1Id; } }
+ // currently unimplemented URL API calls
// /blink1/input/file -- Add and Start file watcher on given filepath
-
// /blink1/input/script -- Add and Start command-line script executer
// /blink1/input/scriptlist -- List available scripts to run
@@ -685,7 +684,7 @@ public Blink1JSONFile(string name, IDirectory parent, Blink1Server aBlink1Server
this.blink1Server = aBlink1Server;
GetStringResponse = delegate(HttpRequest input, Blink1Server bs)
{
- return input.ToString();
+ return input.ToString(); //placeholder
};
}
@@ -714,7 +713,7 @@ public void Dispose()
}
- // this is for tod testing, trying to figure out httpwebserver class
+ // TESTING: this is for tod testing, trying to figure out httpwebserver class
public class Blink1Directory : IDirectory
{
string name;
@@ -755,7 +754,40 @@ public IResource GetResource(string name)
public void Dispose()
{
}
- } // end testing class
+ } //TESTING: end testing class
}
-}
+
+
+}
+
+//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");
+ Properties.Settings.Default.TheInputs = new ObservableCollection<Blink1Input>
+ {
+ new Blink1Input("bob","url",null,null,null),
+ new Blink1Input("sue","file",null,null,null),
+ new Blink1Input("joe","script",null,null,null)
+ };
+ Properties.Settings.Default.Save();
+}
+else {
+ Console.WriteLine("****\n\n found TheInputs Settings!\n\n **********");
+ Console.WriteLine(Properties.Settings.Default.TheInputs.Count.ToString());
+}
+*/

0 comments on commit 3515c76

Please sign in to comment.