Beispiel #1
0
        public async Task ProcessAsync()
        {
            Require.NonNullNonEmpty(SonarUrl, "SonarUrl");
            Require.NonNullNonEmpty(Token, "Token");
            Require.NonNullNonEmpty(SmtpServer, "SmtpServer");
            Require.NonNullNonEmpty(SmtpSenderAddress, "SmtpServerAddress");
            if (SmtpUsername != null && SmtpPassword != null)
            {
                Require.NonNullNonEmpty(SmtpUsername, "SmtpUsername");
                Require.NonNullNonEmpty(SmtpPassword, "SmtpPassword");
            }

            Logger.Info($"Sonar URL: {SonarUrl}");
            Logger.Info($"Max Issue Date: {MaxCreationDate}");
            Logger.Info($"Project filter: {ProjectFilter.ToPrettyString()}, ignored projects: {IgnoredProjects.ToPrettyString()}");
            Logger.Info($"User filter: {UserFilter.ToPrettyString()}, ignored users: {IgnoredUsers.ToPrettyString()}");
            Logger.Info($"SMTP server: {SmtpServer} ({(SmtpSslEnabled ? "SSL enabled" : "SSL disabled")})");
            Logger.Info($"SMTP sender address: {SmtpSenderAddress}");
            Logger.Info($"SMTP authentication: {(SmtpUsername != null && SmtpPassword != null ? $"Yes (username: {SmtpUsername})" : "None")}");
            Logger.Info($"Recipient filter: {RecipientFilter.ToPrettyString()}, ignored recipients: {IgnoredRecipients.ToPrettyString()}");
            Logger.Info($"Summary recipients: {SummaryRecipients.ToPrettyString()}");

            SummaryViewModel summary = await GenerateSummary().OnAnyThread();

            Logger.Info($"Processing complete, {summary.NumberOfOverdueIssues} issues overdue, {summary.NumberOfUnassignedIssues} issues unassigned, {summary.Users.Count} users to notify, {summary.Projects.Count} projects to notify");

            RazorLightEngine razor = new RazorLightEngineBuilder()
                                     .UseEmbeddedResourcesProject(typeof(Startup)) // exception without this (or another project type)
                                     .UseMemoryCachingProvider()
                                     .Build();

            SmtpClient smtpClient = new SmtpClient(SmtpServer !);

            smtpClient.EnableSsl = SmtpSslEnabled;
            if (SmtpUsername != null && SmtpPassword != null)
            {
                smtpClient.Credentials = new NetworkCredential(SmtpUsername, SmtpPassword);
            }

            await NotifyUser(summary, razor, smtpClient).OnAnyThread();
            await NotifySummary(summary, razor, smtpClient).OnAnyThread();
        }