-
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.
- Loading branch information
1 parent
f92b731
commit 1491a07
Showing
61 changed files
with
4,561 additions
and
48 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,18 @@ | ||
using System.ComponentModel; | ||
|
||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface IBusinessObject : IUseBusinessContext, INotifyPropertyChanged, INotifyPropertyChanging | ||
{ | ||
FieldDataManager FieldManager { get; } | ||
|
||
bool FieldExists(IPropertyInfo property); | ||
|
||
object ReadProperty(IPropertyInfo propertyInfo); | ||
|
||
TValue ReadProperty<TValue>(PropertyInfo<TValue> propertyInfo); | ||
|
||
void LoadProperty(IPropertyInfo propertyInfo, object newValue); | ||
|
||
void LoadProperty<TValue>(PropertyInfo<TValue> propertyInfo, TValue newValue); | ||
} |
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,5 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface ICommandObject : IBusinessObject | ||
{ | ||
} |
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,26 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface IEditableObject | ||
{ | ||
/// <summary> | ||
/// Gets the current object state. | ||
/// </summary> | ||
ObjectEditState State { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicate if the object can save. | ||
/// </summary> | ||
bool IsSavable { get; } | ||
|
||
bool IsInsert { get; } | ||
|
||
bool IsUpdate { get; } | ||
|
||
bool IsDelete { get; } | ||
|
||
void MarkAsInsert(); | ||
|
||
void MarkAsUpdate(); | ||
|
||
void MarkAsDelete(); | ||
} |
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,37 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface IHasRuleCheck | ||
{ | ||
/// <summary> | ||
/// Gets a value indicate that whether the object is currently valid or not. | ||
/// </summary> | ||
/// <returns><c>True</c> if the object is currently valid, otherwise <c>False</c>.</returns> | ||
bool IsValid { get; } | ||
|
||
/// <summary> | ||
/// Indicates that a rule has completed. | ||
/// </summary> | ||
/// <param name="property"></param> | ||
void RuleCheckComplete(IPropertyInfo property); | ||
|
||
/// <summary> | ||
/// Indicates that a rule has completed. | ||
/// </summary> | ||
/// <param name="property"></param> | ||
void RuleCheckComplete(string property); | ||
|
||
/// <summary> | ||
/// Indicates that all rules have completed. | ||
/// </summary> | ||
void AllRulesComplete(); | ||
|
||
void SuspendRuleChecking(); | ||
|
||
void ResumeRuleChecking(); | ||
|
||
/// <summary> | ||
/// Gets the broken rules for this object | ||
/// </summary> | ||
/// <returns></returns> | ||
BrokenRuleCollection GetBrokenRules(); | ||
} |
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,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface IOperableProperty | ||
{ | ||
object GetProperty(IPropertyInfo propertyInfo); | ||
|
||
void SetProperty(IPropertyInfo propertyInfo, object newValue); | ||
} |
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,6 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface IReadOnlyObject : IBusinessObject | ||
{ | ||
|
||
} |
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,45 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface ISavable | ||
{ | ||
/// <summary> | ||
/// Event raised when an object has been saved. | ||
/// </summary> | ||
event EventHandler<SavedEventArgs> Saved; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="newObject"></param> | ||
void SaveComplete(object newObject); | ||
|
||
/// <summary> | ||
/// Saves the object to the database. | ||
/// </summary> | ||
/// <param name="forceUpdate">true to force the save to be an update.</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns>A new object containing the saved values.</returns> | ||
Task<object> SaveAsync(bool forceUpdate = false, CancellationToken cancellationToken = default); | ||
} | ||
|
||
public interface ISavable<T> where T : class | ||
{ | ||
/// <summary> | ||
/// Saves the object to the database. | ||
/// </summary> | ||
/// <param name="forceUpdate">true to force the save to be an update.</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns>A new object containing the saved values.</returns> | ||
Task<T> SaveAsync(bool forceUpdate = false, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="newObject"></param> | ||
void SaveComplete(T newObject); | ||
|
||
/// <summary> | ||
/// Event raised when an object has been saved. | ||
/// </summary> | ||
event EventHandler<SavedEventArgs> Saved; | ||
} |
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,14 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface ITrackableObject | ||
{ | ||
bool IsValid { get; } | ||
|
||
bool IsChanged { get; } | ||
|
||
bool IsDeleted { get; } | ||
|
||
bool IsNew { get; } | ||
|
||
bool IsSavable { get; } | ||
} |
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,8 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
public interface IUseBusinessContext | ||
{ | ||
BusinessContext BusinessContext { get; set; } | ||
|
||
IServiceProvider GetServiceProvider(); | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Euonia.Business/Attributes/FactoryCreateAttribute.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,10 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
/// <summary> | ||
/// Represent the marked method would create new domain object data. | ||
/// And the method could be invoked by <see cref="IObjectFactory"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class FactoryCreateAttribute : FactoryMethodAttribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Euonia.Business/Attributes/FactoryDeleteAttribute.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,10 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
/// <summary> | ||
/// Represent the marked method would delete domain object data. | ||
/// And the method could be invoked by <see cref="IObjectFactory"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class FactoryDeleteAttribute : FactoryMethodAttribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Euonia.Business/Attributes/FactoryExecuteAttribute.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,10 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
/// <summary> | ||
/// Represent the marked method would execute a defined command. | ||
/// And the method could be invoked by <see cref="IObjectFactory"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
public class FactoryExecuteAttribute : FactoryMethodAttribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Euonia.Business/Attributes/FactoryFetchAttribute.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,10 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
/// <summary> | ||
/// Represent the marked method would find exists domain object data. | ||
/// And the method could be invoked by <see cref="IObjectFactory"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class FactoryFetchAttribute : FactoryMethodAttribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Euonia.Business/Attributes/FactoryInsertAttribute.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,10 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
/// <summary> | ||
/// Represent the marked method would insert a new row with domain object data. | ||
/// And the method could be invoked by <see cref="IObjectFactory"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class FactoryInsertAttribute : FactoryMethodAttribute | ||
{ | ||
} |
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,9 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
/// <summary> | ||
/// Represent the marked method could be invoked by <see cref="IObjectFactory"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public abstract class FactoryMethodAttribute : Attribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Euonia.Business/Attributes/FactoryUpdateAttribute.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,10 @@ | ||
namespace Nerosoft.Euonia.Business; | ||
|
||
/// <summary> | ||
/// Represent the marked method would update domain object data. | ||
/// And the method could be invoked by <see cref="IObjectFactory"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class FactoryUpdateAttribute : FactoryMethodAttribute | ||
{ | ||
} |
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,117 @@ | ||
using System.Security.Claims; | ||
using System.Security.Principal; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Nerosoft.Euonia.Business; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class BusinessContext | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BusinessContext"/> class. | ||
/// </summary> | ||
/// <param name="contextAccessor"></param> | ||
public BusinessContext(BusinessContextAccessor contextAccessor) | ||
{ | ||
ContextAccessor = contextAccessor; | ||
} | ||
|
||
internal BusinessContextAccessor ContextAccessor { get; } | ||
|
||
/// <summary> | ||
/// Get or set the current ClaimsPrincipal object representing the user's identity. | ||
/// </summary> | ||
public ClaimsPrincipal Principal => (ClaimsPrincipal)User; | ||
|
||
/// <summary> | ||
/// Get or set the current <see cref="IPrincipal" /> object representing the user's identity. | ||
/// </summary> | ||
public IPrincipal User { get; set; } | ||
|
||
internal IServiceProvider CurrentServiceProvider => ContextAccessor.ServiceProvider; | ||
|
||
/// <summary> | ||
/// Get the service object of the specified type. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <returns></returns> | ||
/// <exception cref="NullReferenceException"></exception> | ||
public T GetRequiredService<T>() | ||
{ | ||
if (CurrentServiceProvider == null) | ||
{ | ||
throw new NullReferenceException(nameof(CurrentServiceProvider)); | ||
} | ||
|
||
var result = CurrentServiceProvider.GetRequiredService<T>(); | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Get the service object of the specified type. | ||
/// </summary> | ||
/// <param name="serviceType"></param> | ||
/// <returns></returns> | ||
/// <exception cref="NullReferenceException"></exception> | ||
public object GetRequiredService(Type serviceType) | ||
{ | ||
if (CurrentServiceProvider == null) | ||
{ | ||
throw new NullReferenceException(nameof(CurrentServiceProvider)); | ||
} | ||
|
||
return CurrentServiceProvider.GetRequiredService(serviceType); | ||
} | ||
|
||
/// <summary> | ||
/// Create an instance of the specified type using the constructor that best matches the specified parameters. | ||
/// </summary> | ||
/// <param name="parameters"></param> | ||
/// <typeparam name="T"></typeparam> | ||
/// <returns></returns> | ||
public T CreateInstance<T>(params object[] parameters) | ||
{ | ||
return (T)CreateInstance(typeof(T), parameters); | ||
} | ||
|
||
/// <summary> | ||
/// Create an instance of the specified type using the constructor that best matches the specified parameters. | ||
/// </summary> | ||
/// <param name="objectType"></param> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
public object CreateInstance(Type objectType, params object[] parameters) | ||
{ | ||
object result; | ||
if (CurrentServiceProvider != null) | ||
{ | ||
result = ActivatorUtilities.CreateInstance(CurrentServiceProvider, objectType, parameters); | ||
} | ||
else | ||
{ | ||
result = Activator.CreateInstance(objectType, parameters); | ||
} | ||
|
||
if (result is IUseBusinessContext tmp) | ||
{ | ||
tmp.BusinessContext = this; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Create an instance of the specified type using the constructor that best matches the specified parameters. | ||
/// </summary> | ||
/// <param name="type"></param> | ||
/// <param name="paramTypes"></param> | ||
/// <returns></returns> | ||
internal object CreateGenericInstance(Type type, params Type[] paramTypes) | ||
{ | ||
var genericType = type.GetGenericTypeDefinition(); | ||
var gt = genericType.MakeGenericType(paramTypes); | ||
return CreateInstance(gt); | ||
} | ||
} |
Oops, something went wrong.