Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompanyCommunicatorExportFunction"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 /// <param name="exportDataRepository">Export data repository.</param>
 public CompanyCommunicatorExportFunction(
     NotificationDataRepository notificationDataRepository,
     ExportDataRepository exportDataRepository)
 {
     this.notificationDataRepository = notificationDataRepository;
     this.exportDataRepository       = exportDataRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupDataController"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository instance.</param>
 /// <param name="groupsService">Microsoft Graph service instance.</param>
 public GroupDataController(
     NotificationDataRepository notificationDataRepository,
     IGroupsService groupsService)
 {
     this.notificationDataRepository = notificationDataRepository;
     this.groupsService = groupsService;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SentNotificationsController"/> class.
        /// </summary>
        /// <param name="notificationDataRepository">Notification data repository service that deals with the table storage in azure.</param>
        /// <param name="sentNotificationDataRepository">Sent notification data repository.</param>
        /// <param name="teamDataRepository">Team data repository instance.</param>
        /// <param name="prepareToSendQueue">The service bus queue for preparing to send notifications.</param>
        /// <param name="dataQueue">The service bus queue for the data queue.</param>
        /// <param name="dataQueueMessageOptions">The options for the data queue messages.</param>
        /// <param name="groupsService">The groups service.</param>
        /// <param name="exportDataRepository">The Export data repository instance.</param>
        /// <param name="appCatalogService">App catalog service.</param>
        /// <param name="appSettingsService">App settings service.</param>
        /// <param name="userAppOptions">User app options.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        public SentNotificationsController(
            NotificationDataRepository notificationDataRepository,
            SentNotificationDataRepository sentNotificationDataRepository,
            TeamDataRepository teamDataRepository,
            PrepareToSendQueue prepareToSendQueue,
            DataQueue dataQueue,
            IOptions <DataQueueMessageOptions> dataQueueMessageOptions,
            IGroupsService groupsService,
            ExportDataRepository exportDataRepository,
            IAppCatalogService appCatalogService,
            IAppSettingsService appSettingsService,
            IOptions <UserAppOptions> userAppOptions,
            ILoggerFactory loggerFactory)
        {
            if (dataQueueMessageOptions is null)
            {
                throw new ArgumentNullException(nameof(dataQueueMessageOptions));
            }

            this.notificationDataRepository     = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository));
            this.sentNotificationDataRepository = sentNotificationDataRepository ?? throw new ArgumentNullException(nameof(sentNotificationDataRepository));
            this.teamDataRepository             = teamDataRepository ?? throw new ArgumentNullException(nameof(teamDataRepository));
            this.prepareToSendQueue             = prepareToSendQueue ?? throw new ArgumentNullException(nameof(prepareToSendQueue));
            this.dataQueue = dataQueue ?? throw new ArgumentNullException(nameof(dataQueue));
            this.forceCompleteMessageDelayInSeconds = dataQueueMessageOptions.Value.ForceCompleteMessageDelayInSeconds;
            this.groupsService        = groupsService ?? throw new ArgumentNullException(nameof(groupsService));
            this.exportDataRepository = exportDataRepository ?? throw new ArgumentNullException(nameof(exportDataRepository));
            this.appCatalogService    = appCatalogService ?? throw new ArgumentNullException(nameof(appCatalogService));
            this.appSettingsService   = appSettingsService ?? throw new ArgumentNullException(nameof(appSettingsService));
            this.userAppOptions       = userAppOptions?.Value ?? throw new ArgumentNullException(nameof(userAppOptions));
            this.logger = loggerFactory?.CreateLogger <SentNotificationsController>() ?? throw new ArgumentNullException(nameof(loggerFactory));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HandleFailureActivity"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 /// <param name="localizer">Localization service.</param>
 public HandleFailureActivity(
     NotificationDataRepository notificationDataRepository,
     IStringLocalizer <Strings> localizer)
 {
     this.notificationDataRepository = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository));
     this.localizer = localizer ?? throw new ArgumentNullException(nameof(localizer));
 }
        /// <summary>
        /// Create a new draft notification.
        /// </summary>
        /// <param name="notificationRepository">The notification repository.</param>
        /// <param name="notification">Draft Notification model class instance passed in from Web API.</param>
        /// <param name="userName">Name of the user who is running the application.</param>
        /// <returns>The newly created notification's id.</returns>
        public static async Task <string> CreateDraftNotificationAsync(
            this NotificationDataRepository notificationRepository,
            DraftNotification notification,
            string userName)
        {
            var newId = notificationRepository.TableRowKeyGenerator.CreateNewKeyOrderingOldestToMostRecent();

            var notificationEntity = new NotificationDataEntity
            {
                PartitionKey = NotificationDataTableNames.DraftNotificationsPartition,
                RowKey       = newId,
                Id           = newId,
                Title        = notification.Title,
                ImageLink    = notification.ImageLink,
                Summary      = notification.Summary,
                Author       = notification.Author,
                ButtonTitle  = notification.ButtonTitle,
                ButtonLink   = notification.ButtonLink,
                CreatedBy    = userName,
                CreatedDate  = DateTime.UtcNow,
                IsDraft      = true,
                Teams        = notification.Teams,
                Rosters      = notification.Rosters,
                Groups       = notification.Groups,
                AllUsers     = notification.AllUsers,
            };

            await notificationRepository.CreateOrUpdateAsync(notificationEntity);

            return(newId);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SentNotificationsController"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository service that deals with the table storage in azure.</param>
 /// <param name="notificationDelivery">Notification delivery service instance.</param>
 /// <param name="teamDataRepository">Team data repository instance.</param>
 public SentNotificationsController(
     NotificationDataRepository notificationDataRepository,
     NotificationDelivery notificationDelivery,
     TeamDataRepository teamDataRepository)
 {
     this.notificationDataRepository = notificationDataRepository;
     this.notificationDelivery       = notificationDelivery;
     this.teamDataRepository         = teamDataRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataAggregationTriggerActivity"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 /// <param name="dataQueue">The data queue.</param>
 /// <param name="options">The data queue message options.</param>
 public DataAggregationTriggerActivity(
     NotificationDataRepository notificationDataRepository,
     DataQueue dataQueue,
     IOptions <DataQueueMessageOptions> options)
 {
     this.notificationDataRepository = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository));
     this.dataQueue             = dataQueue ?? throw new ArgumentNullException(nameof(dataQueue));
     this.messageDelayInSeconds = options?.Value?.MessageDelayInSeconds ?? throw new ArgumentNullException(nameof(options));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetTeamDataEntitiesByIdsActivity"/> class.
 /// </summary>
 /// <param name="teamDataRepository">Team Data repository.</param>
 /// <param name="notificationDataRepository">Notification data entity repository.</param>
 /// <param name="localizer">Localization service.</param>
 public GetTeamDataEntitiesByIdsActivity(
     TeamDataRepository teamDataRepository,
     NotificationDataRepository notificationDataRepository,
     IStringLocalizer <Strings> localizer)
 {
     this.teamDataRepository         = teamDataRepository;
     this.notificationDataRepository = notificationDataRepository;
     this.localizer = localizer;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExportFunction"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 /// <param name="exportDataRepository">Export data repository.</param>
 /// <param name="localizer">Localization service.</param>
 public ExportFunction(
     NotificationDataRepository notificationDataRepository,
     ExportDataRepository exportDataRepository,
     IStringLocalizer <Strings> localizer)
 {
     this.notificationDataRepository = notificationDataRepository;
     this.exportDataRepository       = exportDataRepository;
     this.localizer = localizer;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DraftNotificationsController"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository instance.</param>
 /// <param name="teamDataRepository">Team data repository instance.</param>
 /// <param name="draftNotificationPreviewService">Draft notification preview service.</param>
 public DraftNotificationsController(
     NotificationDataRepository notificationDataRepository,
     TeamDataRepository teamDataRepository,
     DraftNotificationPreviewService draftNotificationPreviewService)
 {
     this.notificationDataRepository      = notificationDataRepository;
     this.teamDataRepository              = teamDataRepository;
     this.draftNotificationPreviewService = draftNotificationPreviewService;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncTeamsActivity"/> class.
 /// </summary>
 /// <param name="teamDataRepository">Team Data repository.</param>
 /// <param name="sentNotificationDataRepository">Sent notification data repository.</param>
 /// <param name="localizer">Localization service.</param>
 /// <param name="notificationDataRepository">Notification data entity repository.</param>
 public SyncTeamsActivity(
     TeamDataRepository teamDataRepository,
     SentNotificationDataRepository sentNotificationDataRepository,
     IStringLocalizer <Strings> localizer,
     NotificationDataRepository notificationDataRepository)
 {
     this.teamDataRepository             = teamDataRepository ?? throw new ArgumentNullException(nameof(teamDataRepository));
     this.sentNotificationDataRepository = sentNotificationDataRepository ?? throw new ArgumentNullException(nameof(sentNotificationDataRepository));
     this.localizer = localizer ?? throw new ArgumentNullException(nameof(localizer));
     this.notificationDataRepository = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SendingNotificationCreator"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="notificationDataRepository">Notification Repository instance.</param>
 /// <param name="sendingNotificationDataRepository">Sending notification data repository.</param>
 /// <param name="adaptiveCardCreator">The adaptive card creator</param>
 public SendingNotificationCreator(
     IConfiguration configuration,
     NotificationDataRepository notificationDataRepository,
     SendingNotificationDataRepository sendingNotificationDataRepository,
     AdaptiveCardCreator adaptiveCardCreator)
 {
     this.microsoftAppId                    = configuration["MicrosoftAppId"];
     this.microsoftAppPassword              = configuration["MicrosoftAppPassword"];
     this.notificationDataRepository        = notificationDataRepository;
     this.sendingNotificationDataRepository = sendingNotificationDataRepository;
     this.adaptiveCardCreator               = adaptiveCardCreator;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NotificationDelivery"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="notificationDataRepository">Notification repository service.</param>
 /// <param name="metadataProvider">Metadata Provider instance.</param>
 /// <param name="sendingNotificationCreator">SendingNotification creator.</param>
 /// <param name="sentNotificationDataRepository">Sent notification data repository.</param>
 public NotificationDelivery(
     IConfiguration configuration,
     NotificationDataRepository notificationDataRepository,
     MetadataProvider metadataProvider,
     SendingNotificationCreator sendingNotificationCreator,
     SentNotificationDataRepository sentNotificationDataRepository)
 {
     this.configuration = configuration;
     this.notificationDataRepository     = notificationDataRepository;
     this.metadataProvider               = metadataProvider;
     this.sendingNotificationCreator     = sendingNotificationCreator;
     this.sentNotificationDataRepository = sentNotificationDataRepository;
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataProvider"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="userDataRepository">User Data repository service.</param>
 /// <param name="teamDataRepository">Team Data repository service.</param>
 /// <param name="notificationDataRepository">Notification data repository service.</param>
 /// <param name="adGroupsDataRepository">AD Groups data repository service.</param>
 public MetadataProvider(
     IConfiguration configuration,
     UserDataRepository userDataRepository,
     TeamDataRepository teamDataRepository,
     NotificationDataRepository notificationDataRepository,
     ADGroupsDataRepository adGroupsDataRepository)
 {
     this.configuration              = configuration;
     this.userDataRepository         = userDataRepository;
     this.teamDataRepository         = teamDataRepository;
     this.notificationDataRepository = notificationDataRepository;
     this.adGroupsDataRepository     = adGroupsDataRepository;
 }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DraftNotificationsController"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository instance.</param>
 /// <param name="teamDataRepository">Team data repository instance.</param>
 /// <param name="draftNotificationPreviewService">Draft notification preview service.</param>
 /// <param name="localizer">Localization service.</param>
 /// <param name="groupsService">group service.</param>
 public DraftNotificationsController(
     NotificationDataRepository notificationDataRepository,
     TeamDataRepository teamDataRepository,
     DraftNotificationPreviewService draftNotificationPreviewService,
     IStringLocalizer <Strings> localizer,
     IGroupsService groupsService)
 {
     this.notificationDataRepository      = notificationDataRepository;
     this.teamDataRepository              = teamDataRepository;
     this.draftNotificationPreviewService = draftNotificationPreviewService;
     this.localizer     = localizer;
     this.groupsService = groupsService;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncAllUsersActivity"/> class.
 /// </summary>
 /// <param name="userDataRepository">User Data repository.</param>
 /// <param name="sentNotificationDataRepository">Sent notification data repository.</param>
 /// <param name="usersService">Users service.</param>
 /// <param name="notificationDataRepository">Notification data entity repository.</param>
 /// <param name="localizer">Localization service.</param>
 public SyncAllUsersActivity(
     UserDataRepository userDataRepository,
     SentNotificationDataRepository sentNotificationDataRepository,
     IUsersService usersService,
     NotificationDataRepository notificationDataRepository,
     IStringLocalizer <Strings> localizer)
 {
     this.userDataRepository             = userDataRepository ?? throw new ArgumentNullException(nameof(userDataRepository));
     this.sentNotificationDataRepository = sentNotificationDataRepository ?? throw new ArgumentNullException(nameof(sentNotificationDataRepository));
     this.usersService = usersService ?? throw new ArgumentNullException(nameof(usersService));
     this.notificationDataRepository = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository));
     this.localizer = localizer ?? throw new ArgumentNullException(nameof(localizer));
 }
Example #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduleNotificationDelivery"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="notificationDataRepository">Notification repository service.</param>
 /// <param name="metadataProvider">Meta data Provider instance.</param>
 /// <param name="sendingNotificationCreator">SendingNotification creator.</param>
 /// <param name="scheduleNotificationDataRepository">Schedule Notification data repository.</param>
 /// <param name="teamDataRepository">TeamData Repository instance.</param>
 public ScheduleNotificationDelivery(
     IConfiguration configuration,
     NotificationDataRepository notificationDataRepository,
     MetadataProvider metadataProvider,
     SendingNotificationCreator sendingNotificationCreator,
     ScheduleNotificationDataRepository scheduleNotificationDataRepository,
     TeamDataRepository teamDataRepository)
 {
     this.configuration = configuration;
     this.notificationDataRepository         = notificationDataRepository;
     this.metadataProvider                   = metadataProvider;
     this.sendingNotificationCreator         = sendingNotificationCreator;
     this.scheduleNotificationDataRepository = scheduleNotificationDataRepository;
     this.teamDataRepository                 = teamDataRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetRecipientDataListForRosterActivity"/> class.
 /// </summary>
 /// <param name="botAdapter">The bot adapter.</param>
 /// <param name="botOptions">The bot options.</param>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 /// <param name="sentNotificationDataRepository">Sent notification data repository.</param>
 /// <param name="localizer">Localization service.</param>
 /// <param name="handleWarningActivity">handle warning activity.</param>
 public GetRecipientDataListForRosterActivity(
     BotFrameworkHttpAdapter botAdapter,
     IOptions <BotOptions> botOptions,
     NotificationDataRepository notificationDataRepository,
     SentNotificationDataRepository sentNotificationDataRepository,
     IStringLocalizer <Strings> localizer,
     HandleWarningActivity handleWarningActivity)
 {
     this.botAdapter                     = botAdapter;
     this.microsoftAppId                 = botOptions.Value.MicrosoftAppId;
     this.notificationDataRepository     = notificationDataRepository;
     this.sentNotificationDataRepository = sentNotificationDataRepository;
     this.localizer             = localizer;
     this.handleWarningActivity = handleWarningActivity;
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncTeamMembersActivity"/> class.
 /// </summary>
 /// <param name="teamDataRepository">Team Data repository.</param>
 /// <param name="memberService">Teams member service.</param>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 /// <param name="sentNotificationDataRepository">Sent notification data repository.</param>
 /// <param name="localizer">Localization service.</param>
 /// <param name="userDataRepository">User Data repository.</param>
 public SyncTeamMembersActivity(
     TeamDataRepository teamDataRepository,
     ITeamMembersService memberService,
     NotificationDataRepository notificationDataRepository,
     SentNotificationDataRepository sentNotificationDataRepository,
     IStringLocalizer <Strings> localizer,
     UserDataRepository userDataRepository)
 {
     this.teamDataRepository             = teamDataRepository ?? throw new ArgumentNullException(nameof(teamDataRepository));
     this.memberService                  = memberService ?? throw new ArgumentNullException(nameof(memberService));
     this.notificationDataRepository     = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository));
     this.sentNotificationDataRepository = sentNotificationDataRepository ?? throw new ArgumentNullException(nameof(sentNotificationDataRepository));
     this.localizer          = localizer ?? throw new ArgumentNullException(nameof(localizer));
     this.userDataRepository = userDataRepository ?? throw new ArgumentNullException(nameof(userDataRepository));
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompanyCommunicatorDataFunction"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">The notification data repository.</param>
 /// <param name="aggregateSentNotificationDataService">The service to aggregate the Sent
 /// Notification Data results.</param>
 /// <param name="updateNotificationDataService">The service to update the notification totals.</param>
 /// <param name="dataQueue">The data queue.</param>
 /// <param name="dataQueueMessageOptions">The data queue message options.</param>
 public CompanyCommunicatorDataFunction(
     NotificationDataRepository notificationDataRepository,
     AggregateSentNotificationDataService aggregateSentNotificationDataService,
     UpdateNotificationDataService updateNotificationDataService,
     DataQueue dataQueue,
     IOptions <DataQueueMessageOptions> dataQueueMessageOptions)
 {
     this.notificationDataRepository           = notificationDataRepository;
     this.aggregateSentNotificationDataService = aggregateSentNotificationDataService;
     this.updateNotificationDataService        = updateNotificationDataService;
     this.dataQueue = dataQueue;
     this.firstTenMinutesRequeueMessageDelayInSeconds =
         dataQueueMessageOptions.Value.FirstTenMinutesRequeueMessageDelayInSeconds;
     this.requeueMessageDelayInSeconds =
         dataQueueMessageOptions.Value.RequeueMessageDelayInSeconds;
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduleNotificationDataRepository"/> class.
 /// </summary>
 /// <param name="configuration">Represents the application configuration.</param>
 /// <param name="notificationDataRepository">Notification DataRepository instance.</param>
 /// <param name="scheduleNotificationDelivery">Notification Delivery instance.</param>
 /// <param name="metadataProvider">Meta data Provider instance.</param>
 /// <param name="sendingNotificationCreator">SendingNotification Creator instance.</param>
 /// <param name="isFromAzureFunction">Flag to show if created from Azure Function.</param>
 public ScheduleNotificationDataRepository(
     IConfiguration configuration,
     NotificationDataRepository notificationDataRepository,
     MetadataProvider metadataProvider = null,
     SendingNotificationCreator sendingNotificationCreator     = null,
     ScheduleNotificationDelivery scheduleNotificationDelivery = null,
     bool isFromAzureFunction = false)
     : base(
         configuration,
         PartitionKeyNames.ScheduleNotificationDataTable.TableName,
         PartitionKeyNames.ScheduleNotificationDataTable.ScheduleNotificationsPartition,
         isFromAzureFunction)
 {
     this.notificationDataRepository   = notificationDataRepository;
     this.metadataProvider             = metadataProvider;
     this.sendingNotificationCreator   = sendingNotificationCreator;
     this.scheduleNotificationDelivery = scheduleNotificationDelivery;
 }
Example #22
0
        /// <summary>
        /// Create a new draft notification.
        /// </summary>
        /// <param name="notificationRepository">The notification repository.</param>
        /// <param name="notification">Draft Notification model class instance passed in from Web API.</param>
        /// <param name="userName">Name of the user who is running the application.</param>
        /// <returns>The newly created notification's id.</returns>
        public static async Task <string> CreateDraftNotificationAsync(
            this NotificationDataRepository notificationRepository,
            DraftNotification notification,
            string userName)
        {
            var newId = notificationRepository.TableRowKeyGenerator.CreateNewKeyOrderingOldestToMostRecent();

            var notificationEntity = new NotificationDataEntity
            {
                PartitionKey    = PartitionKeyNames.NotificationDataTable.DraftNotificationsPartition,
                RowKey          = newId,
                Id              = newId,
                Title           = notification.Title,
                ImageLink       = notification.ImageLink,
                Summary         = notification.Summary,
                Author          = notification.Author,
                ButtonTitle     = notification.ButtonTitle,
                ButtonLink      = notification.ButtonLink,
                ButtonTitle2    = notification.ButtonTitle2,
                ButtonLink2     = notification.ButtonLink2,
                CreatedBy       = userName,
                CreatedDate     = DateTime.UtcNow,
                IsDraft         = true,
                Teams           = notification.Teams,
                Rosters         = notification.Rosters,
                ADGroups        = notification.ADGroups,
                AllUsers        = notification.AllUsers,
                IsScheduled     = notification.IsScheduled,
                ScheduleDate    = notification.ScheduleDate,
                IsRecurrence    = notification.IsRecurrence,
                Repeats         = notification.Repeats,
                RepeatFor       = Convert.ToInt32(notification.RepeatFor),
                RepeatFrequency = notification.RepeatFrequency,
                WeekSelection   = notification.WeekSelection,
                RepeatStartDate = notification.RepeatStartDate,
                RepeatEndDate   = notification.RepeatEndDate,
            };

            await notificationRepository.CreateOrUpdateAsync(notificationEntity);

            return(newId);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SentNotificationsController"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository service that deals with the table storage in azure.</param>
 /// <param name="sentNotificationDataRepository">Sent notification data repository.</param>
 /// <param name="teamDataRepository">Team data repository instance.</param>
 /// <param name="prepareToSendQueue">The service bus queue for preparing to send notifications.</param>
 /// <param name="dataQueue">The service bus queue for the data queue.</param>
 /// <param name="dataQueueMessageOptions">The options for the data queue messages.</param>
 /// <param name="sendBatchesDataRepository">The send batches data repository.</param>
 /// <param name="groupsService">The groups service.</param>
 /// <param name="exportDataRepository">The Export data repository instance.</param>
 public SentNotificationsController(
     NotificationDataRepository notificationDataRepository,
     SentNotificationDataRepository sentNotificationDataRepository,
     TeamDataRepository teamDataRepository,
     PrepareToSendQueue prepareToSendQueue,
     DataQueue dataQueue,
     IOptions <DataQueueMessageOptions> dataQueueMessageOptions,
     SendBatchesDataRepository sendBatchesDataRepository,
     IGroupsService groupsService,
     ExportDataRepository exportDataRepository)
 {
     this.notificationDataRepository     = notificationDataRepository;
     this.sentNotificationDataRepository = sentNotificationDataRepository;
     this.teamDataRepository             = teamDataRepository;
     this.prepareToSendQueue             = prepareToSendQueue;
     this.dataQueue = dataQueue;
     this.forceCompleteMessageDelayInSeconds = dataQueueMessageOptions.Value.ForceCompleteMessageDelayInSeconds;
     this.sendBatchesDataRepository          = sendBatchesDataRepository;
     this.groupsService        = groupsService;
     this.exportDataRepository = exportDataRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TeamsConversationActivity"/> class.
 /// </summary>
 /// <param name="conversationService">The create user conversation service.</param>
 /// <param name="sentNotificationDataRepository">The sent notification data repository.</param>
 /// <param name="userDataRepository">The user data repository.</param>
 /// <param name="notificationDataRepository">Notification data entity repository.</param>
 /// <param name="appManagerService">App manager service.</param>
 /// <param name="chatsService">Chats service.</param>
 /// <param name="appSettingsService">App Settings service.</param>
 /// <param name="options">Teams conversation options.</param>
 /// <param name="localizer">Localization service.</param>
 public TeamsConversationActivity(
     IConversationService conversationService,
     SentNotificationDataRepository sentNotificationDataRepository,
     UserDataRepository userDataRepository,
     NotificationDataRepository notificationDataRepository,
     IAppManagerService appManagerService,
     IChatsService chatsService,
     IAppSettingsService appSettingsService,
     IOptions <TeamsConversationOptions> options,
     IStringLocalizer <Strings> localizer)
 {
     this.conversationService            = conversationService ?? throw new ArgumentNullException(nameof(conversationService));
     this.sentNotificationDataRepository = sentNotificationDataRepository ?? throw new ArgumentNullException(nameof(sentNotificationDataRepository));
     this.userDataRepository             = userDataRepository ?? throw new ArgumentNullException(nameof(userDataRepository));
     this.notificationDataRepository     = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository));
     this.appManagerService  = appManagerService ?? throw new ArgumentNullException(nameof(appManagerService));
     this.chatsService       = chatsService ?? throw new ArgumentNullException(nameof(chatsService));
     this.appSettingsService = appSettingsService ?? throw new ArgumentNullException(nameof(appSettingsService));
     this.options            = options?.Value ?? throw new ArgumentNullException(nameof(options));
     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 Run(
            [ServiceBusTrigger("company-communicator-data", Connection = "ServiceBusConnection")]
            string myQueueItem,
            int deliveryCount,
            DateTime enqueuedTimeUtc,
            string messageId,
            ILogger log,
            ExecutionContext context)
        {
            CompanyCommunicatorDataFunction.configuration = CompanyCommunicatorDataFunction.configuration ??
                                                            new ConfigurationBuilder()
                                                            .AddEnvironmentVariables()
                                                            .Build();

            // Simply initialize the variable for certain build environments and versions
            var maxMinutesOfRetryingDataFunction = 0;

            // If parsing fails, out variable is set to 0, so need to set the default
            if (!int.TryParse(CompanyCommunicatorDataFunction.configuration["MaxMinutesOfRetryingDataFunction"], out maxMinutesOfRetryingDataFunction))
            {
                maxMinutesOfRetryingDataFunction = 1440;
            }

            var messageContent = JsonConvert.DeserializeObject <ServiceBusDataQueueMessageContent>(myQueueItem);

            CompanyCommunicatorDataFunction.sentNotificationDataRepository = CompanyCommunicatorDataFunction.sentNotificationDataRepository
                                                                             ?? new SentNotificationDataRepository(CompanyCommunicatorDataFunction.configuration, isFromAzureFunction: true);

            CompanyCommunicatorDataFunction.notificationDataRepository = CompanyCommunicatorDataFunction.notificationDataRepository
                                                                         ?? this.CreateNotificationRepository(CompanyCommunicatorDataFunction.configuration);

            CompanyCommunicatorDataFunction.sendingNotificationDataRepository = CompanyCommunicatorDataFunction.sendingNotificationDataRepository
                                                                                ?? new SendingNotificationDataRepository(CompanyCommunicatorDataFunction.configuration, isFromAzureFunction: true);

            var sentNotificationDataEntities = await CompanyCommunicatorDataFunction.sentNotificationDataRepository.GetAllAsync(
                messageContent.NotificationId);

            if (sentNotificationDataEntities == null)
            {
                if (DateTime.UtcNow >= messageContent.InitialSendDate + TimeSpan.FromMinutes(maxMinutesOfRetryingDataFunction))
                {
                    await this.SetEmptyNotificationDataEntity(messageContent.NotificationId);

                    return;
                }

                await this.SendTriggerToDataFunction(CompanyCommunicatorDataFunction.configuration, messageContent);

                return;
            }

            var succeededCount = 0;
            var failedCount    = 0;
            var throttledCount = 0;
            var unknownCount   = 0;

            DateTime lastSentDateTime = DateTime.MinValue;

            foreach (var sentNotificationDataEntity in sentNotificationDataEntities)
            {
                if (sentNotificationDataEntity.StatusCode == (int)HttpStatusCode.Created)
                {
                    succeededCount++;
                }
                else if (sentNotificationDataEntity.StatusCode == (int)HttpStatusCode.TooManyRequests)
                {
                    throttledCount++;
                }
                else if (sentNotificationDataEntity.StatusCode == 0)
                {
                    unknownCount++;
                }
                else
                {
                    failedCount++;
                }

                if (sentNotificationDataEntity.SentDate != null &&
                    sentNotificationDataEntity.SentDate > lastSentDateTime)
                {
                    lastSentDateTime = sentNotificationDataEntity.SentDate;
                }
            }

            var notificationDataEntityUpdate = new UpdateNotificationDataEntity
            {
                PartitionKey = PartitionKeyNames.NotificationDataTable.SentNotificationsPartition,
                RowKey       = messageContent.NotificationId,
                Succeeded    = succeededCount,
                Failed       = failedCount,
                Throttled    = throttledCount,
                Unknown      = unknownCount,
            };

            // Purposefully exclude the unknown count because those messages may be sent later
            var currentMessageCount = succeededCount
                                      + failedCount
                                      + throttledCount;

            if (currentMessageCount == messageContent.TotalMessageCount ||
                DateTime.UtcNow >= messageContent.InitialSendDate + TimeSpan.FromMinutes(maxMinutesOfRetryingDataFunction))
            {
                notificationDataEntityUpdate.IsCompleted = true;
                notificationDataEntityUpdate.SentDate    = lastSentDateTime != DateTime.MinValue
                    ? lastSentDateTime
                    : DateTime.UtcNow;
            }
            else
            {
                await this.SendTriggerToDataFunction(CompanyCommunicatorDataFunction.configuration, messageContent);
            }

            var operation = TableOperation.InsertOrMerge(notificationDataEntityUpdate);

            await CompanyCommunicatorDataFunction.notificationDataRepository.Table.ExecuteAsync(operation);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PrepareToSendFunction"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 public PrepareToSendFunction(
     NotificationDataRepository notificationDataRepository)
 {
     this.notificationDataRepository = notificationDataRepository ?? throw new ArgumentNullException(nameof(notificationDataRepository));
 }
Example #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HandleFailureActivity"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 public HandleFailureActivity(NotificationDataRepository notificationDataRepository)
 {
     this.notificationDataRepository = notificationDataRepository;
 }
        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")));
        }
Example #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HandleWarningActivity"/> class.
 /// </summary>
 /// <param name="notificationDataRepository">Notification data repository.</param>
 public HandleWarningActivity(NotificationDataRepository notificationDataRepository)
 {
     this.notificationDataRepository = notificationDataRepository;
 }