-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.1.0-b prerelease BREAKING CHANGES
Code cleanup
- Loading branch information
Danny Logsdon
committed
Aug 24, 2024
1 parent
7ab8484
commit 6eaacf0
Showing
106 changed files
with
559 additions
and
1,502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/V1/ServiceBricks.Logging.Cosmos/Rule/LogMessageCreateRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Microsoft.Extensions.Logging; | ||
using ServiceBricks.Storage.EntityFrameworkCore; | ||
|
||
namespace ServiceBricks.Logging.Cosmos | ||
{ | ||
/// <summary> | ||
/// This is a business rule for creating a LogMessage domain object. It will set the Key and PartitionKey. | ||
/// </summary> | ||
public sealed class LogMessageCreateRule : BusinessRule | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
/// <param name="loggerFactory"></param> | ||
public LogMessageCreateRule(ILoggerFactory loggerFactory) | ||
{ | ||
_logger = loggerFactory.CreateLogger<LogMessageCreateRule>(); | ||
Priority = PRIORITY_LOW; | ||
} | ||
|
||
/// <summary> | ||
/// Register the business rule to the DomainCreateBeforeEvent. | ||
/// </summary> | ||
/// <param name="registry"></param> | ||
public static void RegisterRule(IBusinessRuleRegistry registry) | ||
{ | ||
registry.RegisterItem( | ||
typeof(DomainCreateBeforeEvent<LogMessage>), | ||
typeof(LogMessageCreateRule)); | ||
} | ||
|
||
/// <summary> | ||
/// Execute the business rule. | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <returns></returns> | ||
public override IResponse ExecuteRule(IBusinessRuleContext context) | ||
{ | ||
var response = new Response(); | ||
|
||
try | ||
{ | ||
// AI: Make sure the context object is the correct type | ||
if (context.Object is DomainCreateBeforeEvent<LogMessage> e) | ||
{ | ||
// AI: Set the Key and PartitionKey | ||
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"); | ||
} | ||
} | ||
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) | ||
{ | ||
// AI: There is no async work, so just call the sync method | ||
return Task.FromResult<IResponse>(ExecuteRule(context)); | ||
} | ||
} | ||
} |
Oops, something went wrong.