private void preloadJsonProfiles() { /* Preload all json profiles */ System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(clockAppConfig.ProfileRoot); DirectoryInfo[] dirs = dir.GetDirectories(); FileInfo[] files = dir.GetFiles(); if (files.Length == 0) { ClockSettings blankSettings = new ClockSettings(); File.WriteAllText(clockAppConfig.ProfileRoot + "\\" + blankSettings.ProfileName + ".json", JsonConvert.SerializeObject(blankSettings)); } files = dir.GetFiles(); foreach (FileInfo file in files) { ClockSettings clock = JsonConvert.DeserializeObject <ClockSettings>(File.ReadAllText(clockAppConfig.ProfileRoot + "\\" + file.Name)); try { cps.Profiles.Add(new ClockProfiles(clock.ProfileName, clock)); } catch (NullReferenceException nre) { } } cps.LoadedProfile = cps.Profiles[0].ProfileSettings; settings = cps.LoadedProfile; }
public void HandleSaveProfile(HttpListenerContext context) { String json = null; ClockSettings myNewClockSettings = new ClockSettings(); HttpListenerRequest request = context.Request; context.Response.AppendHeader("Access-Control-Allow-Origin", "*"); context.Response.AppendHeader("Access-Control-Allow-Headers", "Content-Type, Accept"); try { using (var reader = new StreamReader(request.InputStream)) { json = reader.ReadToEnd(); } } catch { } finally { json = json.Replace("\"on\"", "\"true\"").Replace("\"off\"", "\"false\""); json = RepairJson(json); myNewClockSettings = JsonConvert.DeserializeObject <ClockSettings>(json); File.WriteAllText(@"profiles\" + myNewClockSettings.ProfileName + ".json", JsonConvert.SerializeObject(myNewClockSettings, Formatting.Indented)); _myClockDisplay.cps.Profiles.Add(new ClockProfiles(myNewClockSettings.ProfileName, myNewClockSettings)); _myClockDisplay.clockSettingsBindingSource.Clear(); _myClockDisplay.clockSettingsBindingSource.Add(myNewClockSettings); _myClockDisplay.settings = myNewClockSettings; } this.SendTextResponse(context, JsonConvert.SerializeObject(myNewClockSettings)); }
public ClockDisplay() { InitializeComponent(); if ( !Directory.Exists(genSettings.ProfilePath) ) { Directory.CreateDirectory(genSettings.ProfilePath); } if (File.Exists(genSettings.ProfilePath + "\\settings.json")) { string clockSettings = File.ReadAllText(genSettings.ProfilePath + "\\settings.json"); genSettings = JsonConvert.DeserializeObject<GeneralSettings>(clockSettings); // Determine the last used profile and whether it falls in the necessary time period or not if (!genSettings.LastProfile.Equals("")) { DateTime profileDate = DateTime.Parse(genSettings.LastProfileDate); if (profileDate.ToShortDateString().Equals(DateTime.Now.ToShortDateString())) { if (File.Exists(genSettings.ProfilePath + "\\" + genSettings.LastProfile + ".json")) { clockSettings = File.ReadAllText(@genSettings.ProfilePath + "\\" + genSettings.LastProfile + ".json"); clockSettingsBindingSource.Clear(); settings = JsonConvert.DeserializeObject<ClockSettings>(clockSettings); clockSettingsBindingSource.Add(settings); clockSettingsBindingSource.ResetBindings(false); } } } } pnlClock.Invalidate(); }
public void HandleTestSave(HttpListenerContext context) { WebClient web = new WebClient(); ClockSettings testClock = new ClockSettings(); testClock.ProfileName = "REST Test 1"; web.UploadString("http://localhost:1234/saveprofile", "POST", JsonConvert.SerializeObject(testClock)); context.Response.AppendHeader("Access-Control-Allow-Origin", "*"); this.SendTextResponse(context, "Test Comlete!"); }
public ClockConfig(ClockDisplay display, BindingSource source, GeneralSettings settings) { InitializeComponent(); this.myDisplay = display; this.settings = settings; if (File.Exists(@settings.ProfilePath + "\\settings.json")) { string clockSettings = File.ReadAllText(@settings.ProfilePath + "\\settings.json"); settings = JsonConvert.DeserializeObject<GeneralSettings>(clockSettings); } else { settings = new GeneralSettings(); settings.writeProfile(settings); } if (!System.IO.Directory.Exists(@settings.ProfilePath)) { System.IO.Directory.CreateDirectory(@settings.ProfilePath); } PaintListView(@settings.ProfilePath); if (source.Current != null) { loadedClock = (ClockSettings)source.Current; clockSettingsBindingSource.Add(source.Current); clockSettingsBindingSource.ResetBindings(false); populatePresentationList(); listView1.FindItemWithText(loadedClock.ProfileName).Selected = true; listView1.Select(); } settings.PropertyChanged += this.HandleSettingsChanged; generalSettingsBindingSource.Add(settings); }
private void loadProfile(string profilename) { string clockJson = null; clockSettingsBindingSource.Clear(); myDisplay.clockSettingsBindingSource.Clear(); clockJson = File.ReadAllText(@settings.ProfilePath + "\\" + profilename); loadedClock = JsonConvert.DeserializeObject<ClockSettings>(clockJson); loadedClock.PropertyChanged += this.HandlePropertyChanged; clockSettingsBindingSource.Add(loadedClock); myDisplay.clockSettingsBindingSource.Add(loadedClock); settings.LastProfile = loadedClock.ProfileName; settings.LastProfileDate = DateTime.Now.ToString(); generalSettingsBindingSource.ResetBindings(false); populatePresentationList(); }
private void createProfile(string profileName) { ClockSettings clock = new ClockSettings(); clock.ProfileName = profileName; clock.writeProfile(@settings.ProfilePath, clock); this.PaintListView(@settings.ProfilePath); loadProfile(clock.ProfileName + ".json"); }
public void writeProfile(string profilePath, ClockSettings profile) { string json = JsonConvert.SerializeObject(profile, Formatting.Indented); File.WriteAllText(profilePath + "\\" + profile.ProfileName + ".json", json); }
public ClockProfiles(string profileName, ClockSettings profileSettings) { this.profileName = profileName; this.profileSettings = profileSettings; }
private void btnConfig_Click(object sender, EventArgs e) { ClockConfig myConfig = new ClockConfig(this, clockSettingsBindingSource, genSettings); myConfig.StartPosition = FormStartPosition.CenterParent; myConfig.ShowDialog(); myConfig.Dispose(); if ((ClockSettings)clockSettingsBindingSource.Current != null) { this.settings = (ClockSettings)clockSettingsBindingSource.Current; } pnlTopText.Invalidate(); pnlBottomText.Invalidate(); }