Skip to content

Commit

Permalink
Merge pull request #284 from GregFinzer/feature/EmailQueueLogic
Browse files Browse the repository at this point in the history
Feature/email queue logic
  • Loading branch information
GregFinzer authored Sep 16, 2023
2 parents adb51f2 + a3760eb commit f49f896
Show file tree
Hide file tree
Showing 30 changed files with 3,012 additions and 340 deletions.
3 changes: 1 addition & 2 deletions BedBrigade.Client/BedBrigade.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

<ItemGroup>
<None Include="compilerconfig.json" />
<None Include="Pages\Administration\AdminTasks\Email.razor" />
<None Include="Pages\Administration\Admin\Email.razor" />
<None Include="wwwroot\css\open-iconic\FONT-LICENSE" />
<None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.svg" />
<None Include="wwwroot\css\open-iconic\ICON-LICENSE" />
Expand Down Expand Up @@ -96,7 +96,6 @@
<ItemGroup>
<ProjectReference Include="..\BedBrigade.Common\BedBrigade.Common.csproj" />
<ProjectReference Include="..\BedBrigade.Data\BedBrigade.Data.csproj" />
<ProjectReference Include="..\BedBrigade.MessageService\BedBrigade.MessageService.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions BedBrigade.Client/Components/DonationGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using BedBrigade.Data.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Asn1.X509;
//using Org.BouncyCastle.Asn1.Cms;
//using Org.BouncyCastle.Asn1.X509;
using Syncfusion.Blazor.DropDowns;
using Syncfusion.Blazor.Grids;
using Syncfusion.Blazor.Notifications;
Expand All @@ -23,7 +23,7 @@ public partial class DonationGrid : ComponentBase
[Inject] private IUserDataService? _svcUser { get; set; }
[Inject] private ILocationDataService? _svcLocation { get; set; }
[Inject] private AuthenticationStateProvider? _authState { get; set; }
[Inject] private IMessageService? _messageService { get; set; }
[Inject] private IEmailQueueLogic? _emailQueueLogic { get; set; }

[Parameter] public string? Id { get; set; }

Expand Down Expand Up @@ -247,10 +247,10 @@ protected async Task SendTax()
{
string body = $"Dear {recipient.Name},\n\n" +
$"Thank you for your generous donation of {recipient.Amount.ToString("C")} to the Bed Brigade";
await _messageService.SendEmailAsync(recipient.Email,
"national@bedbrigade.org",
"Bed Brigade Charitable Donation",
body);
//await _messageService.SendEmailAsync(recipient.Email,
// "national@bedbrigade.org",
// "Bed Brigade Charitable Donation",
// body);
}
await CloseTaxDialog();
}
Expand Down
6 changes: 3 additions & 3 deletions BedBrigade.Client/Components/Error.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@using BedBrigade.Common

@inject ILogger<Error> Logger
@inject IMessageService _svcMessageService

<CascadingValue Value="this">
@ChildContent
Expand All @@ -19,7 +18,8 @@
Logger.LogError("Error:ProcessError - Type: {0} Message: {1}", ex.GetType(), ex.Message);

//Email the error
string body = $"Error: processError - Type {ex.GetType()}, {ex.Message}";
await _svcMessageService.SendEmailAsync("National.Admin@bedbrigade.org","Error.Notice@bedbrigade.org","**** Error ****", body);
//TODO: Implement
//string body = $"Error: processError - Type {ex.GetType()}, {ex.Message}";
//await _svcMessageService.SendEmailAsync("National.Admin@bedbrigade.org","Error.Notice@bedbrigade.org","**** Error ****", body);
}
}
44 changes: 41 additions & 3 deletions BedBrigade.Client/Pages/Administration/Admin/Email.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
@page "/administration/admin/email"
@layout BedBrigade.Client.Shared.AdminLayout
@page "/administration/admin/email"
@inject IEmailQueueLogic EmailQueueLogic;
@attribute [Authorize(Roles = RoleNames.CanSendBulkEmail)]

<h3>Send Email</h3>

