/// <summary> /// Initializes a new instance of the <see cref="DraftNotificationPreviewService"/> class. /// </summary> /// <param name="botOptions">The bot options.</param> /// <param name="adaptiveCardCreator">Adaptive card creator service.</param> /// <param name="companyCommunicatorBotAdapter">Bot framework http adapter instance.</param> public DraftNotificationPreviewService( IOptions <BotOptions> botOptions, AdaptiveCardCreator adaptiveCardCreator, CompanyCommunicatorBotAdapter companyCommunicatorBotAdapter) { var options = botOptions ?? throw new ArgumentNullException(nameof(botOptions)); this.botAppId = options.Value.AuthorAppId; if (string.IsNullOrEmpty(this.botAppId)) { throw new ApplicationException("AuthorAppId setting is missing in the configuration."); } this.adaptiveCardCreator = adaptiveCardCreator ?? throw new ArgumentNullException(nameof(adaptiveCardCreator)); this.companyCommunicatorBotAdapter = companyCommunicatorBotAdapter ?? throw new ArgumentNullException(nameof(companyCommunicatorBotAdapter)); }
/// <summary> /// Initializes a new instance of the <see cref="AuthorTeamsActivityHandler"/> class. /// </summary> /// <param name="teamsFileUpload">File upload service.</param> /// <param name="userDataService">User data service.</param> /// <param name="appSettingsService">App Settings service.</param> /// <param name="notificationDataRepository">Notification data repository service that deals with the table storage in azure.</param> /// <param name="channelDataRepository">ChannelDataRepository.</param> /// <param name="adaptiveCardCreator">adaptiveCardCreator .</param> /// <param name="templateDataRepository">templateD ataRepository.</param> /// <param name="localizer">Localization service.</param> public AuthorTeamsActivityHandler( TeamsFileUpload teamsFileUpload, IUserDataService userDataService, IAppSettingsService appSettingsService, INotificationDataRepository notificationDataRepository, IChannelDataRepository channelDataRepository, AdaptiveCardCreator adaptiveCardCreator, ITemplateDataRepository templateDataRepository, IStringLocalizer <Strings> localizer) { this.userDataService = userDataService ?? throw new ArgumentNullException(nameof(userDataService)); this.teamsFileUpload = teamsFileUpload ?? throw new ArgumentNullException(nameof(teamsFileUpload)); this.appSettingsService = appSettingsService ?? throw new ArgumentNullException(nameof(appSettingsService)); this.notificationDataRepository = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository)); this.adaptiveCardCreator = adaptiveCardCreator ?? throw new ArgumentNullException(nameof(adaptiveCardCreator)); this.templateDataRepository = templateDataRepository ?? throw new ArgumentNullException(nameof(templateDataRepository)); this.channelDataRepository = channelDataRepository ?? throw new ArgumentNullException(nameof(channelDataRepository)); this.localizer = localizer ?? throw new ArgumentNullException(nameof(localizer)); }
public async Task RunAsync( [TimerTrigger("0 */30 * * * *")] TimerInfo scheduleInitializationTimer, ILogger log) { scheduleInitializationTimer = scheduleInitializationTimer ?? throw new ArgumentNullException(nameof(scheduleInitializationTimer)); log.LogInformation($"Schedule Initialization Timer executed at: {scheduleInitializationTimer.ToString()}."); CompanyCommunicatorScheduleFunction.configuration = CompanyCommunicatorScheduleFunction.configuration ?? new ConfigurationBuilder() .AddEnvironmentVariables() .Build(); CompanyCommunicatorScheduleFunction.adaptiveCardCreator = CompanyCommunicatorScheduleFunction.adaptiveCardCreator ?? new AdaptiveCardCreator(); CompanyCommunicatorScheduleFunction.tableRowKeyGenerator = CompanyCommunicatorScheduleFunction.tableRowKeyGenerator ?? new TableRowKeyGenerator(); CompanyCommunicatorScheduleFunction.adGroupsDataRepository = CompanyCommunicatorScheduleFunction.adGroupsDataRepository ?? new ADGroupsDataRepository(CompanyCommunicatorScheduleFunction.configuration, true); CompanyCommunicatorScheduleFunction.notificationDataRepository = CompanyCommunicatorScheduleFunction.notificationDataRepository ?? new NotificationDataRepository(CompanyCommunicatorScheduleFunction.configuration, CompanyCommunicatorScheduleFunction.adGroupsDataRepository, tableRowKeyGenerator, true); CompanyCommunicatorScheduleFunction.userDataRepository = CompanyCommunicatorScheduleFunction.userDataRepository ?? new UserDataRepository(CompanyCommunicatorScheduleFunction.configuration, true); CompanyCommunicatorScheduleFunction.teamDataRepository = CompanyCommunicatorScheduleFunction.teamDataRepository ?? new TeamDataRepository(CompanyCommunicatorScheduleFunction.configuration, true); CompanyCommunicatorScheduleFunction.sendingNotificationDataRepository = CompanyCommunicatorScheduleFunction.sendingNotificationDataRepository ?? new SendingNotificationDataRepository(CompanyCommunicatorScheduleFunction.configuration, true); CompanyCommunicatorScheduleFunction.globalSendingNotificationDataRepository = CompanyCommunicatorScheduleFunction.globalSendingNotificationDataRepository ?? new GlobalSendingNotificationDataRepository(CompanyCommunicatorScheduleFunction.configuration, true); CompanyCommunicatorScheduleFunction.sentNotificationDataRepository = CompanyCommunicatorScheduleFunction.sentNotificationDataRepository ?? new SentNotificationDataRepository(CompanyCommunicatorScheduleFunction.configuration, true); CompanyCommunicatorScheduleFunction.metadataProvider = CompanyCommunicatorScheduleFunction.metadataProvider ?? new MetadataProvider(CompanyCommunicatorScheduleFunction.configuration, userDataRepository, teamDataRepository, notificationDataRepository, adGroupsDataRepository); CompanyCommunicatorScheduleFunction.sendingNotificationCreator = CompanyCommunicatorScheduleFunction.sendingNotificationCreator ?? new SendingNotificationCreator(CompanyCommunicatorScheduleFunction.configuration, notificationDataRepository, sendingNotificationDataRepository, adaptiveCardCreator); CompanyCommunicatorScheduleFunction.scheduleNotificationDelivery = CompanyCommunicatorScheduleFunction.scheduleNotificationDelivery ?? new ScheduleNotificationDelivery(CompanyCommunicatorScheduleFunction.configuration, notificationDataRepository, metadataProvider, sendingNotificationCreator, scheduleNotificationDataRepository, teamDataRepository); CompanyCommunicatorScheduleFunction.scheduleNotificationDataRepository = CompanyCommunicatorScheduleFunction.scheduleNotificationDataRepository ?? new ScheduleNotificationDataRepository(CompanyCommunicatorScheduleFunction.configuration, notificationDataRepository, metadataProvider, sendingNotificationCreator, scheduleNotificationDelivery, true); // Generate filter condition to get pending notifications. var rowKeyFilter = TableQuery.GenerateFilterConditionForDate( nameof(ScheduleNotificationDataEntity.NotificationDate), QueryComparisons.LessThanOrEqual, DateTime.UtcNow); // Get records which are pending to send notification. var pendingNotifications = await CompanyCommunicatorScheduleFunction.scheduleNotificationDataRepository.GetWithFilterAsync( rowKeyFilter); // Repeat all pending notifications. foreach (var pendingNotification in pendingNotifications) { try { log.LogInformation($"Schedule notification triggered for " + pendingNotification.NotificationId); string returnMessage = await CompanyCommunicatorScheduleFunction.scheduleNotificationDataRepository.SendNotificationandCreateScheduleAsync(pendingNotification); if (string.IsNullOrEmpty(returnMessage)) { log.LogInformation($"Schedule notification success for " + pendingNotification.NotificationId); } else { log.LogInformation($"Schedule notification failed for " + pendingNotification.NotificationId); } } catch (Exception ex) { log.LogError($"Error while sending schedule notification:" + pendingNotification.NotificationId, ex); } } }
public async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) { // scheduleInitializationTimer = scheduleInitializationTimer ?? throw new ArgumentNullException(nameof(scheduleInitializationTimer)); //log.LogInformation($"Schedule Initialization Timer executed at: {scheduleInitializationTimer.ToString()}."); SchduleNotificationTestFunction.configuration = SchduleNotificationTestFunction.configuration ?? new ConfigurationBuilder() .AddEnvironmentVariables() .Build(); SchduleNotificationTestFunction.adaptiveCardCreator = SchduleNotificationTestFunction.adaptiveCardCreator ?? new AdaptiveCardCreator(); SchduleNotificationTestFunction.tableRowKeyGenerator = SchduleNotificationTestFunction.tableRowKeyGenerator ?? new TableRowKeyGenerator(); SchduleNotificationTestFunction.adGroupsDataRepository = SchduleNotificationTestFunction.adGroupsDataRepository ?? new ADGroupsDataRepository(SchduleNotificationTestFunction.configuration, true); SchduleNotificationTestFunction.notificationDataRepository = SchduleNotificationTestFunction.notificationDataRepository ?? new NotificationDataRepository(SchduleNotificationTestFunction.configuration, SchduleNotificationTestFunction.adGroupsDataRepository, tableRowKeyGenerator, true); SchduleNotificationTestFunction.userDataRepository = SchduleNotificationTestFunction.userDataRepository ?? new UserDataRepository(SchduleNotificationTestFunction.configuration, true); SchduleNotificationTestFunction.teamDataRepository = SchduleNotificationTestFunction.teamDataRepository ?? new TeamDataRepository(SchduleNotificationTestFunction.configuration, true); SchduleNotificationTestFunction.sendingNotificationDataRepository = SchduleNotificationTestFunction.sendingNotificationDataRepository ?? new SendingNotificationDataRepository(SchduleNotificationTestFunction.configuration, true); SchduleNotificationTestFunction.globalSendingNotificationDataRepository = SchduleNotificationTestFunction.globalSendingNotificationDataRepository ?? new GlobalSendingNotificationDataRepository(SchduleNotificationTestFunction.configuration, true); SchduleNotificationTestFunction.sentNotificationDataRepository = SchduleNotificationTestFunction.sentNotificationDataRepository ?? new SentNotificationDataRepository(SchduleNotificationTestFunction.configuration, true); SchduleNotificationTestFunction.metadataProvider = SchduleNotificationTestFunction.metadataProvider ?? new MetadataProvider(SchduleNotificationTestFunction.configuration, userDataRepository, teamDataRepository, notificationDataRepository, adGroupsDataRepository); SchduleNotificationTestFunction.sendingNotificationCreator = SchduleNotificationTestFunction.sendingNotificationCreator ?? new SendingNotificationCreator(SchduleNotificationTestFunction.configuration, notificationDataRepository, sendingNotificationDataRepository, adaptiveCardCreator); SchduleNotificationTestFunction.scheduleNotificationDelivery = SchduleNotificationTestFunction.scheduleNotificationDelivery ?? new ScheduleNotificationDelivery(SchduleNotificationTestFunction.configuration, notificationDataRepository, metadataProvider, sendingNotificationCreator, scheduleNotificationDataRepository, teamDataRepository); SchduleNotificationTestFunction.scheduleNotificationDataRepository = SchduleNotificationTestFunction.scheduleNotificationDataRepository ?? new ScheduleNotificationDataRepository(SchduleNotificationTestFunction.configuration, notificationDataRepository, metadataProvider, sendingNotificationCreator, scheduleNotificationDelivery, true); // Generate filter condition to get pending notifications. var rowKeyFilter = TableQuery.GenerateFilterConditionForDate( nameof(ScheduleNotificationDataEntity.NotificationDate), QueryComparisons.LessThanOrEqual, DateTime.UtcNow); // Get records which are pending to send notification. var pendingNotifications = await SchduleNotificationTestFunction.scheduleNotificationDataRepository.GetWithFilterAsync( rowKeyFilter); // Repeat all pending notifications. foreach (var pendingNotification in pendingNotifications) { try { log.LogInformation($"Schedule notification triggered for " + pendingNotification.NotificationId); string returnMessage = await SchduleNotificationTestFunction.scheduleNotificationDataRepository.SendNotificationandCreateScheduleAsync(pendingNotification); if (string.IsNullOrEmpty(returnMessage)) { log.LogInformation($"Schedule notification success for " + pendingNotification.NotificationId); } else { log.LogInformation($"Schedule notification failed for " + pendingNotification.NotificationId); } } catch (Exception ex) { log.LogError($"Error while sending schedule notification:" + pendingNotification.NotificationId, ex); } } return(await Task.FromResult((ActionResult) new OkObjectResult("OK"))); }
/// <summary> /// Initializes a new instance of the <see cref="CompanyCommunicatorBot"/> class. /// </summary> /// <param name="teamsDataCapture">Teams data capture service.</param> /// <param name="adaptiveCardCreator">To regenerate adaptive card with full text.</param> public CompanyCommunicatorBot(TeamsDataCapture teamsDataCapture, AdaptiveCardCreator adaptiveCardCreator) { this.teamsDataCapture = teamsDataCapture; this.adaptiveCardCreator = adaptiveCardCreator; }