예제 #1
0
        private void SendEmail(
            Election election, EmailDefinition definition,
            RecipientIdsGenerator recipientIdsGenerator,
            IJobCancellationToken cancellationToken
            )
        {
            if (!definition.IsEnabled)
            {
                return;
            }

            if (recipientIdsGenerator == null)
            {
                recipientIdsGenerator = DefaultGenerateRecipientIds;
            }

            string[] recipientIds = recipientIdsGenerator(election).ToArray();
            int      definitionId = definition.Id;

            cancellationToken.ThrowIfCancellationRequested();
            ScheduleJobsInTransaction(
                recipientIds,
                (userId, jobClient) => jobClient.Enqueue <StudentMailerJob>(
                    mailer => mailer.SendSingleEmail(definitionId, userId)
                    )
                );
        }
예제 #2
0
        protected void SendCommonEmail(int electionId,
                                       IJobCancellationToken cancellationToken,
                                       Func <Election, EmailDefinition> emailDefinitionFetcher,
                                       RecipientIdsGenerator recipientIdsGenerator = null
                                       )
        {
            Election        election   = GetElection(electionId);
            EmailDefinition definition = emailDefinitionFetcher(election);

            cancellationToken.ThrowIfCancellationRequested();
            SendEmail(election, definition, recipientIdsGenerator, cancellationToken);
        }
예제 #3
0
        protected void SendCouncilEmail(
            int electionId,
            IJobCancellationToken cancellationToken,
            Func <CouncilElectionData, EmailDefinition> emailFetcher,
            RecipientIdsGenerator recipientIdsGenerator = null
            )
        {
            Election        election   = GetElection(electionId);
            EmailDefinition definition = emailFetcher(GetCouncilData(
                                                          election,
                                                          "Requested to send council-specific email for election that isn't a council one"
                                                          ));

            SendEmail(election, definition, recipientIdsGenerator, cancellationToken);
        }