Ejemplo n.º 1
0
        private static object HydrateCompactObject(TargetObjectType type, JToken item)
        {
            try
            {
                if (item != null)
                {
                    switch (type)
                    {
                    case TargetObjectType.Badge:
                        return(Badge.ParseJson(item));

                    case TargetObjectType.Checkin:
                        return(Checkin.ParseJson(item));

                    case TargetObjectType.Special:
                        // VenueId, if null, must be parsed out of the
                        // notification or else it will throw. FYI.
                        return(CompactSpecial.ParseJson(item, null));

                    case TargetObjectType.Tip:
                        return(Tip.ParseJson(item));

                    case TargetObjectType.Url:
                        Uri uri = Json.TryGetUriProperty(item, "url");
                        return(uri);

                    case TargetObjectType.User:
                        return(CompactUser.ParseJson(item));

                    case TargetObjectType.Venue:
                        return(CompactVenue.ParseJson(item));

                    default:
                        break;
                    }
                }
            }
            catch (Exception)
            {
            }

            return(null);
        }
Ejemplo n.º 2
0
        public RecommendedTipNotification(JToken item)
        {
            string text = Json.TryGetJsonProperty(item, "name");

            if (string.IsNullOrEmpty(text))
            {
                text = "Popular tip";
            }
            Text = text;

            var jtip = item["tip"];

            if (jtip != null)
            {
                Tip tip = Tip.ParseJson(jtip, typeof(RecommendedTipNotification), string.Empty);
                if (tip != null)
                {
                    RecommendedTip = tip;
                }
            }
        }
Ejemplo n.º 3
0
            // TODO: the iOS client offers sets the sort property to allow for recent, nearby, popular... hard-coding to recent for now! need to determine what kind of UI is useful for this kind of sort... and yeah it's probably yet another pivot...

            protected override object DeserializeCore(JObject json, Type objectType, LoadContext context)
            {
                try
                {
                    var b = new UserTips(context);

                    var sets = json["tips"];
                    if (sets != null)
                    {
                        List <Tip> tips = new List <Tip>();

                        var items = sets["items"];
                        if (items != null)
                        {
                            foreach (var tip in items)
                            {
                                Tip t = Tip.ParseJson(tip, typeof(UserTips), (string)context.Identity);
                                if (t != null)
                                {
                                    tips.Add(t);
                                }
                            }
                        }

                        b.Tips = tips;
                    }

                    b.IsLoadComplete = true;

                    return(b);
                }
                catch (Exception e)
                {
                    throw new UserIntendedException(
                              "There was a problem trying to read the list of tips.", e);
                }
            }
Ejemplo n.º 4
0
            protected override object DeserializeCore(JObject json, Type objectType, LoadContext context)
            {
                try
                {
                    var nv = new DetailedTip(context);

                    var tip = json["tip"];

                    var compactTip = Tip.ParseJson(tip, typeof(DetailedTip), null);
                    if (compactTip != null)
                    {
                        nv.CompactTip = compactTip;
                    }

                    nv.IsLoadComplete = true;

                    return(nv);
                }
                catch (Exception e)
                {
                    throw new UserIntendedException(
                              "There was a problem trying to read the tip.", e);
                }
            }
Ejemplo n.º 5
0
        public static RecommendedCompactVenue ParseJson(JToken jsonRecommendation)
        {
            var recommendation = new RecommendedCompactVenue();

            var reasons    = jsonRecommendation["reasons"];
            var reasonList = new List <RecommendationReason>();

            if (reasons != null)
            {
                var items = reasons["items"];
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        string sType    = Json.TryGetJsonProperty(item, "type");
                        string sMessage = Json.TryGetJsonProperty(item, "message");
                        reasonList.Add(new RecommendationReason
                        {
                            Reason  = sType,
                            Message = sMessage,
                        });
                    }

                    if (reasonList.Count > 0)
                    {
                        recommendation.PrimaryReason = reasonList[0];

                        if (reasonList.Count > 1)
                        {
                            List <RecommendationReason> otherReasons = new List <RecommendationReason>();
                            for (int i = 1; i < reasonList.Count; i++)
                            {
                                otherReasons.Add(reasonList[i]);
                            }
                            recommendation.SecondaryReasons = otherReasons;
                        }
                    }
                }
            }
            recommendation.Reasons = reasonList;

            var venue = jsonRecommendation["venue"];

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

            var todos = jsonRecommendation["tips"];
            var tips  = new List <Tip>();

            if (todos != null)
            {
                foreach (var todo in todos)
                {
                    tips.Add(Tip.ParseJson(todo));
                }
                if (tips.Count > 0)
                {
                    recommendation.PrimaryTip = tips[0];
                }
            }
            recommendation.Tips = tips;

            return(recommendation);
        }
