示例#1
0
            protected override object DeserializeCore(JObject json, Type objectType, PhotoAddLoadContext context)
            {
                try
                {
                    var data = new PhotoAddResponse((PhotoAddLoadContext)context);

                    var p = json["photo"];
                    if (p != null)
                    {
                        Photo photo = Photo.ParseJson(p);
                        if (photo != null)
                        {
                            data.Photo = photo;
                        }
                    }

                    data.IsLoadComplete = true;
                    return(data);
                }
                catch (Exception e)
                {
                    throw new UserIntendedException(
                              "There was a problem trying to add the photo, please try again later.", e);
                }
            }
示例#2
0
            protected override object DeserializeCore(JObject json, Type objectType, LoadContext context)
            {
                try
                {
                    var u = new DetailedCheckin(context);
                    //u.IgnoreRaisingPropertyChanges = true;

                    var jcheckin = json["checkin"];
                    if (jcheckin != null)
                    {
                        Checkin compactCheckin = Checkin.ParseJson(jcheckin);

                        // So links are not displayed, etc.
                        if (compactCheckin != null)
                        {
                            compactCheckin.ReduceFunctionality      = true;
                            compactCheckin.ReduceFunctionalityVis   = System.Windows.Visibility.Visible;
                            compactCheckin.CompleteFunctionalityVis = System.Windows.Visibility.Collapsed;
                        }

                        u.CompactCheckin = compactCheckin;

                        List <Photo> photos = new List <Photo>();
                        var          pl     = jcheckin["photos"];
                        if (pl != null)
                        {
                            var pll = pl["items"];
                            if (pll != null)
                            {
                                foreach (var photo in pll)
                                {
                                    var po = Photo.ParseJson(photo);
                                    if (po != null)
                                    {
                                        photos.Add(po);
                                    }
                                }
                            }
                        }

                        List <Comment> comments = new List <Comment>();
                        var            cl       = jcheckin["comments"];
                        if (cl != null)
                        {
                            var cll = cl["items"];
                            if (cll != null)
                            {
                                foreach (var comment in cll)
                                {
                                    var co = Comment.ParseJson(comment);
                                    if (co != null)
                                    {
                                        comments.Add(co);
                                    }
                                }
                            }
                        }

                        //var list = combined.OrderBy(w => w.CreatedDateTime).ToList();
                        //cap.AddRange(list);

                        List <object> both = new List <object>(photos.Cast <object>());
                        both.AddRange(comments.Cast <object>());

                        //List<CommentsList> lcl = null;
                        //if (cap.Count > 0)
                        //{
                        //    lcl = new List<CommentsList>();
                        //    lcl.Add(cap);
                        //}

                        u.CommentsAndPhotos = both;
                    }

                    u.IgnoreRaisingPropertyChanges = false;
                    u.IsLoadComplete = true;

                    return(u);
                }
                catch (Exception e)
                {
                    throw new UserIntendedException(
                              "There was a problem trying to read information about the checkin.", e);
                }
            }
        public static CompactList ParseJson(JToken list)
        {
            CompactList l = new CompactList();

            l.Id = Json.TryGetJsonProperty(list, "id");

            l.Name        = Json.TryGetJsonProperty(list, "name");
            l.Description = Json.TryGetJsonProperty(list, "description");

            Uri uri = null;

            Uri.TryCreate(string.Format(
                              CultureInfo.InvariantCulture,
                              "/JeffWilcox.FourthAndMayor.Lists;component/ListView.xaml?id={0}&name={1}&description={2}",
                              l.Id,
                              l.Name,
                              l.Description), UriKind.Relative, out uri);
            l.LocalListUri = uri;

            var cu = list["user"];

            if (cu != null)
            {
                var ocu = CompactUser.ParseJson(cu);
                if (ocu != null)
                {
                    l.User = ocu;
                }
            }

            l.IsFollowing = Json.TryGetJsonBool(list, "following");

            // TODO: v4: "followers"

            l.IsEditable      = Json.TryGetJsonBool(list, "editable");
            l.IsCollaborative = Json.TryGetJsonBool(list, "collaborative");

            // TODO: v4: "collaborators"

            l.CaonicalUri = Json.TryGetUriProperty(list, "caonicalUrl");

            var pic = list["photo"];

            if (pic != null)
            {
                var opic = Photo.ParseJson(pic);
                if (opic != null)
                {
                    l.Photo = opic;
                }
            }

            string s = Json.TryGetJsonProperty(list, "doneCount");
            int    i;

            if (int.TryParse(s, out i))
            {
                l.DoneCount = i;
            }

            s = Json.TryGetJsonProperty(list, "venueCount");
            if (int.TryParse(s, out i))
            {
                l.VenueCount = i;
            }

            s = Json.TryGetJsonProperty(list, "visitedCount");
            if (int.TryParse(s, out i))
            {
                l.VisitedCount = i;
            }

            //var b = new List<CompactListItem>();
            //var lis = list["listItems"];
            //if (lis != null)
            //{
            //    var items = lis["items"];
            //    if (items != null)
            //    {
            //        foreach (var entry in items)
            //        {
            //            var u = CompactListItem.ParseJson(entry);
            //            if (u != null)
            //            {
            //                b.Add(u);
            //            }
            //        }
            //    }
            //}

            // l.ListItems = b;

            return(l);
        }
