Ejemplo n.º 1
0
        public bool RegisterPushDevice(UserProfile user, PushDeviceRegistrationModel deviceRegistrationModel)
        {
            UserPushNotificationDevice userPushNotificationDevice = _userPushNotificationDeviceRepository.ReadUserDevice(user.UserId, deviceRegistrationModel.DeviceId, deviceRegistrationModel.DeviceOS);

            if (userPushNotificationDevice == null)
            {
                userPushNotificationDevice = new UserPushNotificationDevice()
                {
                    DeviceOS = deviceRegistrationModel.DeviceOS,
                    DeviceId = deviceRegistrationModel.DeviceId,
                    UserId   = user.UserId
                };
            }

            userPushNotificationDevice.ProviderToken      = deviceRegistrationModel.ProviderToken;
            userPushNotificationDevice.ProviderEndpointId = _pushNotificationMessageProvider.RegisterRecipient(userPushNotificationDevice);
            userPushNotificationDevice.Enabled            = true;

            _userPushNotificationDeviceRepository.CreateOrUpdate(userPushNotificationDevice);
            _uow.SaveChanges();

            // now, to create/confirm/update the application endpoint in AWS
            return(true);
        }
Ejemplo n.º 2
0
        private void DisableDevices(List <Recipient> badRecipients)
        {
            foreach (Recipient recipient in badRecipients)
            {
                UserPushNotificationDevice device = _userPushNotificationDeviceRepository.ReadUserDevice(recipient.UserId, recipient.DeviceId, recipient.DeviceOS.Value);

                if (device != null)
                {
                    device.Enabled     = false;
                    device.ModifiedUtc = DateTime.Now.ToUniversalTime();

                    _unitOfWork.SaveChanges();

                    StringBuilder msg = new StringBuilder();

                    msg.AppendLine("Disabling device.");
                    msg.AppendLine("DeviceId: {DeviceId}");
                    msg.AppendLine("DeviceOS: {DeviceOS}");
                    msg.AppendLine("ProviderEndPoint: {ProviderEndpoint}");

                    _eventLog.WriteInformationLog(msg.ToString().Inject(recipient));
                }
            }
        }