Ejemplo n.º 6
0
        // DESIGN: Not a very good place for a web service call like this.
        public static void AddNewTip(string venueId, string tipText, Stream photo, Action <Tip, Exception> result)
        {
            // NOTE: Official API supports an extra "url" parameter to associate
            var client = (new FourSquareWebClient()).GetWrappedClientTemporary();
            var uuri   = FourSquareWebClient.BuildFourSquareUri(
                "tips/add",
                GeoMethodType.None,
                "venueId",
                venueId,
                "text",
                tipText);
            Uri uri    = uuri.Uri;
            var newUri = FourSquareWebClient.CreateServiceRequest(uri, true);

            client.UploadStringCompleted += (x, xe) =>
            {
                Exception e = null;
                Tip       t = null;

                if (xe.Error != null)
                {
                    e = xe.Error;
                }
                else
                {
                    string rs = xe.Result;
                    try
                    {
                        var json = FourSquareDataLoaderBase <LoadContext> .ProcessMetaAndNotificationsReturnJson(rs);

                        Tip tip = Tip.ParseJson(json["tip"], typeof(Venue), venueId);

                        if (photo != null)
                        {
                            // Result comes after the photo upload.
                            var req = Model.PhotoAddLoadContext.AddPhotoToTip(tip.TipId, false, false);
                            req.SetPhotoBytes(photo);

                            FourSquare.Instance.AddPhoto(req,

                                                         (pic) =>
                            {
                                // that's it..
                                //RefreshVenue(null);
                                result(tip, null);
                            },

                                                         (fail) =>
                            {
                                result(null, fail);
                            });
                        }
                    }
                    catch (Exception ee)
                    {
                        e = new UserIntendedException("There was a problem adding the tip, please try again later.", ee);
                    }
                }
                client = null;

                // Result now if there is not a photo.
                if (photo == null)
                {
                    result(t, e);
                }
            };

            // POST request.
            client.UploadStringAsync(newUri, string.Empty);
            //client.DownloadStringAsyncWithPost(r, string.Empty);
        }