示例#4
0
            /// <summary>
            /// Parses the JSON response to retrieve the leaderboard, parsing
            /// of individual items are handled by their compact object
            /// parse routines.
            /// </summary>
            protected override object DeserializeCore(JObject json, Type objectType, ListLoadContext context)
            {
                try
                {
                    var l = new List(context);

                    var list = json["list"];

                    l.Id          = Json.TryGetJsonProperty(list, "id");
                    l.Name        = Json.TryGetJsonProperty(list, "name");
                    l.Description = Json.TryGetJsonProperty(list, "description");

                    var cu = list["user"];
                    if (cu != null)
                    {
                        var ocu = CompactUser.ParseJson(cu);
                        if (ocu != null)
                        {
                            l.User = ocu;

                            l.IsOwnList = ocu.IsSelf;
                        }
                    }

                    l.IsFollowing = Json.TryGetJsonBool(list, "following");

                    // TODO: v4: "followers"

                    l.IsEditable      = Json.TryGetJsonBool(list, "editable");
                    l.IsCollaborative = Json.TryGetJsonBool(list, "collaborative");

                    // TODO: v4: "collaborators"

                    l.CaonicalUri = Json.TryGetUriProperty(list, "caonicalUrl");

                    var pic = list["photo"];
                    if (pic != null)
                    {
                        var opic = Photo.ParseJson(pic);
                        if (opic != null)
                        {
                            l.Photo = opic;
                        }
                    }

                    string s = Json.TryGetJsonProperty(list, "doneCount");
                    int    i;
                    if (int.TryParse(s, out i))
                    {
                        l.DoneCount = i;
                    }

                    s = Json.TryGetJsonProperty(list, "venueCount");
                    if (int.TryParse(s, out i))
                    {
                        l.VenueCount = i;
                    }

                    s = Json.TryGetJsonProperty(list, "visitedCount");
                    if (int.TryParse(s, out i))
                    {
                        l.VisitedCount = i;
                    }

                    if (l.VenueCount > 0)
                    {
                        var appStrings = Application.Current as IProvideLocalizedStrings;
                        if (appStrings != null)
                        {
                            string key = "ListYouveBeenTo";
                            if (l.VenueCount == 1)
                            {
                                key = "ListYouveBeenToSingular";
                            }
                            var format = appStrings.GetLocalizedString(key);
                            if (format != null)
                            {
                                l.VisitedPlacesString = string.Format(
                                    CultureInfo.CurrentCulture,
                                    format,
                                    Math.Min(l.VisitedCount, l.VenueCount), // was reporting at times "35 out of 30" which is not cool.
                                    l.VenueCount
                                    );
                            }
                        }
                    }

                    var b   = new List <CompactListItem>();
                    var lis = list["listItems"];
                    if (lis != null)
                    {
                        var items = lis["items"];
                        if (items != null)
                        {
                            foreach (var entry in items)
                            {
                                var u = CompactListItem.ParseJson(entry);
                                if (u != null)
                                {
                                    // Associate the contextual parent/list ID.
                                    u.ListId = l.Id;
                                    b.Add(u);
                                }
                            }
                        }
                    }

                    l.ListItems = b;

                    l.IsLoadComplete = true;

                    return(l);
                }
                catch (Exception e)
                {
                    throw new UserIntendedException(
                              "The list information could not be returned right now.", e);
                }
            }
