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) ) ); }
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); }
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); }