public static UserNotificationChannelDto FromDomainObject(UserNotificationChannel source) { var result = SimpleMapper.Map(source, new UserNotificationChannelDto { Status = new Dictionary <string, ChannelSendInfoDto>() }); if (source.Setting != null) { result.Setting = ChannelSettingDto.FromDomainObject(source.Setting); } else { result.Setting = new ChannelSettingDto(); } if (source.Status != null) { foreach (var(key, value) in source.Status) { result.Status[key] = ChannelSendInfoDto.FromDomainObject(value); } } return(result); }
public UserNotificationsManager(ConnectedDevicesPlatform platform, ConnectedDevicesAccount account) { m_feed = UserDataFeed.GetForAccount(account, platform, Secrets.APP_HOST_NAME); m_feed.SyncStatusChanged += Feed_SyncStatusChanged; m_channel = new UserNotificationChannel(m_feed); m_reader = m_channel.CreateReader(); m_reader.DataChanged += Reader_DataChanged; Logger.Instance.LogMessage($"Setup feed for {account.Id} {account.Type}"); }
private async Task <UserNotification> CreateUserNotificationAsync(UserEventMessage userEvent, SendOptions options) { using (Telemetry.Activities.StartActivity("CreateUserNotification")) { var notification = userNotificationFactory.Create(options.App, options.User, userEvent); if (notification == null) { throw new DomainException(Texts.Notification_NoSubject); } foreach (var channel in channels) { if (channel.IsSystem && !string.IsNullOrWhiteSpace(channel.Name)) { if (!notification.Channels.TryGetValue(channel.Name, out var channelInfo)) { channelInfo = new UserNotificationChannel { Setting = new ChannelSetting { Send = ChannelSend.Send } }; notification.Channels[channel.Name] = channelInfo; } } if (notification.Channels.TryGetValue(channel.Name, out var channelConfig) && channelConfig.Setting.Send == ChannelSend.Send) { var configurations = channel.GetConfigurations(notification, channelConfig.Setting, options); foreach (var configuration in configurations) { if (!string.IsNullOrWhiteSpace(configuration)) { channelConfig.Status[configuration] = new ChannelSendInfo(); await userNotificationsStore.CollectAsync(notification, channel.Name, ProcessStatus.Attempt); } } } } return(notification); } }
private async Task SetupChannel() { var account = m_accoutProvider.SignedInAccount; if (account != null && m_platform == null) { m_platform = new ConnectedDevicesPlatform(m_accoutProvider, this); } if (m_feed == null) { // Need to run UserDataFeed creation on a background thread // because MSA/AAD token request might need to show UI. await Task.Run(() => { lock (this) { if (account != null && m_feed == null) { try { m_feed = new UserDataFeed(account, m_platform, "graphnotifications.sample.windows.com"); m_feed.SyncStatusChanged += Feed_SyncStatusChanged; m_feed.AddSyncScopes(new List <IUserDataFeedSyncScope> { UserNotificationChannel.SyncScope }); m_channel = new UserNotificationChannel(m_feed); m_reader = m_channel.CreateReader(); m_reader.DataChanged += Reader_DataChanged; Logger.Instance.LogMessage($"Setup feed for {account.Id} {account.Type}"); } catch (Exception ex) { Logger.Instance.LogMessage($"Failed to setup UserNotificationChannel {ex.Message}"); m_feed = null; } } } }); } }