示例#1
0
        public Json.JsonObject ToJson()
        {
            var result = new Json.JsonObject
            {
                { "uuid", Json.JsonValue.CreateStringValue(uuid.ToString()) },
                { "status", Json.JsonValue.CreateStringValue(status.ToString().ToLower()) },
                { "description", Json.JsonValue.CreateStringValue(description) },
                { "entry", Json.JsonValue.CreateStringValue(entered.ToString()) },
                { "modified", Json.JsonValue.CreateStringValue(lastModified.ToString()) }
            };

            if (!tags.IsEmpty)
            {
                var tags = new Json.JsonArray();
                this.tags.ForEach(tag => tags.Add(Json.JsonValue.CreateStringValue(tag)));
                result.Add("tags", tags);
            }
            foreach (var attribute in this.additionalAttributes)
            {
                result.Add(attribute.Key, attribute.Value);
            }
            return(result);
        }
        public void SaveSettings()
        {
            var alarmsJson = new Windows.Data.Json.JsonArray();

            foreach (var alarm in Alarms)
            {
                var alarmJson = new Windows.Data.Json.JsonObject();
                alarmJson[JsonId]             = JsonValue.CreateStringValue(alarm.Id.ToString());
                alarmJson[JsonEnabled]        = JsonValue.CreateStringValue(alarm.Enabled.ToString());
                alarmJson[JsonTime]           = JsonValue.CreateStringValue(alarm.Time.Ticks.ToString());
                alarmJson[JsonDaysOfWeek]     = JsonValue.CreateStringValue(((int)alarm.DaysOfWeek).ToString());
                alarmJson[JsonAudioFilename]  = JsonValue.CreateStringValue(alarm.AudioFilename);
                alarmJson[JsonImageFilename]  = JsonValue.CreateStringValue(alarm.ImageFilename);
                alarmJson[JsonOccurrence]     = JsonValue.CreateStringValue(alarm.Occurrence.ToString());
                alarmJson[JsonIgnoreHolidays] = JsonValue.CreateBooleanValue(alarm.IgnoreHolidays);
                alarmJson[JsonDateTimeOffset] = JsonValue.CreateStringValue(alarm.DateTimeOffset.ToString(System.Globalization.CultureInfo.InvariantCulture));

                alarmsJson.Add(alarmJson);
            }

            var holidaysJson = new Windows.Data.Json.JsonArray();

            foreach (var holiday in Holidays)
            {
                var holidayJson = new Windows.Data.Json.JsonObject();
                holidayJson[JsonHolidayDate]               = JsonValue.CreateNumberValue(holiday.Date.Ticks);
                holidayJson[JsonHolidayLocalDescription]   = JsonValue.CreateStringValue(holiday.LocalDescription);
                holidayJson[JsonHolidayEnglishDescription] = JsonValue.CreateStringValue(holiday.EnglishDescription);

                holidaysJson.Add(holidayJson);
            }

            // WARNING: maximum size can be 8KB!!!
            Windows.Storage.ApplicationData.Current.LocalSettings.Values[AlarmsKey]       = alarmsJson.Stringify();
            Windows.Storage.ApplicationData.Current.LocalSettings.Values[JsonHolidaysKey] = holidaysJson.Stringify();
        }