示例#5
0
        public static CompactListItem ParseJson(JToken json)
        {
            CompactListItem c = new CompactListItem();

            c.Id = Json.TryGetJsonProperty(json, "id");

            string created = Json.TryGetJsonProperty(json, "createdAt");

            if (created != null)
            {
                DateTime dtc = UnixDate.ToDateTime(created);
                c.CreatedAt = Checkin.GetDateString(dtc);
                c.Created   = dtc;
            }

            var user = json["user"];

            if (user != null)
            {
                c.User = CompactUser.ParseJson(user);
            }

            var photo = json["photo"];

            if (photo != null)
            {
                c.Photo = Photo.ParseJson(photo);
            }

            var venue = json["venue"];

            if (venue != null)
            {
                c.Venue = CompactVenue.ParseJson(venue);
            }

            var tip = json["tip"];

            if (tip != null)
            {
                c.Tip = Tip.ParseJson(tip);
            }

            var note = json["note"];

            if (note != null)
            {
                c.Note = Json.TryGetJsonProperty(note, "text");
            }

            c.Todo   = Json.TryGetJsonBool(json, "todo");
            c.IsDone = Json.TryGetJsonBool(json, "done");

            string s = Json.TryGetJsonProperty(json, "visitedCount");

            if (s != null)
            {
                int i;
                if (int.TryParse(s, out i))
                {
                    c.VisitedCount = i;
                }
            }

            // TODO: V4: "listed" list of compact venues where the item appears on.

            return(c);
        }
