예제 #1
0
        public void Push(string userId, string objectId, string type, string message, int?badge = null)
        {
            var context = new PushContext();
            var hashed  = userId.PrependHash();
            var pushes  = (from item in context.NotiUserSubscriptions.Query()
                           where item.UserId == hashed
                           select item).ToLookup(item => item.Platform);

            Push(pushes, objectId, type, message, badge);
        }
예제 #2
0
        public void Push(int start, int end, string objectId, string type, string message)
        {
            var startHash = start.ToString("00000") + "|";
            var endHash   = end.ToString("00000") + "||";

            var context = new PushContext();
            var pushes  = (from item in context.NotiUserSubscriptions.Query()
                           where item.UserId.CompareTo(startHash) > 0 &&
                           item.UserId.CompareTo(endHash) < 0
                           select item).ToLookup(item => item.Platform);

            Push(pushes, objectId, type, message, null);
        }
예제 #3
0
        public NotiSubscription RemoveSubscription(string subscriptionId)
        {
            var context      = new PushContext();
            var nosign       = subscriptionId.RemoveSign();
            var subscription = (from item in context.NotiSubscriptions.Query()
                                where item.PartitionKey == nosign &&
                                item.Token == subscriptionId
                                select item).FirstOrDefault();

            if (subscription == null)
            {
                return(null);
            }

            context.NotiUserSubscriptions.SafeDelete(subscription.UserId.PrependHash(), nosign);
            context.NotiSubscriptions.SafeDelete(subscription);
            return(subscription);
        }
예제 #4
0
        public void AddSubscription(string userId, string platform, string subscriptionId)
        {
            //check if subscription already exists
            var context      = new PushContext();
            var nosign       = subscriptionId.RemoveSign();
            var subscription = (from item in context.NotiSubscriptions.Query()
                                where item.PartitionKey == nosign &&
                                item.Token == subscriptionId
                                select item).FirstOrDefault();

            if (subscription != null)
            {
                if (subscription.UserId == userId)
                {
                    return;
                }

                context.NotiUserSubscriptions.SafeDelete(userId.PrependHash(), nosign);
            }

            //insert subscription
            subscription = new NotiSubscription
            {
                PartitionKey = nosign,
                RowKey       = Guid.NewGuid().ToString("N"),
                Token        = subscriptionId,
                UserId       = userId,
                Platform     = platform,
            };
            context.NotiSubscriptions.Insert(subscription, true);
            var userSubscription = new NotiUserSubscription
            {
                PartitionKey = userId.PrependHash(),
                RowKey       = nosign,
                Platform     = platform,
                UserId       = userId,
                Token        = subscriptionId,
            };

            context.NotiUserSubscriptions.Insert(userSubscription, true);
        }