-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Widget, Reporting Widget only for add #157
- Loading branch information
1 parent
29853e5
commit 81e297e
Showing
22 changed files
with
325 additions
and
16 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
22 changes: 22 additions & 0 deletions
22
src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidget.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,22 @@ | ||
using EasyMicroservices.Cores.Interfaces; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.Cores.Database.Interfaces; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IDatabaseWidget<T> : IWidget<T> | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
bool CanProcess(IBaseUnitOfWork baseUnitOfWork); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="databaseWidgetManager"></param> | ||
/// <param name="baseUnitOfWork"></param> | ||
/// <param name="contract"></param> | ||
/// <returns></returns> | ||
Task Process(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, T contract); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidgetManager.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,19 @@ | ||
using EasyMicroservices.Cores.Interfaces; | ||
using EasyMicroservices.Database.Interfaces; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.Cores.Database.Interfaces; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IDatabaseWidgetManager : IWidgetManager | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="baseUnitOfWork"></param> | ||
/// <param name="contract"></param> | ||
/// <returns></returns> | ||
Task Add<T>(IBaseUnitOfWork baseUnitOfWork, T contract); | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DatabaseWidgetManager.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,31 @@ | ||
using EasyMicroservices.Cores.Database.Interfaces; | ||
using EasyMicroservices.Cores.Interfaces; | ||
using EasyMicroservices.Cores.Widgets; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.Cores.Database.Managers; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class DatabaseWidgetManager : WidgetManager, IDatabaseWidgetManager | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="baseUnitOfWork"></param> | ||
/// <param name="contract"></param> | ||
/// <returns></returns> | ||
public async Task Add<T>(IBaseUnitOfWork baseUnitOfWork, T contract) | ||
{ | ||
var widgets = GetWidgetsByType(typeof(T)); | ||
foreach (var widget in widgets) | ||
{ | ||
if (widget is IDatabaseWidget<T> databaseWidget && databaseWidget.CanProcess(baseUnitOfWork)) | ||
{ | ||
await databaseWidget.Process(this, baseUnitOfWork, contract); | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/CSharp/EasyMicroservices.Cores.Database/Database/Widgets/DatabaseBuilderWidget.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,34 @@ | ||
using EasyMicroservices.Cores.Interfaces; | ||
using System; | ||
using System.Reflection.Emit; | ||
|
||
namespace EasyMicroservices.Cores.Database.Widgets; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class DatabaseBuilderWidget<TModelBuilder> : IWidget | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public void Build() | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="modelBuilder"></param> | ||
/// <param name="suffix"></param> | ||
/// <param name="prefix"></param> | ||
public abstract void OnModelCreating(TModelBuilder modelBuilder, string suffix = "", string prefix = ""); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
public Type GetObjectType() | ||
{ | ||
return typeof(DatabaseBuilderWidget<TModelBuilder>); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/CSharp/EasyMicroservices.Cores.Database/Database/Widgets/ReportingBuilderWidget.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,22 @@ | ||
using EasyMicroservices.Cores.Interfaces; | ||
using System; | ||
|
||
namespace EasyMicroservices.Cores.Database.Widgets; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class ReportingBuilderWidget : IWidget | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract void Build(); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
public Type GetObjectType() | ||
{ | ||
return typeof(ReportingBuilderWidget); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/CSharp/EasyMicroservices.Cores.Database/Database/Widgets/SimpleReportingEntityWidget.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 EasyMicroservices.Cores.Database.Interfaces; | ||
using EasyMicroservices.Cores.Interfaces; | ||
using EasyMicroservices.ServiceContracts; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.Cores.Widgets; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <typeparam name="TReportEntity"></typeparam> | ||
/// <typeparam name="TObjectContract"></typeparam> | ||
public class SimpleReportingEntityWidget<TReportEntity, TObjectContract> : IDatabaseWidget<TObjectContract> | ||
where TReportEntity : class | ||
where TObjectContract : class | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public void Build() | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public bool CanProcess(IBaseUnitOfWork baseUnitOfWork) | ||
{ | ||
if (baseUnitOfWork.LogicOptions.HasValue) | ||
return !baseUnitOfWork.LogicOptions.Value.DoStopReporting; | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
public Type GetObjectType() | ||
{ | ||
return typeof(TObjectContract); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
public Task Initialize(params TObjectContract[] parameters) | ||
{ | ||
return TaskHelper.GetCompletedTask(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="databaseWidgetManager"></param> | ||
/// <param name="baseUnitOfWork"></param> | ||
/// <param name="contract"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NotImplementedException"></exception> | ||
public async Task Process(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, TObjectContract contract) | ||
{ | ||
var reportEntity = await baseUnitOfWork | ||
.GetMapper() | ||
.MapAsync<TReportEntity>(contract); | ||
|
||
await baseUnitOfWork.GetLogic<TReportEntity>(new Models.LogicOptions() | ||
{ | ||
DoStopReporting = true | ||
}) | ||
.Add(reportEntity) | ||
.AsCheckedResult(); | ||
} | ||
} |
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
Oops, something went wrong.