<EditForm Model="@email" OnValidSubmit="@HandleSubmit">
<div class="form-group">
<label for="to">To:</label>
<InputText id="to" class="form-control" @bind-Value="email.ToAddress" />
</div>

<div class="form-group">
<label for="subject">Subject:</label>
<InputText id="subject" class="form-control" @bind-Value="email.Subject" />
</div>

<div class="form-group">
<label for="body">Body:</label>
<InputTextArea id="body" class="form-control" @bind-Value="email.Body"></InputTextArea>
</div>

<button type="submit" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-secondary" @onclick="ProcessQueue">Process Queue</button>
</EditForm>



<h3 class="w-100 text-center my-4">Email</h3>

@code {
private EmailQueue email = new EmailQueue();

private async Task HandleSubmit()
{
await EmailQueueLogic.QueueEmail(email);
// // Logic to send email. For simplicity, we'll just print to console for now.
// Console.WriteLine($"Sending email to: {email.To}, Subject: {email.Subject}, Body: {email.Body}");
}

}
private async Task ProcessQueue()
{
EmailQueueLogic.ProcessQueue(email);
}
}
6 changes: 0 additions & 6 deletions BedBrigade.Client/Pages/Administration/AdminTasks/Email.razor

This file was deleted.

10 changes: 0 additions & 10 deletions BedBrigade.Client/Services/IMessageService.cs

This file was deleted.

33 changes: 0 additions & 33 deletions BedBrigade.Client/Services/MessageService.cs

This file was deleted.

13 changes: 4 additions & 9 deletions BedBrigade.Client/StartupLogic.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using BedBrigade.Client.Components;
using BedBrigade.Client.Pages.Administration.Admin;
using BedBrigade.Client.Services;
using BedBrigade.Data.Services;
using BedBrigade.Data;
using BedBrigade.Data.Seeding;
using BedBrigade.MessageService;
using Blazored.SessionStorage;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.EntityFrameworkCore;
using Syncfusion.Blazor;
using Serilog;
using BedBrigade.MessageService.Services;
using BedBrigade.Common;
using Microsoft.AspNetCore.Mvc;

Expand Down Expand Up @@ -69,20 +68,14 @@ public static void AddServicesToTheContainer(WebApplicationBuilder builder)
options.UseApplicationServiceProvider(_svcProvider);
});

// Add Email Messageing Service config
// Email Messaging Service
EmailConfiguration emailConfig = builder.Configuration.GetSection("EmailConfiguration").Get<EmailConfiguration>();
builder.Services.AddSingleton(emailConfig);


builder.Services.AddHttpClient(); // VS 7/31/2023

ClientServices(builder);

DataServices(builder);

builder.Services.AddScoped<IMessageService, Services.MessageService>();
builder.Services.AddScoped<IEmailService, EmailService>();