Ejemplo n.º 7
0
        public static Tip ParseJson(JToken tip, Type parentType, string parentIdentifier)
        {
            var t = new Tip();

            t.ParentType       = parentType;
            t.ParentIdentifier = parentIdentifier;

            t.TipId = Json.TryGetJsonProperty(tip, "id");
            Debug.Assert(t.TipId != null);

            string txt = Checkin.SanitizeString(Json.TryGetJsonProperty(tip, "text"));

            if (!string.IsNullOrEmpty(txt))
            {
                t.Text = txt;
            }

            var user = tip["user"];

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

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

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

            // NOTE: Consider getting tip group details. Only available in the
            // request. Would be a nice future release update probably.

            var todoCount = tip["todo"];

            if (todoCount != null)
            {
                string cc = Json.TryGetJsonProperty(todoCount, "count");
                int    i;
                if (int.TryParse(cc, out i))
                {
                    t.TodoCount = i;
                }
            }

            var doneCount = tip["done"];

            if (doneCount != null)
            {
                string cc = Json.TryGetJsonProperty(doneCount, "count");
                int    i;
                if (int.TryParse(cc, out i))
                {
                    t.DoneCount = i;
                }
            }

            if (t.DoneCount <= 0)
            {
                t.DoneText = "No one has done this.";
            }
            else if (t.DoneCount == 1)
            {
                t.DoneText = "1 person has done this.";
            }
            else
            {
                t.DoneText = t.DoneCount.ToString(CultureInfo.InvariantCulture) + " people have done this.";
            }

            var photo = tip["photo"];

            if (photo != null)
            {
                var pht = Model.Photo.ParseJson(photo);
                if (pht != null)
                {
                    t.Photo = pht;
                }
            }

            string status = Json.TryGetJsonProperty(tip, "status");

            //Debug.WriteLine("tip status read as (temp): " + status);
            t.Status = TipStatus.None;
            if (status != null)
            {
                if (status == "done")
                {
                    t.Status     = TipStatus.Done;
                    t.StatusText = "You've done this!";
                }
                else if (status == "todo")
                {
                    t.Status     = TipStatus.Todo;
                    t.StatusText = "You need to do this!";

                    // Don't tell the user nobody has done this if it's just them.
                    if (t.DoneCount <= 0)
                    {
                        t.DoneText = null;
                    }
                }
            }

            var compactVenue = tip["venue"];

            if (compactVenue != null)
            {
                t.Venue = CompactVenue.ParseJson(compactVenue);
            }

            string parentTypeText = t.ParentType == typeof(Model.Venue) ? "venue" : null;

            if (parentTypeText == null)
            {
                if (t.ParentType == typeof(Model.UserTips))
                {
                    parentTypeText = "usertips";
                }
                else if (t.ParentType == typeof(RecommendedTipNotification) || t.ParentType == typeof(DetailedTip))
                {
                    parentTypeText = "direct";
                }
                else
                {
                    parentTypeText = "unknown";
                }
            }

            Uri tipUri = new Uri(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "/JeffWilcox.FourthAndMayor.Lists;component/ListItem.xaml?id={0}&tipId={0}",
                    Uri.EscapeDataString(t.TipId))
                , UriKind.Relative);

            t.TipUri = tipUri;

            // TODO: This supports todo w/count, done w/count, ...

            return(t);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public static Tip ParseJson(JToken tip, Type parentType, string parentIdentifier)
        {
            var t = new Tip();

            t.ParentType = parentType;
            t.ParentIdentifier = parentIdentifier;

            t.TipId = Json.TryGetJsonProperty(tip, "id");
            Debug.Assert(t.TipId != null);

            string txt = Checkin.SanitizeString(Json.TryGetJsonProperty(tip, "text"));
            if (!string.IsNullOrEmpty(txt))
            {
                t.Text = txt;
            }

            var user = tip["user"];
            if (user != null)
            {
                t.User = CompactUser.ParseJson(user);
            }

            string created = Json.TryGetJsonProperty(tip, "createdAt");
            if (created != null)
            {
                DateTime dtc = UnixDate.ToDateTime(created);
                t.CreatedDateTime = dtc;
                t.Created = Checkin.GetDateString(dtc);
            }

            // NOTE: Consider getting tip group details. Only available in the
            // request. Would be a nice future release update probably.

            var todoCount = tip["todo"];
            if (todoCount != null)
            {
                string cc = Json.TryGetJsonProperty(todoCount, "count");
                int i;
                if (int.TryParse(cc, out i))
                {
                    t.TodoCount = i;
                }
            }

            var doneCount = tip["done"];
            if (doneCount != null)
            {
                string cc = Json.TryGetJsonProperty(doneCount, "count");
                int i;
                if (int.TryParse(cc, out i))
                {
                    t.DoneCount = i;
                }
            }

            if (t.DoneCount <= 0)
                t.DoneText = "No one has done this.";
            else if (t.DoneCount == 1)
                t.DoneText = "1 person has done this.";
            else
                t.DoneText = t.DoneCount.ToString(CultureInfo.InvariantCulture) + " people have done this.";

            var photo = tip["photo"];
            if (photo != null)
            {
                var pht = Model.Photo.ParseJson(photo);
                if (pht != null)
                {
                    t.Photo = pht;
                }
            }

            string status = Json.TryGetJsonProperty(tip, "status");
            //Debug.WriteLine("tip status read as (temp): " + status);
            t.Status = TipStatus.None;
            if (status != null)
            {
                if (status == "done")
                {
                    t.Status = TipStatus.Done;
                    t.StatusText = "You've done this!";
                }
                else if (status == "todo")
                {
                    t.Status = TipStatus.Todo;
                    t.StatusText = "You need to do this!";

                    // Don't tell the user nobody has done this if it's just them.
                    if (t.DoneCount <= 0)
                    {
                        t.DoneText = null;
                    }
                }
            }

            var compactVenue = tip["venue"];
            if (compactVenue != null)
            {
                t.Venue = CompactVenue.ParseJson(compactVenue);
            }

            string parentTypeText = t.ParentType == typeof(Model.Venue) ? "venue" : null;
            if (parentTypeText == null)
            {
                if (t.ParentType == typeof (Model.UserTips))
                {
                    parentTypeText = "usertips";
                }
                else if (t.ParentType == typeof(RecommendedTipNotification) || t.ParentType == typeof(DetailedTip))
                {
                    parentTypeText = "direct";
                }
                else
                {
                    parentTypeText = "unknown";
                }
            }

            Uri tipUri = new Uri(
                string.Format(
                CultureInfo.InvariantCulture,
                "/JeffWilcox.FourthAndMayor.Lists;component/ListItem.xaml?id={0}&tipId={0}",
                                               Uri.EscapeDataString(t.TipId))
                                               , UriKind.Relative);

            t.TipUri = tipUri;

            // TODO: This supports todo w/count, done w/count, ...

            return t;
        }
Ejemplo n.º 10
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);
            }
Ejemplo n.º 11
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;
        }