public static JsonObject ToJson(Dominion.GameDescription gameDescription, int starRating) { JsonObject root = new Windows.Data.Json.JsonObject(); root.Add(jsonNameDeck, ToJson(gameDescription)); JsonArray expansionArray = new JsonArray(); Dominion.Expansion[] presentExpansions; Dominion.Expansion[] missingExpansions; gameDescription.GetRequiredExpansions(out presentExpansions, out missingExpansions); foreach (var expansion in presentExpansions) { JsonObject expansionObject = new JsonObject(); expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName())); expansionObject.Add("present", JsonValue.CreateBooleanValue(true)); expansionArray.Add(expansionObject); } foreach (var expansion in missingExpansions) { JsonObject expansionObject = new JsonObject(); expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName())); expansionObject.Add("present", JsonValue.CreateBooleanValue(false)); expansionArray.Add(expansionObject); } root.Add(jsonNameRequiredExpansions, expansionArray); root.Add(jsonNameRating, JsonValue.CreateNumberValue(starRating)); return root; }
public static JsonObject ToJson(Dominion.GameDescription gameDescription) { JsonObject root = new Windows.Data.Json.JsonObject(); root.Add(jsonNameUseShelters, JsonValue.CreateBooleanValue(gameDescription.useShelters)); root.Add(jsonNameUseColonyAndPlatinum, JsonValue.CreateBooleanValue(gameDescription.useColonyAndPlatinum)); string banePileName = gameDescription.BanePileProgrammaticName(); if (banePileName != null) { root.Add(jsonNameBane, JsonValue.CreateStringValue(banePileName)); } JsonArray kingdomArray = new JsonArray(); foreach (var cardName in gameDescription.KingdomPileProgramaticNames()) { kingdomArray.Add(JsonValue.CreateStringValue(cardName)); } root.Add(jsonNameKingdomPiles, kingdomArray); JsonArray eventArray = new JsonArray(); foreach (var cardName in gameDescription.EventProgramaticNames()) { eventArray.Add(JsonValue.CreateStringValue(cardName)); } root.Add(jsonNameEvents, eventArray); return root; }
public static JsonObject ToJson(Dominion.GameDescription gameDescription, int starRating) { JsonObject root = new Windows.Data.Json.JsonObject(); root.Add(jsonNameDeck, ToJson(gameDescription)); JsonArray expansionArray = new JsonArray(); Dominion.Expansion[] presentExpansions; Dominion.Expansion[] missingExpansions; gameDescription.GetRequiredExpansions(out presentExpansions, out missingExpansions); foreach (var expansion in presentExpansions) { JsonObject expansionObject = new JsonObject(); expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName())); expansionObject.Add("present", JsonValue.CreateBooleanValue(true)); expansionArray.Add(expansionObject); } foreach (var expansion in missingExpansions) { JsonObject expansionObject = new JsonObject(); expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName())); expansionObject.Add("present", JsonValue.CreateBooleanValue(false)); expansionArray.Add(expansionObject); } root.Add(jsonNameRequiredExpansions, expansionArray); root.Add(jsonNameRating, JsonValue.CreateNumberValue(starRating)); return(root); }
public void TestToJson() { // given var rawUUID = "296d835e-8f85-4224-8f36-c612cad1b9f8"; var description = "test"; var enteredDate = new WPTaskClient.Data.Timestamp(new DateTime(2017, 7, 25, 21, 29, 0)); var modifiedDate = new WPTaskClient.Data.Timestamp(new DateTime(2017, 7, 28, 13, 25, 0)); var tags = new List <string>() { "first", "second" }.ToImmutableList(); var additionalAttributes = new Dictionary <string, Json.IJsonValue>() { { "estimate", Json.JsonValue.CreateStringValue("1w") } }.ToImmutableDictionary(); // when var entry = new WPTaskClient.Data.Task(Guid.Parse(rawUUID), WPTaskClient.Data.TaskStatus.Pending, description, enteredDate, modifiedDate, tags, additionalAttributes); var json = entry.ToJson(); // then var expectedJson = new Json.JsonObject() { { "uuid", Json.JsonValue.CreateStringValue(rawUUID) }, { "status", Json.JsonValue.CreateStringValue("pending") }, { "entry", Json.JsonValue.CreateStringValue("20170725T212900Z") }, { "modified", Json.JsonValue.CreateStringValue("20170728T132500Z") }, { "description", Json.JsonValue.CreateStringValue(description) }, { "estimate", Json.JsonValue.CreateStringValue("1w") }, { "tags", new Json.JsonArray() { Json.JsonValue.CreateStringValue("first"), Json.JsonValue.CreateStringValue("second") } }, }; AssertJsonEqual(json, expectedJson); }
private void ProcessObject(JsonObject jsonObj, Windows.Data.Json.JsonObject jsonData) { foreach (var item in jsonData) { JsonObject value = null; Process(out value, item.Value); jsonObj.Add(item.Key, value); } }
public override void ReadData(Windows.Data.Json.JsonObject jsonObj) { this.Id = (int)jsonObj["Id"].GetNumber(); this.Name = jsonObj["Name"].GetString(); this.Description = jsonObj["Description"].ValueType != JsonValueType.Null? jsonObj["Description"].GetString():null; this.WebSite = jsonObj["WebSite"].ValueType != JsonValueType.Null? jsonObj["WebSite"].GetString():null; }
public void parseJson(string response) { Windows.Data.Json.JsonObject root = Windows.Data.Json.JsonObject.Parse(response); IJsonValue json; if (root.TryGetValue("new_id", out json)) { //JsonArray array = json.GetArray(); newPicId = json.GetNumber(); } }
private static async Task <MethodResponse> OnSampleMethod2Called(MethodRequest methodRequest, object userContext) { Debug.WriteLine("SampleMethod2 has been called: Data: " + methodRequest.DataAsJson); var jso = new Windows.Data.Json.JsonObject(); jso.Add(new KeyValuePair <string, Windows.Data.Json.IJsonValue>("hep", Windows.Data.Json.JsonValue.CreateStringValue("ajjaja"))); //jso.Stringify(); return(new MethodResponse(Encoding.UTF8.GetBytes(jso.Stringify()), 200)); }
public static JsonObject ToJson(Dominion.GameDescription gameDescription) { JsonObject root = new Windows.Data.Json.JsonObject(); root.Add(jsonNameUseShelters, JsonValue.CreateBooleanValue(gameDescription.useShelters)); root.Add(jsonNameUseColonyAndPlatinum, JsonValue.CreateBooleanValue(gameDescription.useColonyAndPlatinum)); string banePileName = gameDescription.BanePileProgrammaticName(); if (banePileName != null) { root.Add(jsonNameBane, JsonValue.CreateStringValue(banePileName)); } JsonArray kingdomArray = new JsonArray(); foreach (var cardName in gameDescription.KingdomPileProgramaticNames()) { kingdomArray.Add(JsonValue.CreateStringValue(cardName)); } root.Add(jsonNameKingdomPiles, kingdomArray); JsonArray eventArray = new JsonArray(); foreach (var cardName in gameDescription.EventProgramaticNames()) { eventArray.Add(JsonValue.CreateStringValue(cardName)); } root.Add(jsonNameEvents, eventArray); JsonArray projectArray = new JsonArray(); foreach (var cardName in gameDescription.ProjectProgramaticNames()) { projectArray.Add(JsonValue.CreateStringValue(cardName)); } root.Add(jsonNameProjects, projectArray); JsonArray landmarkArray = new JsonArray(); foreach (var cardName in gameDescription.LandmarkProgramaticNames()) { projectArray.Add(JsonValue.CreateStringValue(cardName)); } root.Add(jsonNameLandmarks, projectArray); return(root); }
public static Task FromJson(Json.JsonObject json) { var uuid = Guid.Parse(json.GetNamedString("uuid")); var status = statusLUT[json.GetNamedString("status")]; var description = json.GetNamedString("description"); var entered = new Timestamp(json.GetNamedString("entry")); var lastModified = new Timestamp(json.GetNamedString("modified")); var tags = noTags; if (json.ContainsKey("tags")) { tags = ImmutableList.CreateRange(json.GetNamedArray("tags").Select(value => value.GetString())); } var additionalAttributes = ImmutableDictionary.CreateRange(json.Where(entry => !handledAttributes.Contains(entry.Key))); return(new Task(uuid, status, description, entered, lastModified, tags, additionalAttributes)); }
public static JsonObject ToJsonForGetExpansions(AppDataContext appDataContext) { JsonObject root = new Windows.Data.Json.JsonObject(); JsonArray expansionArray = new JsonArray(); foreach (var expansion in appDataContext.Expansions) { JsonObject expansionObject = new JsonObject(); expansionObject.Add("name", JsonValue.CreateStringValue(expansion.DominionExpansion.ToProgramaticName())); expansionObject.Add("present", JsonValue.CreateBooleanValue(expansion.IsEnabled.Value)); expansionArray.Add(expansionObject); } root.Add(jsonNameRequiredExpansions, expansionArray); return(root); }
public static JsonObject ToJsonForGetExpansions(AppDataContext appDataContext) { JsonObject root = new Windows.Data.Json.JsonObject(); JsonArray expansionArray = new JsonArray(); foreach (var expansion in appDataContext.Expansions) { JsonObject expansionObject = new JsonObject(); expansionObject.Add("name", JsonValue.CreateStringValue(expansion.DominionExpansion.ToProgramaticName())); expansionObject.Add("present", JsonValue.CreateBooleanValue(expansion.IsEnabled.Value)); expansionArray.Add(expansionObject); } root.Add(jsonNameRequiredExpansions, expansionArray); return root; }
public override void ReadData(Windows.Data.Json.JsonObject jsonObj) { this.Id = (int)jsonObj["Id"].GetNumber(); this.Code = jsonObj["Code"].GetString(); this.NoteType = (NoteType)jsonObj["NoteType"].GetNumber(); if (jsonObj["Open"].ValueType != JsonValueType.Null) { this.Open = DateTime.Parse(jsonObj["Open"].GetString()); } if (jsonObj["Close"].ValueType != JsonValueType.Null) { this.Close = DateTime.Parse(jsonObj["Close"].GetString()); } if (jsonObj["OpenPrice"].ValueType != JsonValueType.Null) { this.OpenPrice = (decimal)jsonObj["OpenPrice"].GetNumber(); } if (jsonObj["ClosePrice"].ValueType != JsonValueType.Null) { this.ClosePrice = (decimal)jsonObj["ClosePrice"].GetNumber(); } if (jsonObj["OpenValue"].ValueType != JsonValueType.Null) { this.OpenValue = (decimal)jsonObj["OpenValue"].GetNumber(); } if (jsonObj["CloseValue"].ValueType != JsonValueType.Null) { this.CloseValue = (decimal)jsonObj["CloseValue"].GetNumber(); } this.Count = (int)jsonObj["Count"].GetNumber(); }
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(); }
public FotballTippingData(Windows.Data.Json.JsonObject jsonObjectLotto, string spillnavn) : base(spillnavn) { this.jsonObjectLotto = jsonObjectLotto; System.Diagnostics.Debug.WriteLine("fotballtipping"); var b = jsonObjectLotto["gameDays"].GetArray(); foreach (JsonValue obj in b) { { if (obj.ValueType != JsonValueType.Null) { JsonObject ob1 = obj.GetObject(); string dd1 = ob1["drawDate"].GetString(); System.Diagnostics.Debug.WriteLine(dd1); DateTime trekningspunkt2 = DateTime.ParseExact(dd1, "yyyy,MM,dd,HH,mm,ss", CultureInfo.CurrentCulture); string trekningspunktAsString2 = trekningspunkt2.ToString("dddd d. MMMM", CultureInfo.CurrentCulture); JsonArray events = ob1["events"].GetArray(); StringBuilder kamper = new StringBuilder(); String kampstatus = ""; int tellert = 1; HashSet <string> statusMap = new HashSet <string>(); StringBuilder liveResultat = new StringBuilder(); StringBuilder liveResultatStatus = new StringBuilder(); foreach (JsonValue ev in events) { JsonArray arra = ev.GetArray(); String lag1 = arra[1].GetString(); String lag2 = arra[2].GetString(); String kamp = lag1 + " - " + lag2; if (kamp.Count() > 39) { kamp = kamp.Substring(0, 39) + "."; } kamper.Append(String.Format("{0}\r\n", kamp)); liveResultat.Append(String.Format("{0}\r\n", arra[5].GetString())); String klokkeSlettAsString = arra[6].GetString(); DateTime kampStartDate = DateTime.ParseExact(klokkeSlettAsString, "yyyy,MM,dd,HH,mm,ss", CultureInfo.CurrentCulture); string kampStartKlokkeslett = kampStartDate.ToString("HH.mm", CultureInfo.CurrentCulture); string enKampStatus = arra[4].GetString(); enKampStatus = translateKamptatus(enKampStatus); if ("Ikke startet".Equals(enKampStatus) || "Not started".Equals(enKampStatus)) { enKampStatus += ": " + kampStartKlokkeslett; } liveResultatStatus.Append(String.Format("({0})\r\n", enKampStatus)); if (tellert % 3 == 0) { kamper.Append("\r\n"); liveResultat.Append("\r\n"); liveResultatStatus.Append("\r\n"); } tellert++; String status = arra[4].GetString(); statusMap.Add(status); } Boolean alleKamperErFerdig = false; if ((statusMap.Contains("Slutt") || (statusMap.Contains("Trukket")) && statusMap.Count == 1) || (statusMap.Contains("Trukket") && statusMap.Contains("Slutt")) && statusMap.Count < 3) { alleKamperErFerdig = true; } if (alleKamperErFerdig) { if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName.Equals("nb")) { kampstatus = "Alle kamper er ferdig"; } else { kampstatus = "All matches are finished"; } } else { if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName.Equals("nb")) { kampstatus = "Ikke alle kamper er ferdig"; } else { kampstatus = "Not all matches are finished"; } } StringBuilder halvtid = new StringBuilder(); StringBuilder heltid = new StringBuilder(); StringBuilder premieTekst = new StringBuilder(); StringBuilder premieVerdi = new StringBuilder(); StringBuilder antallVinnere = new StringBuilder(); //initialiseres ikke med linjeskift fordi linjeskift fordi siste element i linja StringBuilder premieTekstFullTid = new StringBuilder(); StringBuilder premieVerdiFullTid = new StringBuilder(); StringBuilder antallVinnereFullTid = new StringBuilder(); int teller = 0; JsonArray results = ob1["matchStages"].GetArray(); foreach (JsonValue ev in results) { String resultatText = null; JsonObject r2 = ev.GetObject(); JsonArray res2 = r2["results"].GetArray(); resultatText = GetFotballtippingResultater(res2); if (teller == 0) { halvtid.Append(resultatText); } else { heltid.Append(resultatText); } teller++; res2 = r2["prizes"].GetArray(); IList abba = res2.Reverse().ToList(); foreach (JsonValue j2 in abba) { if (teller == 1) { JsonArray j22 = j2.GetArray(); String text = String.Join("", j22.Select((x, i) => i == 0 ? x.GetString().Replace("av", CultureInfo.CurrentCulture.TwoLetterISOLanguageName.Equals("nb") ? "av" : "of") : i == 1 ? "" : "\r\n")); premieTekst.Append(text); String text2 = String.Join("", j22.Select((x, i) => i == 1 ? x.ValueType == JsonValueType.String ? x.GetString() : x.GetNumber() == 0 ? "-" : x.GetNumber().ToString("### ### ### kr") : i == 0 ? "" : "\r\n")); premieVerdi.Append(text2); String antallVinnerePrRette = String.Join("", j22.Select((x, i) => i == 2 ? x.ValueType == JsonValueType.String ? x.GetString() : x.GetNumber() == 0 ? "0\r\n" : x.GetNumber().ToString("### ###\r\n") : "")); antallVinnere.Append(antallVinnerePrRette); } if (teller == 2) { JsonArray j22 = j2.GetArray(); String text = String.Join("", j22.Select((x, i) => i == 0 ? x.GetString().Replace("av", CultureInfo.CurrentCulture.TwoLetterISOLanguageName.Equals("nb") ? "av" : "of") : i == 1 ? "" : "\r\n")); premieTekstFullTid.Append(text); String text2 = String.Join("", j22.Select((x, i) => i == 1 ? x.ValueType == JsonValueType.String ? x.GetString() : x.GetNumber() == 0 ? "-" : x.GetNumber().ToString("### ### ### kr") : i == 0 ? "" : "\r\n")); premieVerdiFullTid.Append(text2); String antallVinnerePrRette = String.Join("", j22.Select((x, i) => i == 2 ? x.ValueType == JsonValueType.String ? x.GetString() : x.GetNumber() == 0 ? "0\r\n" : x.GetNumber().ToString("### ###\r\n") : "")); antallVinnereFullTid.Append(antallVinnerePrRette); } } } this.Heltid = heltid.ToString(); this.Kamper = kamper.ToString(); this.Halvtid = halvtid.ToString(); this.Trekningsdato = trekningspunktAsString2; this.Premienavn = premieTekst.ToString(); this.Premietall = premieVerdi.ToString(); this.Kampstatus = kampstatus; this.LiveResultat = liveResultat.ToString(); this.LiveResultatStatus = liveResultatStatus.ToString(); this.AntallVinnere = antallVinnere.ToString(); this.PremienavnFullTid = premieTekstFullTid.ToString(); this.PremietallFullTid = premieVerdiFullTid.ToString(); this.AntallVinnereFullTid = antallVinnereFullTid.ToString(); } } } }
/// <summary> /// This function extracts access_token from the response returned from web authentication broker /// and uses that token to get user information using facebook graph api. /// </summary> /// <param name="responseData">responseData returned from AuthenticateAsync result.</param> private async Task GetFacebookUserNameAsync(string responseData) { var decoder = new WwwFormUrlDecoder(responseData); var error = decoder.TryGetValue("error"); if (error != null) { FacebookUserName.Text = $"Error: {error}"; return; } // You can store access token locally for further use. string access_token = decoder[0].Value; this.fb_token = decoder[0].Value; string expires_in = decoder.TryGetValue("expires_in"); // expires_in is optional Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient(); Uri uri = new Uri($"https://graph.facebook.com/me?fields=id,name,picture,birthday&access_token={Uri.EscapeDataString(access_token)}"); HttpGetStringResult result = await httpClient.TryGetStringAsync(uri); if (result.Succeeded) { Windows.Data.Json.JsonObject userInfo = Windows.Data.Json.JsonObject.Parse(result.Value).GetObject(); FacebookUserName.Text = userInfo.GetNamedString("name"); this.userID = userInfo.GetNamedString("id"); } else { FacebookUserName.Text = "Error contacting Facebook"; } Windows.Web.Http.HttpClient httpClient2 = new Windows.Web.Http.HttpClient(); Uri uri2 = new Uri($"https://graph.facebook.com/{this.userID}/accounts?fields=name,access_token&access_token={this.fb_token}"); HttpGetStringResult myresult = await httpClient.TryGetStringAsync(uri2); if (myresult.Succeeded) { Windows.Data.Json.JsonObject userInfo2 = Windows.Data.Json.JsonObject.Parse(myresult.Value).GetObject(); this.Page_token = userInfo2["data"].GetArray()[0].GetObject().GetNamedString("access_token"); } else { Debug.Write("man ta osso!"); } Windows.Web.Http.HttpClient httpClient3 = new Windows.Web.Http.HttpClient(); Uri uri3 = new Uri($"https://graph.facebook.com/{this.userID}/accounts?access_token={this.fb_token}"); HttpGetStringResult result3 = await httpClient.TryGetStringAsync(uri3); if (result3.Succeeded) { Windows.Data.Json.JsonObject userInfo = Windows.Data.Json.JsonObject.Parse(result3.Value).GetObject(); this.PageId = userInfo["data"].GetArray()[0].GetObject().GetNamedString("id"); } else { FacebookUserName.Text = "Error contacting Facebook"; } }