builder.Services.AddScoped<ToastService, ToastService>();
builder.Services.AddSignalR(e =>
{
Expand Down Expand Up @@ -120,6 +113,8 @@ private static void DataServices(WebApplicationBuilder builder)
builder.Services.AddScoped<ITemplateDataService, TemplateDataService>();
builder.Services.AddScoped<IContactUsDataService, ContactUsDataService>();
builder.Services.AddScoped<IVolunteerEventsDataService, VolunteerEventsDataService>();
builder.Services.AddScoped<IEmailQueueDataService, EmailQueueDataService>();
builder.Services.AddScoped<IEmailQueueLogic, EmailQueueLogic>();
}

private static void ClientServices(WebApplicationBuilder builder)
Expand Down
17 changes: 15 additions & 2 deletions BedBrigade.Common/ConfigNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
{
public static class ConfigNames
{
//Email Section
public const string FromEmailAddress = "FromEmailAddress";
public const string HostName = "HostName";
public const string Port = "Port";
public const string FromEmailDisplayName = "FromEmailDisplayName";
public const string EmailBeginHour = "EmailBeginHour";
public const string EmailEndHour = "EmailEndHour";
public const string EmailBeginDayOfWeek = "EmailBeginDayOfWeek";
public const string EmailEndDayOfWeek = "EmailEndDayOfWeek";
public const string EmailMaxSendPerMinute = "EmailMaxSendPerMinute";
public const string EmailMaxSendPerHour = "EmailMaxSendPerHour";
public const string EmailMaxSendPerDay = "EmailMaxSendPerDay";
public const string EmailLockWaitMinutes = "EmailLockWaitMinutes";
public const string EmailKeepDays = "EmailKeepDays";
public const string EmailMaxPerChunk = "EmailMaxPerChunk";
public const string EmailUseFileMock = "EmailUseFileMock";

//Other
public const string TokenExpiration = "TokenExpiration";
public const string AllowedFileExtensions = "AllowedFileExtensions";
public const string AllowedVideoExtensions = "AllowedVideoExtensions";
Expand Down
10 changes: 10 additions & 0 deletions BedBrigade.Common/EmailQueueStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BedBrigade.Common
{
public enum EmailQueueStatus
{
Queued,
Locked,
Sent,
Failed
}
}
1 change: 1 addition & 0 deletions BedBrigade.Data/BedBrigade.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@


<ItemGroup>
<PackageReference Include="Azure.Communication.Email" Version="1.0.1" />
<PackageReference Include="BetterAddressParser" Version="1.17.0" />
<PackageReference Include="Blazored.SessionStorage" Version="2.3.0" />
<PackageReference Include="EntityFramework" Version="6.4.4" />
Expand Down
86 changes: 73 additions & 13 deletions BedBrigade.Data/Data/Seeding/Seed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,7 @@ private static async Task SeedConfigurations(IDbContextFactory<DataContext> cont
new()
{
ConfigurationKey = ConfigNames.FromEmailAddress,
ConfigurationValue = "webmaster@bedbrigade.org",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.HostName,
ConfigurationValue = "mail.bedbrigade.org",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.Port,
ConfigurationValue = "8889",
ConfigurationValue = "DoNotReply@89a27aba-71cb-4968-863a-b1e5203187d5.azurecomm.net",
Section = ConfigSection.Email
},
new()
Expand Down Expand Up @@ -299,6 +287,78 @@ private static async Task SeedConfigurations(IDbContextFactory<DataContext> cont
ConfigurationValue = "6LedaRIdAAAAACLvJRk3_zhzPL56te_aMIZwl7rZ",
Section = ConfigSection.System
},
new()
{
ConfigurationKey = ConfigNames.EmailBeginHour,
ConfigurationValue = "8",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailEndHour,
ConfigurationValue = "17",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailBeginDayOfWeek,
ConfigurationValue = "1",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailEndDayOfWeek,
ConfigurationValue = "5",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailMaxSendPerMinute,
ConfigurationValue = "30",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailMaxSendPerHour,
ConfigurationValue = "60",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailMaxSendPerDay,
ConfigurationValue = "1440",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailLockWaitMinutes,
ConfigurationValue = "10",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailKeepDays,
ConfigurationValue = "30",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailMaxPerChunk,
ConfigurationValue = "30",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.EmailUseFileMock,
ConfigurationValue = "true",
Section = ConfigSection.Email
},
new()
{
ConfigurationKey = ConfigNames.FromEmailDisplayName,
ConfigurationValue = "Bed Brigade NoReply",
Section = ConfigSection.Email
},
};

await context.Configurations.AddRangeAsync(configurations);
Expand Down
2 changes: 1 addition & 1 deletion BedBrigade.Data/Data/Seeding/SeedHtml/Header.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<li class="dropdown nav-item">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" onclick="DisplayToggle.Toggle('adminAdmin'); DisplayToggle.SetDisplay('manageAdmin','none');" href="javascript:void(0);">Admin</a>
<ul id="adminAdmin" class="dropdown-menu" style="display: none;">
<li class="nav-link nadmin ladmin lsched"><a class="dropdown-item mx-2" href="administration/admintasks/email">Send Email</a></li>
<li class="nav-link nadmin ladmin lsched"><a class="dropdown-item mx-2" href="administration/admin/email">Send Email</a></li>
</ul>
</li>
<li class="nadmin ladmin"><hr class="dropdown-divider"></li>
Expand Down
Loading

0 comments on commit f49f896

Please sign in to comment.