コード例 #1
0
        public void HandleLoadProfile(HttpListenerContext context)
        {
            context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
            var profileName = context.Request.QueryString["profile"];

            ClockProfiles response = _myClockDisplay.cps.Profiles.Find(r => r.ProfileName == profileName);

            _myClockDisplay.cps.LoadedProfile = response.ProfileSettings;

            _myClockDisplay.clockSettingsBindingSource.Clear();
            _myClockDisplay.clockSettingsBindingSource.Add(_myClockDisplay.cps.LoadedProfile);
            _myClockDisplay.settings = _myClockDisplay.cps.LoadedProfile;

            this.SendTextResponse(context, "Profile loaded!");
        }
コード例 #2
0
        public void HandleUpdateProfile(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);

                ClockProfiles response = _myClockDisplay.cps.Profiles.Find(r => r.ProfileName == myNewClockSettings.ProfileName);

                response.ProfileSettings = JsonConvert.DeserializeObject <ClockSettings>(json);

                File.WriteAllText(@"profiles\" + myNewClockSettings.ProfileName + ".json", JsonConvert.SerializeObject(myNewClockSettings, Formatting.Indented));

                if (response.ProfileSettings.ProfileName == _myClockDisplay.cps.LoadedProfile.ProfileName)
                {
                    _myClockDisplay.cps.LoadedProfile = myNewClockSettings;
                    _myClockDisplay.clockSettingsBindingSource.Clear();
                    _myClockDisplay.clockSettingsBindingSource.Add(myNewClockSettings);
                    _myClockDisplay.settings = myNewClockSettings;
                }
            }

            this.SendTextResponse(context, JsonConvert.SerializeObject(myNewClockSettings));
        }