示例#1
0
        // specialized comparison string getter?

        public static CompactListItem CreateTipFaçade(Tip tip)
        {
            if (tip != null)
            {
                CompactListItem c = new CompactListItem();

                c.Created = tip.CreatedDateTime;
                //c.CreatedAt
                c.Id = tip.TipId;

                c.IsDone = tip.Status == TipStatus.Done;
                c.Todo   = tip.Status == TipStatus.Todo;

                c.ListId = null;
                // ? c.LocalListItemUri
                c.Note  = null;
                c.Photo = tip.Photo;
                c.Tip   = tip;

                c.User  = tip.User;
                c.Venue = tip.Venue;
                // c.VisitedCount

                return(c);
            }

            return(null);
        }
示例#2
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);
                }
            }
示例#3
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);
        }
        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;
        }
        // specialized comparison string getter?

        public static CompactListItem CreateTipFaçade(Tip tip)
        {
            if (tip != null)
            {
                CompactListItem c = new CompactListItem();

                c.Created = tip.CreatedDateTime;
                //c.CreatedAt
                c.Id = tip.TipId;

                c.IsDone = tip.Status == TipStatus.Done;
                c.Todo = tip.Status == TipStatus.Todo;

                c.ListId = null;
                // ? c.LocalListItemUri
                c.Note = null;
                c.Photo = tip.Photo;
                c.Tip = tip;

                c.User = tip.User;
                c.Venue = tip.Venue;
                // c.VisitedCount

                return c;
            }

            return null;
        }