Skip to content

Commit

Permalink
v1.1.0-l pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Logsdon committed Oct 3, 2024
1 parent ca65173 commit e7c0722
Show file tree
Hide file tree
Showing 173 changed files with 2,213 additions and 1,195 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
Expand All @@ -9,12 +9,13 @@
<ItemGroup>
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Domain\LogMessage.cs" Link="LogMessage.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Domain\WebRequestMessage.cs" Link="WebRequestMessage.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Extensions\ApplicationBuilderExtensions.cs" Link="ApplicationBuilderExtensions.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Extensions\ServiceCollectionExtensions.cs" Link="ServiceCollectionExtensions.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Mapping\LogMessageMappingProfile.cs" Link="LogMessageMappingProfile.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Mapping\WebRequestMessageMappingProfile.cs" Link="WebRequestMessageMappingProfile.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Model\LoggingAzureDataTablesConstants.cs" Link="LoggingAzureDataTablesConstants.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Model\LoggingAzureDataTablesModule.cs" Link="LoggingAzureDataTablesModule.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Rule\LoggingAzureDataTablesModuleAddRule.cs" Link="LoggingAzureDataTablesModuleAddRule.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Rule\LoggingAzureDataTablesModuleStartRule.cs" Link="LoggingAzureDataTablesModuleStartRule.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Rule\LogMessageCreateRule.cs" Link="LogMessageCreateRule.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Rule\LogMessageQueryRule.cs" Link="LogMessageQueryRule.cs" />
<Compile Include="..\ServiceBricks.Logging.AzureDataTables\Rule\WebRequestMessageCreateRule.cs" Link="WebRequestMessageCreateRule.cs" />
Expand All @@ -25,9 +26,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ServiceBricks.Storage.AzureDataTables" Version="1.1.0-g" />
<ProjectReference Include="..\ServiceBricks.Logging.Debug\ServiceBricks.Logging.Debug.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ServiceBricks.Logging.Debug\ServiceBricks.Logging.Debug.csproj" />
<PackageReference Include="ServiceBricks.Storage.AzureDataTables" Version="1.1.0-l" />
</ItemGroup>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,16 @@ public static partial class ServiceCollectionExtensions
/// <returns></returns>
public static IServiceCollection AddServiceBricksLoggingAzureDataTables(this IServiceCollection services, IConfiguration configuration)
{
// AI: Add the module to the ModuleRegistry
ModuleRegistry.Instance.RegisterItem(typeof(LoggingAzureDataTablesModule), new LoggingAzureDataTablesModule());

// AI: Add parent module
services.AddServiceBricksLogging(configuration);

// AI: Configure all options for the module

// AI: Add storage services for the module. Each domain object should have its own storage repository
services.AddScoped<IStorageRepository<LogMessage>, LoggingStorageRepository<LogMessage>>();
services.AddScoped<IStorageRepository<WebRequestMessage>, LoggingStorageRepository<WebRequestMessage>>();

// AI: Add API services for the module. Each DTO should have two registrations, one for the generic IApiService<> and one for the named interface
services.AddScoped<IApiService<LogMessageDto>, LogMessageApiService>();
services.AddScoped<ILogMessageApiService, LogMessageApiService>();

services.AddScoped<IApiService<WebRequestMessageDto>, WebRequestMessageApiService>();
services.AddScoped<IWebRequestMessageApiService, WebRequestMessageApiService>();

// AI: Register business rules for the module
DomainCreateDateRule<LogMessage>.Register(BusinessRuleRegistry.Instance);
LogMessageCreateRule.Register(BusinessRuleRegistry.Instance);
LogMessageQueryRule.Register(BusinessRuleRegistry.Instance);
// AI: Add the module to the ModuleRegistry
ModuleRegistry.Instance.Register(LoggingAzureDataTablesModule.Instance);

DomainCreateDateRule<WebRequestMessage>.Register(BusinessRuleRegistry.Instance);
WebRequestMessageCreateRule.Register(BusinessRuleRegistry.Instance);
WebRequestMessageQueryRule.Register(BusinessRuleRegistry.Instance);
// AI: Add module business rules
LoggingAzureDataTablesModuleAddRule.Register(BusinessRuleRegistry.Instance);
LoggingAzureDataTablesModuleStartRule.Register(BusinessRuleRegistry.Instance);
ModuleSetStartedRule<LoggingAzureDataTablesModule>.Register(BusinessRuleRegistry.Instance);

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ namespace ServiceBricks.Logging.AzureDataTables
/// <summary>
/// This is the module definition for the ServiceBricks Logging Azure Data Tables module.
/// </summary>
public partial class LoggingAzureDataTablesModule : IModule
public partial class LoggingAzureDataTablesModule : ServiceBricks.Module
{
/// <summary>
/// Instance
/// </summary>
public static LoggingAzureDataTablesModule Instance = new LoggingAzureDataTablesModule();

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -21,20 +26,5 @@ public LoggingAzureDataTablesModule()
new LoggingModule()
};
}

