public string Register(PushUserServiceRequest pushUserRegister)
        {
            // Authenticate.
            var userId = this.UserId;

            try
            {
                var pushUserEndpoint = this.pushUserEndpointsRepository.GetPushUserByApplicationAndDevice(pushUserRegister.ApplicationId, pushUserRegister.DeviceId);
                if (pushUserEndpoint == null)
                {
                    var newPushUserEndPoint = new PushUserEndpoint(pushUserRegister.ApplicationId, pushUserRegister.DeviceId) { ChannelUri = pushUserRegister.ChannelUri.ToString(), UserId = userId };
                    this.pushUserEndpointsRepository.AddPushUserEndpoint(newPushUserEndPoint);
                }
                else
                {
                    // If the user did not change the channel URI, then, there is nothing to update, otherwise, set the new connection status
                    if (!pushUserEndpoint.ChannelUri.Equals(pushUserRegister.ChannelUri.ToString()) ||
                        !pushUserEndpoint.UserId.Equals(userId))
                    {
                        // Update che channelUri for the UserEndpoint and reset status fields.
                        pushUserEndpoint.ChannelUri = pushUserRegister.ChannelUri.ToString();
                        pushUserEndpoint.UserId = userId;
                    }

                    this.pushUserEndpointsRepository.UpdatePushUserEndpoint(pushUserEndpoint);
                }
            }
            catch (Exception exception)
            {
                throw new WebFaultException<string>(
                    string.Format(CultureInfo.InvariantCulture, "There was an error registering the Push Notification Endpoint: {0}", exception.Message),
                    HttpStatusCode.InternalServerError);
            }

            return "Success";
        }
Пример #2
0
        private static void CreatePushNotificationTable(CloudTableClient cloudTableClient)
        {
            cloudTableClient.CreateTableIfNotExist(UserTablesServiceContext.PushUserTableName);

            // Execute conditionally for development storage only.
            if (cloudTableClient.BaseUri.IsLoopback)
            {
                var context = cloudTableClient.GetDataServiceContext();
                var entity = new PushUserEndpoint("applicationID", "deviceID") { UserId = "UserName", ChannelUri = "http://tempuri", TileCount = 0 };

                context.AddObject(UserTablesServiceContext.PushUserTableName, entity);
                context.SaveChangesWithRetries();
                context.DeleteObject(entity);
                context.SaveChangesWithRetries();
            }
        }
 public void UpdatePushUserEndpoint(PushUserEndpoint pushUserEndpoint)
 {
     this.UpdateObject(pushUserEndpoint);
     this.SaveChanges();
 }
        public void RemovePushUserEndpoint(PushUserEndpoint pushUserEndpointData)
        {
            var pushUserEndpoint = this.GetPushUserByApplicationAndDevice(pushUserEndpointData.PartitionKey, pushUserEndpointData.RowKey);

            this.DeleteObject(pushUserEndpoint);

            this.SaveChanges();
        }
 public void AddPushUserEndpoint(PushUserEndpoint pushUserEndPoint)
 {
     this.AddObject(PushUserTableName, pushUserEndPoint);
     this.SaveChanges();
 }
        private void QueueMessage(PushUserEndpoint pushUser, string message)
        {
            var queueName = GetQueueName(pushUser.PartitionKey, pushUser.RowKey, pushUser.UserId);
            var queue = this.cloudQueueClient.GetQueueReference(queueName);

            queue.CreateIfNotExist();
            queue.AddMessage(new CloudQueueMessage(message));
        }