Пример #1
0
        public async Task <IActionResult> DeleteDevice([FromRoute] string deviceId)
        {
            var user = await UserManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound());
            }
            var device = DbContext.UserDevices.SingleOrDefault(x => x.UserId == user.Id && x.DeviceId == deviceId);

            if (device is null)
            {
                return(NotFound());
            }
            try {
                await PushNotificationService.UnRegister(deviceId);
            } catch (Exception exception) {
                Logger.LogError("An exception occurred when connection to Azure Notification Hubs. Exception is '{Exception}'. Inner Exception is '{InnerException}'.", exception.Message, exception.InnerException?.Message ?? "N/A");
                throw;
            }
            DbContext.UserDevices.Remove(device);
            await DbContext.SaveChangesAsync();

            var @event = new DeviceDeletedEvent(DeviceInfo.FromUserDevice(device), SingleUserInfo.FromUser(user));
            await EventService.Publish(@event);

            return(NoContent());
        }
Пример #2
0
        public async Task OnMessageAsync(DeviceDeletedEvent deviceDeletedEvent)
        {
            var device = deviceDeletedEvent.Device;

            Logger.LogMessage("Device deleted event: UserId: {0}", device.UserId);

            PurgeOldMediaRequestEvent purgeOldMediaRequest = new PurgeOldMediaRequestEvent
            {
                UpTo = DateTime.UtcNow,
                User = deviceDeletedEvent.Device
            };
            await _bus.PublishAsync(purgeOldMediaRequest);
        }
Пример #3
0
        public async Task OnMessageAsync(DeviceDeletedEvent obj)
        {
            _logger.LogInformation("DeviceDeletedEvent: {0}", obj.Device.UserId);

            try
            {
                await _membershipService.DeleteUserAsync(obj.Device.AccountId, obj.Device.UserId);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to delete device user properties");
                // Sink.
            }
        }
        private void DeviceRemovedEvent(object sender, EventArrivedEventArgs e)
        {
            try {
                Dictionary <string, string> properties = new Dictionary <string, string>();
                ManagementBaseObject        instance   = (ManagementBaseObject)e.NewEvent["TargetInstance"];
                foreach (var p in instance.Properties)
                {
                    if (p.Value != null)
                    {
                        properties.Add(p.Name, p.Value.ToString());
                    }
                }

                DeviceDeletedEvent?.Invoke(properties);
            } catch (PDException ex) {
                throw new PDException("invalid device removed", ex);
            }
        }