/// <summary>
/// The list of dependent modules for the module.
/// </summary>
public List<IModule> DependentModules { get; }

/// <summary>
/// The list of assemblies that contain AutoMapper profiles for the module.
/// </summary>
public List<Assembly> AutomapperAssemblies { get; }

/// <summary>
/// The list of assemblies that contain view models for the module.
/// </summary>
public List<Assembly> ViewAssemblies { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using ServiceBricks.Storage.AzureDataTables;
using ServiceBricks.Storage.AzureDataTables;

namespace ServiceBricks.Logging.AzureDataTables
{
Expand All @@ -8,15 +7,11 @@ namespace ServiceBricks.Logging.AzureDataTables
/// </summary>
public sealed class LogMessageCreateRule : BusinessRule
{
private readonly ILogger _logger;

/// <summary>
/// Constructor.
/// </summary>
/// <param name="loggerFactory"></param>
public LogMessageCreateRule(ILoggerFactory loggerFactory)
public LogMessageCreateRule()
{
_logger = loggerFactory.CreateLogger<LogMessageCreateRule>();
Priority = PRIORITY_LOW;
}

Expand Down Expand Up @@ -51,44 +46,34 @@ public override IResponse ExecuteRule(IBusinessRuleContext context)
{
var response = new Response();

try
// AI: Make sure the context object is the correct type
if (context == null || context.Object == null)
{
// AI: Make sure the context object is the correct type
if (context.Object is DomainCreateBeforeEvent<LogMessage> e)
{
// AI: Set the Key, PartitionKey, and RowKey
var item = e.DomainObject;
item.Key = Guid.NewGuid();

// AI: Set the PartitionKey to be the year, month and day so that the data is partitioned
item.PartitionKey = item.CreateDate.ToString("yyyyMMdd");

// AI: Set the RowKey to be the reverse date and time so that the newest items are at the top when querying
var reverseDate = DateTimeOffset.MaxValue.Ticks - item.CreateDate.Ticks;
item.RowKey =
reverseDate.ToString("d19") +
StorageAzureDataTablesConstants.KEY_DELIMITER +
item.Key.ToString();
}
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.PARAMETER_MISSING, "context"));
return response;
}
catch (Exception ex)
var e = context.Object as DomainCreateBeforeEvent<LogMessage>;
if (e == null || e.DomainObject == null)
{
_logger.LogError(ex, ex.Message);
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.ERROR_BUSINESS_RULE));
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.PARAMETER_MISSING, "context"));
return response;
}

return response;
}
// AI: Set the Key, PartitionKey, and RowKey
var item = e.DomainObject;
item.Key = Guid.NewGuid();

