Exemplo n.º 1
0
        public static Notification ParseJson(JToken notification, string venueId)
        {
            Notification n = null;

            string type = Json.TryGetJsonProperty(notification, "type");
            var    item = notification["item"];

            if (item != null)
            {
                switch (type)
                {
                case "message":
                    n = new MessageNotification(item);
                    break;

                case "badge":
                    n = new BadgeNotification(item);
                    break;

                case "mayorship":
                    n = new MayorshipNotification(item);
                    break;

                case "tip":
                    n = new RecommendedTipNotification(item);
                    break;

                case "leaderboard":
                    n = new LeaderboardNotification(item);
                    break;

                case "special":
                    // TODO: Implement special support in notificationis. Comes AFTER mayor and BEFORE tip and points.
                    n = new SpecialNotification(item, venueId);
                    break;

                case "score":
                    n = new ScoreNotification(item);
                    break;

                default:
                    // Consider a silent watson here about the type.
                    var hasMessage = item["message"];
                    if (hasMessage != null)
                    {
                        n = new MessageNotification(item);
                    }
                    // else n is null

                    break;
                }
            }

            return(n);
        }
Exemplo n.º 2
0
        public static Notification ParseJson(JToken notification, string venueId)
        {
            Notification n = null;

            string type = Json.TryGetJsonProperty(notification, "type");
            var item = notification["item"];

            if (item != null)
            {
                switch (type)
                {
                    case "message":
                        n = new MessageNotification(item);
                        break;

                    case "badge":
                        n = new BadgeNotification(item);
                        break;

                    case "mayorship":
                        n = new MayorshipNotification(item);
                        break;

                    case "tip":
                        n = new RecommendedTipNotification(item);
                        break;

                    case "leaderboard":
                        n = new LeaderboardNotification(item);
                        break;

                    case "special":
                        // TODO: Implement special support in notificationis. Comes AFTER mayor and BEFORE tip and points.
                        n = new SpecialNotification(item, venueId);
                        break;

                    case "score":
                        n = new ScoreNotification(item);
                        break;

                    default:
                        // Consider a silent watson here about the type.
                        var hasMessage = item["message"];
                        if (hasMessage != null)
                        {
                            n = new MessageNotification(item);
                        }
                        // else n is null

                        break;
                }
            }

            return n;
        }