public static Notifications ParseJson(JToken json, string venueId, Model.CheckinRequest optionalCheckinRequest) { var ns = new Notifications(); ns._temporaryCheckinRequest = optionalCheckinRequest; // Save as a tombstoning object. var tt = new TombstoningText("notifications"); tt.Text = venueId + Environment.NewLine + json.ToString(); tt.Save(ns.UniqueId); foreach (var notif in json) { Notification notification = Notification.ParseJson(notif, venueId); if (notification != null) { ns.Add(notification); } else { string s = Json.TryGetJsonProperty(notif, "type"); if (s == "notificationTray") { var item = notif["item"]; if (item != null) { string unreadCount = Json.TryGetJsonProperty(item, "unreadCount"); int i; if (int.TryParse(unreadCount, out i)) { ns.UnreadNotifications = i; } } } } } // Reorder the notifications per Foursquare preferred ordering. int currentIndex = 0; TryReorderNotificationOfType(ns, typeof(MessageNotification), ref currentIndex); TryReorderNotificationOfType(ns, typeof(BadgeNotification), ref currentIndex); TryReorderNotificationOfType(ns, typeof(MayorshipNotification), ref currentIndex); TryReorderNotificationOfType(ns, typeof(SpecialNotification), ref currentIndex); TryReorderNotificationOfType(ns, typeof(ScoreNotification), ref currentIndex); TryReorderNotificationOfType(ns, typeof(LeaderboardNotification), ref currentIndex); TryReorderNotificationOfType(ns, typeof(RecommendedTipNotification), ref currentIndex); return(ns); }
public static CheckinResponse Rehydrate(string uniqueId) { var tt = new TombstoningText("response"); if (tt.Load(uniqueId)) { var text = tt.Text; var json = JArray.Parse(text); if (json != null) { // TODO: Fix this pattern where unique ID is changing. var o = ParseJson(json); o.UniqueId = uniqueId; return o; } } return null; }
public static CheckinResponse Rehydrate(string uniqueId) { var tt = new TombstoningText("response"); if (tt.Load(uniqueId)) { var text = tt.Text; var json = JArray.Parse(text); if (json != null) { // TODO: Fix this pattern where unique ID is changing. var o = ParseJson(json); o.UniqueId = uniqueId; return(o); } } return(null); }
public static CheckinResponse ParseJson(JToken json) { var r = new CheckinResponse(); var tt = new TombstoningText("response"); tt.Text = json.ToString(); tt.Save(r.UniqueId); try { var checkin = json["checkin"]; // (JArray)json["checkin"]; // string type = Json.TryGetJsonProperty(checkin, "type"); // checkin,shout,venueless string created = Json.TryGetJsonProperty(checkin, "createdAt"); if (created != null) { DateTime dtc = UnixDate.ToDateTime(created); r.Created = dtc; } r.CheckinId = Json.TryGetJsonProperty(checkin, "id"); var venue = checkin["venue"]; if (venue != null) { r.Venue = CompactVenue.ParseJson(venue); } return(r); } catch (Exception e) { throw new UserIntendedException( "There was a problem trying to check-in, please try again later.", e); } }
public static CheckinResponse ParseJson(JToken json) { var r = new CheckinResponse(); var tt = new TombstoningText("response"); tt.Text = json.ToString(); tt.Save(r.UniqueId); try { var checkin = json["checkin"]; // (JArray)json["checkin"]; // string type = Json.TryGetJsonProperty(checkin, "type"); // checkin,shout,venueless string created = Json.TryGetJsonProperty(checkin, "createdAt"); if (created != null) { DateTime dtc = UnixDate.ToDateTime(created); r.Created = dtc; } r.CheckinId = Json.TryGetJsonProperty(checkin, "id"); var venue = checkin["venue"]; if (venue != null) { r.Venue = CompactVenue.ParseJson(venue); } return r; } catch (Exception e) { throw new UserIntendedException( "There was a problem trying to check-in, please try again later.", e); } }
public static Notifications Rehydrate(string uniqueId) { var tt = new TombstoningText("notifications"); if (tt.Load(uniqueId)) { var sr = new StringReader(tt.Text); string lineOne = sr.ReadLine(); string venueId = null; if (lineOne != null) { venueId = lineOne.Trim(); } var text = sr.ReadToEnd(); var json = JArray.Parse(text); if (json != null) { return(ParseJson(json, venueId, null)); } } return(null); }