Skip to content

Commit

Permalink
Checking in so I can work on the VM
Browse files Browse the repository at this point in the history
  • Loading branch information
dgmjr committed Jan 26, 2024
1 parent fc6d559 commit 7dcb415
Show file tree
Hide file tree
Showing 230 changed files with 8,568 additions and 488 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/AspNetCore.Hashids"]
path = lib/AspNetCore.Hashids
url = https://github.com/dgmjr/AspNetCore.Hashids.git
[submodule "src/Http/CorrelationId"]
path = src/Http/CorrelationId
url = https://github.com/dgmjr-io/CorrelationId.git
25 changes: 25 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageReference Include="Dgmjr.Enumerations.Abstractions" />
<PackageReference Include="Dgmjr.Abstractions" />
<PackageReference Include="Dgmjr.Primitives" />
<PackageReference Include="Dgmjr.Enumerations.CodeGenerator.Runtime" />
<PackageReference Include="Dgmjr.Enumerations.CodeGenerator" IncludeAssets="Analyzers;Build" ExcludeAssets="Native;BuildTransitive;BuildMultitargeting;ContentFiles;Compile;Runtime" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}"
ProjectSection(SolutionItems) = preProject
..\..\..\..\Directory.Build.props = ..\..\..\..\Directory.Build.props
..\..\Directory.Build.props = ..\..\Directory.Build.props
..\..\..\..\Directory.Build.targets = ..\..\..\..\Directory.Build.targets
..\..\..\..\global.json = ..\..\..\..\global.json
..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\Packages\Versions.Local.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.AspNetCore.Communication.Abstractions", "Dgmjr.AspNetCore.Communication.Abstractions.csproj", "{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.AspNetCore.Communication.Abstractions", "Dgmjr.AspNetCore.Communication.Abstractions.csproj", "{3B567DE2-8008-43B6-B04C-20586C7F30CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -20,18 +20,18 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Local|Any CPU.ActiveCfg = Local|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Local|Any CPU.Build.0 = Local|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Testing|Any CPU.Build.0 = Testing|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Staging|Any CPU.Build.0 = Staging|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Production|Any CPU.ActiveCfg = Local|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Production|Any CPU.Build.0 = Local|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BE89DB2-FCC3-4CC5-9713-6FD2CB8B2E4B}.Release|Any CPU.Build.0 = Release|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Local|Any CPU.ActiveCfg = Local|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Local|Any CPU.Build.0 = Local|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Testing|Any CPU.Build.0 = Testing|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Staging|Any CPU.Build.0 = Staging|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Production|Any CPU.ActiveCfg = Local|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Production|Any CPU.Build.0 = Local|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B567DE2-8008-43B6-B04C-20586C7F30CF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
35 changes: 35 additions & 0 deletions src/Communication.Abstractions/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
date: 2023-07-13T05:44:46:00-05:00Z
description: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, yadda, yadda, yadda...
keywords:
- IP
- copyright
- license
- mit
permissions:
- commercial-use
- modifications
- distribution
- private-use
conditions:
- include-copyright
limitations:
- liability
- warranty
lastmod: 2024-01-0T00:39:00.0000+05:00Z
license: MIT
slug: mit-license
title: MIT License
type: license
---

# MIT License

## Copyright © 2022-2024 [David G. Moore, Jr.](mailto:[email protected] "Send Dr. Moore") ([@dgmjr](https://github.com/dgmjr "Contact Dr. Moore on GitHub")), All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Binary file added src/Communication.Abstractions/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
124 changes: 124 additions & 0 deletions src/Communication/AzureCommunicationServicesAutoConfigurator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* AutoConfigurator.cs
*
* Created: 2024-17-19T08:17:28-05:00
* Modified: 2024-17-19T08:17:28-05:00
*
* Author: David G. Moore, Jr. <[email protected]>
*
* Copyright © 2024 David G. Moore, Jr., All Rights Reserved
* License: MIT (https://opensource.org/licenses/MIT)
*/

namespace Microsoft.Extensions.DependencyInjection;

using Dgmjr.AspNetCore.Communication;
using Dgmjr.AspNetCore.Communication.Email;
using Dgmjr.AspNetCore.Communication.Sms;

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

public class AzureCommunicationServicesAutoConfigurator(
ILogger<AzureCommunicationServicesAutoConfigurator> logger
) : IConfigureIHostApplicationBuilder, IConfigureIApplicationBuilder, ILog
{
public ConfigurationOrder Order => ConfigurationOrder.AnyTime;

public ILogger Logger => logger;

public void Configure(IApplicationBuilder builder)
{
var emailSenderOptions = builder.ApplicationServices.GetService<
IOptions<EmailSenderOptions>
>();
if (emailSenderOptions is null)
{
Logger.LogWarning(
"Azure Email Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
var smsSenderOptions = builder.ApplicationServices.GetService<IOptions<SmsSenderOptions>>();
if (smsSenderOptions is null)
{
Logger.LogWarning(
"Azure SMS Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
}

public void Configure(IHostApplicationBuilder builder)
{
var optionsSection = builder.Configuration.GetSection(
AzureCommunicationServicesOptionsBase.ConfigurationSectionName
);
if (!optionsSection.Exists())
{
Logger.LogWarning(
"Azure Communication Services options are not configured. Please configure them in your appsettings.json file."
);
}
else
{
builder.Services.Configure<AzureCommunicationServicesOptions>(optionsSection);

var emailCommunicationSection = builder.Configuration.GetSection(
EmailSenderOptions.ConfigurationSectionName
);
if (!emailCommunicationSection.Exists())
{
Logger.LogWarning(
"Azure Email Communication Services options are not configured. Please configure them in your appsettings.json file."
);
builder.Services.AddSingleton<IEmailSender>(
y =>
throw new KeyNotFoundException(
$"The {nameof(EmailSenderOptions)} configuration section was not found in the appsettings.json file."
)
);
}
else
{
builder.Services.Configure<EmailSenderOptions>(emailCommunicationSection);
builder.Services.AddSingleton<IEmailSender>(
y =>
new EmailSender(
y.GetService<IOptions<EmailSenderOptions>>()
?? throw new KeyNotFoundException(
$"The {nameof(EmailSenderOptions)} configuration section was not found in the appsettings.json file."
)
)
);
}
var smsCommunicationSection = builder.Configuration.GetSection(
SmsSenderOptions.ConfigurationSectionName
);
if (!smsCommunicationSection.Exists())
{
Logger.LogWarning(
"Azure SMS Communication Services options are not configured. Please configure them in your appsettings.json file."
);
builder.Services.AddSingleton<ISmsSender>(
y =>
throw new KeyNotFoundException(
$"The {nameof(SmsSenderOptions)} configuration section was not found in the appsettings.json file."
)
);
}
else
{
builder.Services.Configure<SmsSenderOptions>(smsCommunicationSection);
builder.Services.AddSingleton<ISmsSender>(
y =>
new SmsSender(
y.GetService<IOptions<SmsSenderOptions>>()
?? throw new KeyNotFoundException(
$"The {nameof(SmsSenderOptions)} configuration section was not found in the appsettings.json file."
)
)
);
}
}
}
}
24 changes: 21 additions & 3 deletions src/Communication/AzureCommunicationServicesOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,32 @@ namespace Dgmjr.AspNetCore.Communication;

using System;

using Dgmjr.AspNetCore.Communication.Email;
using Dgmjr.AspNetCore.Communication.Sms;

public class AzureCommunicationServicesOptions
{
public EmailSenderOptions Email { get; set; } = new EmailSenderOptions();
public SmsSenderOptions Sms { get; set; } = new SmsSenderOptions();
}

[RegexDto(_RegexString)]
public partial record class AzureCommunicationServicesOptionsBase
{
public const string EmptyValue = "endpoint=https://empty.example;accessKey=NOTHING";
public const string ConfigurationSectionName = "CommunicationServices";

#if NET8_0_OR_GREATER
[StringSyntax(SS.Regex)]
[@StringSyntax(SS.Regex)]
#endif
public const string _RegexString =
"^endpoint=(?<Endpoint:uri>https://.*);accessKey=(?<AccessKey:string>.*)$";
"^endpoint=(?<EndpointString:string>https://.*);accessKey=(?<AccessKey:string>.*)$";

public uri Endpoint
{
get => EndpointString;
init => EndpointString = value;
}

public AzureCommunicationServicesOptionsBase(uri endpoint, string accessKey)
{
Expand Down Expand Up @@ -47,7 +65,7 @@ protected AzureCommunicationServicesOptions(uri endpoint, string accessKey)
: base(endpoint, accessKey) { }

protected AzureCommunicationServicesOptions()
: this(string.Empty) { }
: this(EmptyValue) { }

public abstract TAddressType DefaultFrom { get; set; }

Expand Down
11 changes: 9 additions & 2 deletions src/Communication/Dgmjr.AspNetCore.Communication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
<Description>This package contains the communication classes for the project. It's used for sending SMS and email messages.</Description>
<SlnGenSolutionFolder>comms</SlnGenSolutionFolder>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<TargetFrameworks>$(TargetedDotNetFrameworks)</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Communication.Email" />
<PackageReference Include="Azure.Communication.Sms" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Dgmjr.Primitives" />
<PackageReference Include="Dgmjr.Configuration.Extensions" />
<PackageReference Include="Dgmjr.Enumerations.Abstractions" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Dgmjr.Enumerations.CodeGenerator" IncludeAssets="Analyzers;Build" ExcludeAssets="Native;BuildTransitive;BuildMultitargeting;ContentFiles;Compile;Runtime" PrivateAssets="All" />
<PackageReference Include="Dgmjr.RegexDtoGenerator" IncludeAssets="Analyzers;Build" ExcludeAssets="Native;BuildTransitive;BuildMultitargeting;ContentFiles;Compile;Runtime" PrivateAssets="All" />
<ProjectReference Include="../Communication.Abstractions/Dgmjr.AspNetCore.Communication.Abstractions.csproj" />
<PackageReference Include="System.Private.CoreLib.Polyfills" IncludeAssets="ContentFiles;Build;BuildTransitive;BuildMultitargeting" ExcludeAssets="Analyzers;Runtime;Native" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Using Include="Dgmjr.Enumerations" />
</ItemGroup>
</Project>
Loading

0 comments on commit 7dcb415

Please sign in to comment.