public async Task SendEmailAsync([ActivityTrigger] EmailSenderRequest request, ILogger log)
        {
            await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"{nameof(EmailSenderFunction)} function started", RunId = request.RunId });

            await _graphUpdaterService.SendEmailAsync(request.ToEmail, request.ContentTemplate, request.AdditionalContentParams, request.RunId, request.CcEmail);

            await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"{nameof(EmailSenderFunction)} function completed", RunId = request.RunId });
        }
        public async Task <bool> ValidateGroupAsync([ActivityTrigger] GroupValidatorRequest request)
        {
            await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"{nameof(GroupValidatorFunction)} function started", RunId = request.RunId });

            bool isExistingGroup   = false;
            var  groupExistsResult = await _graphUpdaterService.GroupExistsAsync(request.GroupId, request.RunId);

            if (groupExistsResult.Outcome == OutcomeType.Successful && groupExistsResult.Result)
            {
                await _loggingRepository.LogMessageAsync(new LogMessage { RunId = request.RunId, Message = $"Group with ID {request.GroupId} exists." });

                isExistingGroup = true;
            }
            else
            {
                if (groupExistsResult.Outcome == OutcomeType.Successful)
                {
                    await _loggingRepository.LogMessageAsync(new LogMessage { RunId = request.RunId, Message = $"Group with ID {request.GroupId} doesn't exist." });

                    var syncJob = await _graphUpdaterService.GetSyncJobAsync(request.JobPartitionKey, request.JobRowKey);

                    if (syncJob != null)
                    {
                        await _graphUpdaterService.SendEmailAsync(
                            syncJob.Requestor,
                            SyncDisabledNoGroupEmailBody,
                            new[] { request.GroupId.ToString(), _emailSenderAndRecipients.SupportEmailAddresses },
                            request.RunId);
                    }
                }
                else if (groupExistsResult.FaultType == FaultType.ExceptionHandledByThisPolicy)
                {
                    await _loggingRepository.LogMessageAsync(new LogMessage { RunId = request.RunId, Message = $"Exceeded {NumberOfGraphRetries} while trying to determine if a group exists." });
                }

                if (groupExistsResult.FinalException != null)
                {
                    throw groupExistsResult.FinalException;
                }

                isExistingGroup = false;
            }

            await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"{nameof(GroupValidatorFunction)} function completed", RunId = request.RunId });

            return(isExistingGroup);
        }
Example #3
0
        private async Task SendThresholdNotificationAsync(ThresholdResult threshold, SyncJob job, Guid runId)
        {
            var currentThresholdViolations = job.ThresholdViolations + 1;
            var followUpLimit              = _thresholdConfig.NumberOfThresholdViolationsToNotify + _thresholdConfig.NumberOfThresholdViolationsFollowUps;
            var sendNotification           = currentThresholdViolations >= _thresholdConfig.NumberOfThresholdViolationsToNotify && currentThresholdViolations <= followUpLimit;
            var sendDisableJobNotification = currentThresholdViolations == _thresholdConfig.NumberOfThresholdViolationsToDisableJob;

            if (!sendNotification && !sendDisableJobNotification)
            {
                return;
            }

            var groupName = await _graphUpdaterService.GetGroupNameAsync(job.TargetOfficeGroupId);

            var emailSubject = SyncThresholdEmailSubject;

            await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"Threshold exceeded, no changes made to group {groupName} ({job.TargetOfficeGroupId}). ", RunId = runId });

            string contentTemplate;

            string[] additionalContent;
            string[] additionalSubjectContent = new[] { groupName };

            var thresholdEmail = GetThresholdEmail(groupName, threshold, job);

            contentTemplate   = thresholdEmail.ContentTemplate;
            additionalContent = thresholdEmail.AdditionalContent;

            var recipients = _emailSenderAndRecipients.SupportEmailAddresses ?? _emailSenderAndRecipients.SyncDisabledCCAddresses;

            if (!string.IsNullOrWhiteSpace(job.Requestor))
            {
                var recipientList = await GetThresholdRecipientsAsync(job.Requestor, job.TargetOfficeGroupId);

                if (recipientList.Count > 0)
                {
                    recipients = string.Join(",", recipientList);
                }
            }

            if (sendDisableJobNotification)
            {
                emailSubject      = SyncThresholdDisablingJobEmailSubject;
                contentTemplate   = SyncJobDisabledEmailBody;
                additionalContent = new[]
                {
                    groupName,
                    job.TargetOfficeGroupId.ToString(),
                    _gmmResources.LearnMoreAboutGMMUrl,
                    _emailSenderAndRecipients.SupportEmailAddresses
                };
            }

            await _graphUpdaterService.SendEmailAsync(
                recipients,
                contentTemplate,
                additionalContent,
                runId,
                ccEmail : _emailSenderAndRecipients.SupportEmailAddresses,
                emailSubject : emailSubject,
                additionalSubjectParams : additionalSubjectContent);
        }