/// <summary>
/// Execute the business rule.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task<IResponse> ExecuteRuleAsync(IBusinessRuleContext context)
{
// AI: There is no async work, so just call the sync method
return Task.FromResult<IResponse>(ExecuteRule(context));
// AI: Set the PartitionKey to be the year, month and day so that the data is partitioned
item.PartitionKey = item.CreateDate.ToString("yyyyMMdd");

// AI: Set the RowKey to be the reverse date and time so that the newest items are at the top when querying
var reverseDate = DateTimeOffset.MaxValue.Ticks - item.CreateDate.Ticks;
item.RowKey =
reverseDate.ToString("d19") +
StorageAzureDataTablesConstants.KEY_DELIMITER +
item.Key.ToString();

return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using ServiceBricks.Storage.AzureDataTables;
using ServiceBricks.Storage.AzureDataTables;

namespace ServiceBricks.Logging.AzureDataTables
{
Expand All @@ -8,15 +7,11 @@ namespace ServiceBricks.Logging.AzureDataTables
/// </summary>
public sealed class LogMessageQueryRule : BusinessRule
{
private readonly ILogger _logger;

/// <summary>
/// Constructor.
/// </summary>
/// <param name="loggerFactory"></param>
public LogMessageQueryRule(ILoggerFactory loggerFactory)
public LogMessageQueryRule()
{
_logger = loggerFactory.CreateLogger<LogMessageQueryRule>();
Priority = PRIORITY_NORMAL;
}

Expand Down Expand Up @@ -51,66 +46,57 @@ public override IResponse ExecuteRule(IBusinessRuleContext context)
{
var response = new Response();

try
// AI: Make sure the context object is the correct type
if (context == null || context.Object == null)
{
// AI: Make sure the context object is the correct type
if (context.Object is DomainQueryBeforeEvent<LogMessage> ei)
{
var item = ei.DomainObject;
if (ei.ServiceQueryRequest == null || ei.ServiceQueryRequest.Filters == null)
return response;
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.PARAMETER_MISSING, "context"));
return response;
}
var ei = context.Object as DomainQueryBeforeEvent<LogMessage>;
if (ei == null)
{
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.PARAMETER_MISSING, "context"));
return response;
}

// AI: Nothing to do
if (ei.ServiceQueryRequest == null || ei.ServiceQueryRequest.Filters == null)
return response;

// AI: Iterate through the filters and modify the property name for StorageKey and change it to Key
foreach (var filter in ei.ServiceQueryRequest.Filters)
// AI: Iterate through the filters and modify the property name for StorageKey and change it to Key
foreach (var filter in ei.ServiceQueryRequest.Filters)
{
if (filter.Properties != null &&
filter.Properties.Count > 0)
{
bool found = false;
for (int i = 0; i < filter.Properties.Count; i++)
{
if (filter.Properties != null &&
filter.Properties.Count > 0)
if (string.Compare(filter.Properties[i], "StorageKey", true) == 0)
{
bool found = false;
for (int i = 0; i < filter.Properties.Count; i++)
{
if (string.Compare(filter.Properties[i], "StorageKey", true) == 0)
{
found = true;
filter.Properties[i] = "Key";
}
}
if (found)
found = true;
filter.Properties[i] = "Key";
}
}
if (found)
{
// AI: Iterate through the values. Split each one using the delimiter and re-set the value to use the second part. See LogMessageCreateRule for more information.
if (filter.Values != null && filter.Values.Count > 0)
{
for (int i = 0; i < filter.Values.Count; i++)
{
// AI: Iterate through the values. Split each one using the delimiter and re-set the value to use the second part. See LogMessageCreateRule for more information.
if (filter.Values != null && filter.Values.Count > 0)
string[] split = filter.Values[i].Split(StorageAzureDataTablesConstants.KEY_DELIMITER);
if (split.Length == 2)
{
for (int i = 0; i < filter.Values.Count; i++)
{
string[] split = filter.Values[i].Split(StorageAzureDataTablesConstants.KEY_DELIMITER);
if (split.Length == 2)
{
filter.Values[i] = split[1];
}
}
filter.Values[i] = split[1];
}
}
}
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.ERROR_BUSINESS_RULE));
}

return response;
}

/// <summary>
/// Execute the business rule.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task<IResponse> ExecuteRuleAsync(IBusinessRuleContext context)
{
return Task.FromResult<IResponse>(ExecuteRule(context));
}
}
}
Loading

0 comments on commit e7c0722

Please sign in to comment.