Ejemplo n.º 1
0
        private static Task SendSummaryReport(SiteStats siteStats, string instanceName, string sendGridApiKey)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"Summary Report for '{instanceName}'");
            sb.AppendLine($"Total Number of Users: {siteStats.UserCount}");
            sb.AppendLine($"Total Number of Events: {siteStats.EventCount}");
            sb.AppendLine($"Total Number of Attendees: {siteStats.AttendeeCount}");
            sb.AppendLine($"Total Number of Future Events: {siteStats.FutureEventsCount}");
            sb.AppendLine($"Total Number of Future Event Attendees: {siteStats.FutureEventAttendeesCount}");
            sb.AppendLine($"Total Number of Contact Requests: {siteStats.ContactRequestsCount}");

            var email = new Email
            {
                Subject = $"Summary Report for '{instanceName}'",
                Message = sb.ToString()
            };

            email.Addresses.Add(new EmailAddress()
            {
                Email = Constants.TrashMobEmailAddress, Name = Constants.TrashMobEmailName
            });

            var emailSender = new EmailSender()
            {
                ApiKey = sendGridApiKey
            };

            return(emailSender.SendEmailAsync(email));
        }
Ejemplo n.º 2
0
        public async Task Run([TimerTrigger("0 0 0 */1 * *")] MyInfo myTimer, FunctionContext context)
        {
            var log = context.GetLogger("HttpExample");

            log.LogInformation($"Getting Stats trigger function executed at: {DateTime.Now}");
            var connectionString = Environment.GetEnvironmentVariable("TMDBServerConnectionString");
            var sendGridApiKey   = Environment.GetEnvironmentVariable("SendGridApiKey");
            var instanceName     = Environment.GetEnvironmentVariable("InstanceName");

            var siteStats = new SiteStats();

            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();

                siteStats.UserCount = await CountUsers(log, conn).ConfigureAwait(false);

                siteStats.EventCount = await CountEvents(log, conn).ConfigureAwait(false);

                siteStats.AttendeeCount = await CountEventAttendees(log, conn).ConfigureAwait(false);

                siteStats.FutureEventsCount = await CountFutureEvents(log, conn).ConfigureAwait(false);

                siteStats.FutureEventAttendeesCount = await CountFutureEventAttendees(log, conn).ConfigureAwait(false);

                siteStats.ContactRequestsCount = await CountContactRequests(log, conn).ConfigureAwait(false);
            }

            await SendSummaryReport(siteStats, instanceName, sendGridApiKey).ConfigureAwait(false);
        }