示例#6
0
            protected override object DeserializeCore(JObject json, Type objectType, LoadContext context)
            {
                var v = new Venue(context);

                try
                {
                    var venue = json["venue"];

                    CompactVenue bv = CompactVenue.ParseJson(venue);
                    v.VenueId = bv.VenueId;
                    Debug.Assert(v.VenueId != null);

                    // TODO: Consider architecture.
                    v.Location    = bv.Location;
                    v.Address     = bv.Address;
                    v.City        = bv.City;
                    v.CrossStreet = bv.CrossStreet;
                    v.State       = bv.State;
                    v.Zip         = bv.Zip;
                    v.Name        = bv.Name;

                    var menuEntry = venue["menu"];
                    if (menuEntry != null)
                    {
                        string mobileMenu = Json.TryGetJsonProperty(menuEntry, "mobileUrl");
                        if (!string.IsNullOrEmpty(mobileMenu))
                        {
                            v.HasMenu = true;
                        }
                    }

                    string desc = Checkin.SanitizeString(Json.TryGetJsonProperty(venue, "description"));
                    if (desc != null)
                    {
                        v.Description = desc;
                    }

                    // TODO: V2: timeZone // timeZone: "America/New_York"

                    string swu = Json.TryGetJsonProperty(venue, "shortUrl");
                    if (swu != null)
                    {
                        v.ShortWebUri = new Uri(swu);
                    }

                    string verif = Json.TryGetJsonProperty(venue, "verified");
                    if (verif != null && verif.ToLowerInvariant() == "true")
                    {
                        v.IsVerified = true;
                    }

                    // older code.
                    string phone = Json.TryGetJsonProperty(venue, "phone");
                    if (phone != null)
                    {
                        v.Phone = phone; // User.FormatSimpleUnitedStatesPhoneNumberMaybe(phone);
                    }

                    // newer code for contact stuff.
                    var contact = venue["contact"];
                    if (contact != null)
                    {
                        v.Twitter = Json.TryGetJsonProperty(contact, "twitter");

                        string newerPhone = Json.TryGetJsonProperty(contact, "phone");
                        if (newerPhone != null)
                        {
                            v.Phone = newerPhone;
                        }

                        string bestPhone = Json.TryGetJsonProperty(contact, "formattedPhone");
                        if (bestPhone != null)
                        {
                            v.FormattedPhone = bestPhone;
                        }

                        // fallback.
                        if (v.FormattedPhone == null && !string.IsNullOrEmpty(v.Phone))
                        {
                            v.FormattedPhone = User.FormatSimpleUnitedStatesPhoneNumberMaybe(v.Phone);
                        }
                    }

                    string homepage = Json.TryGetJsonProperty(venue, "url");
                    if (!string.IsNullOrEmpty(homepage))
                    {
                        v.Homepage = new Uri(homepage, UriKind.Absolute);
                    }

                    var todos = venue["todos"];
                    if (todos != null)
                    {
                        var items = todos["items"];
                        if (items != null)
                        {
                            var todosList = new List <Todo>();
                            foreach (var todo in items)
                            {
                                var td = Todo.ParseJson(todo);
                                if (td != null)
                                {
                                    todosList.Add(td);
                                }
                            }
                            v.Todos = todosList;
                        }
                    }

                    var events = venue["events"];
                    if (events != null)
                    {
                        string pct = Json.TryGetJsonProperty(events, "count");
                        int    pcti;
                        if (int.TryParse(pct, out pcti))
                        {
                            v.EventsCount = pcti;

                            if (pcti > 0)
                            {
                                v.EventsSummary = Json.TryGetJsonProperty(events, "summary");
                            }

                            if (v.HasEvents)
                            {
                                // ? will this work ?
                                v.Events = DataManager.Current.Load <VenueEvents>(
                                    new LoadContext(
                                        v.LoadContext.Identity
                                        )
                                    );
                            }
                        }
                    }

                    var photos = venue["photos"];
                    if (photos != null)
                    {
                        string pct = Json.TryGetJsonProperty(photos, "count");
                        int    pcti;
                        if (int.TryParse(pct, out pcti))
                        {
                            if (pcti == 1)
                            {
                                v.PhotosCount = "1 photo";
                            }
                            else if (pcti > 1)
                            {
                                v.PhotosCount = pcti.ToString() + " photos";
                            }

                            // get the grounds
                            if (pcti > 0)
                            {
                                var groups = photos["groups"];
                                if (groups != null)
                                {
                                    var pg = new List <PhotoGroup>();
                                    foreach (var item in groups)
                                    {
                                        string name  = Json.TryGetJsonProperty(item, "name");
                                        var    items = item["items"];
                                        var    group = new PhotoGroup();
                                        group.Name = name;
                                        foreach (var it in items)
                                        {
                                            Photo p = Photo.ParseJson(it);
                                            if (p != null)
                                            {
                                                group.Add(p);
                                            }
                                        }
                                        if (group.Count > 0)
                                        {
                                            pg.Add(group);
                                        }
                                    }
                                    if (pg.Count > 0)
                                    {
                                        v.PhotoGroups = pg;
                                    }
                                }
                            }
                        }
                    }
                    // Allowing the GIC to show the empty template.
                    if (v.PhotoGroups == null)
                    {
                        v.PhotoGroups = new List <PhotoGroup>();
                    }

                    string htodo = Json.TryGetJsonProperty(venue, "hasTodo"); // checkin mode only
                    if (htodo != null && htodo.ToLowerInvariant() == "true")
                    {
                        v.HasToDo = true;
                    }

                    v.HereNow = "Nobody";
                    bool hereNow = false;
                    var  herenow = venue["hereNow"];
                    if (herenow != null)
                    {
                        bool isSelfHere = false;

                        string summary = Json.TryGetJsonProperty(herenow, "summary");
                        if (summary != null)
                        {
                            v.HereNow = summary;
                        }

                        var    groups = herenow["groups"];
                        string hn     = Json.TryGetJsonProperty(herenow, "count");
                        if (/*!string.IsNullOrEmpty(hn) &&*/ groups != null) // I still want to compute this anyway.
                        {
                            int totalCount     = int.Parse(hn, CultureInfo.InvariantCulture);
                            int remainingCount = totalCount;

                            var hereNowGroups = new List <CheckinsGroup>();
                            foreach (var group in groups)
                            {
                                string type  = Json.TryGetJsonProperty(group, "type");  // friends, others
                                string name  = Json.TryGetJsonProperty(group, "name");  // "friends here", "other people here"
                                string count = Json.TryGetJsonProperty(group, "count"); // the count, an int
                                var    items = group["items"];

                                if (items != null)
                                {
                                    var cg = new CheckinsGroup {
                                        Name = name
                                    };

                                    foreach (var item in items)
                                    {
                                        Checkin cc = Checkin.ParseJson(item);
                                        remainingCount--;
                                        if (cc.User != null && cc.User.Relationship == FriendStatus.Self)
                                        {
                                            // Self!
                                            var selfGroup = new CheckinsGroup {
                                                Name = "you're here!"
                                            };
                                            isSelfHere = true;
                                            selfGroup.Add(cc);
                                            hereNowGroups.Add(selfGroup);
                                        }
                                        else
                                        {
                                            cg.Add(cc);
                                        }
                                    }

                                    if (cg.Count > 0)
                                    {
                                        hereNowGroups.Add(cg);
                                    }
                                }
                            }

                            // Special last item with the remainder count.
                            if (remainingCount > 0 && hereNowGroups.Count > 0)
                            {
                                var lastGroup = hereNowGroups[hereNowGroups.Count - 1];
                                var hnr       = new Checkin
                                {
                                    HereNowRemainderText =
                                        remainingCount == 1
                                            ? "... plus 1 person"
                                            : "... plus " + remainingCount.ToString() + " people",
                                };
                                lastGroup.Add(hnr);
                            }

                            v.HereNowGroups = hereNowGroups;

                            // subtract one for self
                            if (isSelfHere)
                            {
                                totalCount--;
                            }
                            string prefix = (isSelfHere ? "You and " : string.Empty);
                            if (string.IsNullOrEmpty(summary))
                            {
                                if (totalCount > 1)
                                {
                                    v.HereNow = prefix + Json.GetPrettyInt(totalCount) + " " + (isSelfHere ? "other " : "") + "people";
                                }
                                else if (totalCount == 1)
                                {
                                    v.HereNow = prefix + "1 " + (isSelfHere ? "other " : "") + "person";
                                }
                                else if (totalCount == 0 && isSelfHere)
                                {
                                    v.HereNow = "You are here";
                                }
                            }

                            if (totalCount > 0)
                            {
                                hereNow = true;
                            }
                        }
                    }

                    v.HasHereNow = hereNow;

                    var stats = venue["stats"];
                    if (stats != null)
                    {
                        string checkins = Json.TryGetJsonProperty(stats, "checkinsCount");
                        if (checkins != null)
                        {
                            int i;
                            if (int.TryParse(checkins, out i))
                            {
                                v.Checkins = i;
                            }
                        }

                        checkins = Json.TryGetJsonProperty(stats, "usersCount");
                        if (checkins != null)
                        {
                            int i;
                            if (int.TryParse(checkins, out i))
                            {
                                v.TotalPeople = i;
                            }
                        }
                    }

                    var mayor = venue["mayor"];
                    if (mayor != null)
                    {
                        string mayorCheckinCount = Json.TryGetJsonProperty(mayor, "count");

                        var user = mayor["user"];
                        if (user != null)
                        {
                            v.Mayor = CompactUser.ParseJson(user);
                        }

                        // Note there is a mayor.count property, it is the num
                        // of checkins in the last 60 days.
                    }

                    var beenHere = venue["beenHere"];
                    if (beenHere != null)
                    {
                        string c = Json.TryGetJsonProperty(beenHere, "count");
                        if (c != null)
                        {
                            int i;
                            if (int.TryParse(c, out i))
                            {
                                v.BeenHere = i;
                            }
                        }
                    }

                    var tips = venue["tips"];
                    if (tips != null)
                    {
                        string tipsCountStr = Json.TryGetJsonProperty(tips, "count");
                        if (tipsCountStr != null)
                        {
                            int tc;
                            if (int.TryParse(tipsCountStr, out tc))
                            {
                                if (tc <= 0)
                                {
                                    tipsCountStr = "No tips";
                                }
                                else if (tc == 1)
                                {
                                    tipsCountStr = "1 tip";
                                }
                                else
                                {
                                    tipsCountStr = tc.ToString() + " tips";
                                }
                            }
                        }
                        else
                        {
                            tipsCountStr = "No tips";
                        }
                        v.TipsCountText = tipsCountStr;

                        var ml        = new List <TipGroup>();
                        var tipGroups = tips["groups"];
                        if (tipGroups != null)
                        {
                            foreach (var tipGroup in tipGroups)
                            {
                                //string groupType = Json.TryGetJsonProperty(tipGroup, "type"); // others, ???v2
                                string groupName = Json.TryGetJsonProperty(tipGroup, "name"); // tips from others
                                //string countStr = Json.TryGetJsonProperty(tipGroup, "count");

                                var tipSet = tipGroup["items"];
                                if (tipSet != null)
                                {
                                    TipGroup tg = new TipGroup {
                                        Name = groupName
                                    };
                                    foreach (var tip in tipSet)
                                    {
                                        Tip t = Tip.ParseJson(tip, typeof(Model.Venue), (string)context.Identity);
                                        if (t != null)
                                        {
                                            tg.Add(t);
                                        }
                                    }
                                    if (tg.Count > 0)
                                    {
                                        ml.Add(tg);
                                    }
                                }
                            }
                        }
                        v.TipGroups = ml;
                    }

                    var specials     = venue["specials"];
                    var specialsList = new SpecialGroup {
                        Name = "specials here"
                    };
                    if (specials != null)
                    {
                        try
                        {
                            var items = specials["items"];
                            if (items != null)
                            {
                                foreach (var s in items)
                                {
                                    CompactSpecial cs = CompactSpecial.ParseJson(s, v.VenueId);
                                    if (cs != null)
                                    {
                                        specialsList.Add(cs);

                                        if (cs.IsUnlocked)
                                        {
                                            v.SpecialUnlocked = true;
                                        }
                                    }
                                }
                                if (specialsList.Count == 1)
                                {
                                    specialsList.Name = "special here";
                                }
                            }
                        }
                        catch (Exception)
                        {
                            // 3.4 moves to a new Foursquare API version and so
                            // we don't want old cached data to throw here.
                        }
                    }
                    v.Specials = specialsList;

                    var nearby             = venue["specialsNearby"];
                    var nearbySpecialsList = new SpecialGroup {
                        Name = "specials nearby"
                    };
                    if (nearby != null)
                    {
                        foreach (var s in nearby)
                        {
                            CompactSpecial cs = CompactSpecial.ParseJson(s, null);
                            if (cs != null)
                            {
                                nearbySpecialsList.Add(cs);
                            }
                        }
                        if (nearbySpecialsList.Count == 1)
                        {
                            nearbySpecialsList.Name = "special nearby";
                        }
                    }
                    v.NearbySpecials = nearbySpecialsList;

                    var cmb = new List <SpecialGroup>(2);
                    if (specialsList.Count > 0)
                    {
                        cmb.Add(specialsList);
                    }
                    if (nearbySpecialsList.Count > 0)
                    {
                        cmb.Add(nearbySpecialsList);
                    }
                    v.CombinedSpecials = cmb;

                    var categories = venue["categories"];
                    if (categories != null)
                    {
                        foreach (var cat in categories)
                        {
                            var cc = Category.ParseJson(cat);
                            if (cc != null && cc.IsPrimary)
                            {
                                v.PrimaryCategory = cc;
                                break;
                            }
                            // Just the first actually!
                            break;
                        }
                    }

                    // stats
                    // .herenow
                    // .checkins
                    // beenhere: me:true;

                    // specials

                    var tags = venue["tags"];
                    if (tags != null)
                    {
                        List <string> tl = new List <string>();
                        foreach (string tag in tags)
                        {
                            tl.Add(tag);
                        }

                        if (tl.Count > 0)
                        {
                            v.Tags = tl;

                            StringBuilder sb = new StringBuilder();
                            for (int i = 0; i < tl.Count; i++)
                            {
                                if (i > 0)
                                {
                                    sb.Append(", ");
                                }

                                sb.Append(tl[i]);
                            }

                            v.TagsString = sb.ToString();
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new UserIntendedException(
                              "There was a problem trying to read the venue information.", e);
                }

                v.IsLoadComplete = true;

                return(v);
            }
示例#7
0
        public static Checkin ParseJson(JToken checkin)
        {
            Checkin c = new Checkin();

            string created = Json.TryGetJsonProperty(checkin, "createdAt");

            if (created != null)
            {
                // FUTURE: Consider an option to NOT include people in the checkin list who have not checked in within the last month. (perf default!)
                DateTime dtc = UnixDate.ToDateTime(created);
                c.CreatedDateTime = dtc;
                c.Created         = GetDateString(dtc);
            }

            // Client information.
            var source = checkin["source"];

            if (source != null)
            {
                c.ClientName = Json.TryGetJsonProperty(source, "name");

                // TODO: Create a crashless URI helper.
                try
                {
                    string url = Json.TryGetJsonProperty(source, "url");
                    if (!string.IsNullOrEmpty(url))
                    {
                        if (url.StartsWith("www"))
                        {
                            url = "http://" + url;
                        }
                        c.ClientWebUri = new Uri(url, UriKind.Absolute);
                    }
                }
                catch
                {
                }
            }

            string type = Json.TryGetJsonProperty(checkin, "type");

            // Only if present. Won't show up in badge winnings, for instance.
            if (type != null)
            {
                Debug.Assert(type == "checkin" || type == "shout" || type == "venueless");
            }
            c.CheckinType = type;

            c.CheckinId = Json.TryGetJsonProperty(checkin, "id");
            // badge mode actually won't have this Debug.Assert(c.CheckinId != null);

            if (!string.IsNullOrEmpty(c.CheckinId))
            {
                c.LocalCommentsUri = new Uri(string.Format(CultureInfo.InvariantCulture, "/Views/Comments.xaml?checkin={0}", c.CheckinId), UriKind.Relative);
            }

            var location = checkin["location"];

            if (location != null && type == "venueless") // consider if that's right
            {
                // if shout or venueless, will provide...
                // lat, lng pair and/or a name
                string venuelessName = Json.TryGetJsonProperty(location, "name");
                c.VenuelessName = venuelessName;
            }

            var user = checkin["user"];

            if (user != null)
            {
                CompactUser bu = CompactUser.ParseJson(user);
                c.User = bu;
            }

            var venue = checkin["venue"];

            if (venue != null)
            {
                CompactVenue bv = CompactVenue.ParseJson(venue);
                if (bv != null)
                {
                    c.DisplayAddressLine = bv.AddressLine;
                }
                c.Venue = bv;
            }

            // Show venueless name at least.
            if (c.Venue == null && !string.IsNullOrEmpty(c.VenuelessName))
            {
                c.Venue = CompactVenue.CreateVenueless(c.VenuelessName);
            }

            c.Shout = Json.TryGetJsonProperty(checkin, "shout");

            string ismayor = Json.TryGetJsonProperty(checkin, "isMayor");

            if (ismayor != null && ismayor.ToLowerInvariant() == "true")
            {
                c.IsMayor = true;
            }

            string dist = Json.TryGetJsonProperty(checkin, "distance");

            if (dist == null)
            {
                c.Meters = double.NaN;
            }
            else
            {
                c.Meters = double.Parse(dist, CultureInfo.InvariantCulture);

                // Doing this here to centralize it somewhere at least.
                if (c.Meters > 40000) // NOTE: This is a random value, What value should define a different city?
                {
                    c.IsInAnotherCity = true;
                    if (c.Venue != null)
                    {
                        string s = c.Venue.City ?? string.Empty;
                        if (!string.IsNullOrEmpty(c.Venue.State))
                        {
                            s += ", ";
                        }
                        if (c.Venue.State != null)
                        {
                            s += c.Venue.State;
                        }

                        c.DisplayAddressLine = s;
                    }
                }
            }

            if (c.User != null)
            {
                c.DisplayUser = c.User.ShortName;
                c.UserUri     = c.User.UserUri;
            }
            if (c.Venue != null)
            {
                c.DisplayBetween = null; // WAS:  "@";
                c.DisplayVenue   = c.Venue.Name;
                c.VenueUri       = c.Venue.VenueUri;
            }
            else
            {
                if (type == "shout")
                {
                    //c.DisplayBetween = "shouted:";
                }
                else if (type == "venueless")
                {
                    c.DisplayBetween = c.VenuelessName;
                }
                else
                {
                    c.DisplayBetween = "[off-the-grid]"; // @
                }
            }

            // Photo and Comment information
            c.CommentsCount = GetNodeCount(checkin, "comments");
            c.PhotosCount   = GetNodeCount(checkin, "photos");

            c.HasComments         = c.CommentsCount > 0;
            c.HasPhotos           = c.PhotosCount > 0;
            c.HasPhotosOrComments = c.HasComments || c.HasPhotos;

            if (c.HasPhotos)
            {
                List <Photo> photos = new List <Photo>();
                var          pl     = checkin["photos"];
                if (pl != null)
                {
                    var pll = pl["items"];
                    if (pll != null)
                    {
                        foreach (var photo in pll)
                        {
                            var po = Photo.ParseJson(photo);
                            if (po != null)
                            {
                                photos.Add(po);
                            }
                        }
                    }
                }
                c.Photos = photos;

                if (photos.Count > 0)
                {
                    c.FirstCheckinPhoto = photos[0];
                }
            }

            int activityCount = c.CommentsCount; // +c.PhotosCount;

            c.CommentsAndPhotosOrAdd = activityCount > 0 ? activityCount.ToString(CultureInfo.InvariantCulture) : "+";

            if (c.User != null && c.User.Relationship == FriendStatus.Self)
            {
                c.CanAddPhotos = true;
            }

            return(c);
        }