9using System.Collections.Concurrent;
10using System.Threading.Tasks;
17 private static readonly ConcurrentDictionary<Type, DataPortalMethodNames> _methodNameList =
18 new ConcurrentDictionary<Type, DataPortalMethodNames>();
19 private readonly IDataPortalTarget _target;
20 private readonly DataPortalMethodNames _methodNames;
22 public DataPortalTarget(
object obj)
25 _target = obj as IDataPortalTarget;
26 _methodNames = _methodNameList.GetOrAdd(obj.GetType(),
27 (t) => DataPortalMethodNames.Default);
30 public void OnDataPortalInvoke(DataPortalEventArgs eventArgs)
33 _target.DataPortal_OnDataPortalInvoke(eventArgs);
38 public void Child_OnDataPortalInvoke(DataPortalEventArgs eventArgs)
41 _target.Child_OnDataPortalInvoke(eventArgs);
47 public void OnDataPortalInvokeComplete(DataPortalEventArgs eventArgs)
50 _target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
55 internal void Child_OnDataPortalInvokeComplete(DataPortalEventArgs eventArgs)
58 _target.Child_OnDataPortalInvokeComplete(eventArgs);
63 internal void OnDataPortalException(DataPortalEventArgs eventArgs, Exception ex)
66 _target.DataPortal_OnDataPortalException(eventArgs, ex);
72 internal void Child_OnDataPortalException(DataPortalEventArgs eventArgs, Exception ex)
75 _target.Child_OnDataPortalException(eventArgs, ex);
80 public void ThrowIfBusy()
83 throw new InvalidOperationException(
string.Format(
"{0}.IsBusy == true",
Instance.GetType().Name));
94 public void MarkAsChild()
97 _target.MarkAsChild();
102 internal void MarkOld()
110 private async Task InvokeOperationAsync<T>(
object criteria,
bool isSync)
111 where T : DataPortalOperationAttribute
113 object[] parameters = DataPortal.GetCriteriaArray(criteria);
114 await CallMethodTryAsyncDI<T>(isSync, parameters).ConfigureAwait(
false);
117 public async Task CreateAsync(
object criteria,
bool isSync)
119 await InvokeOperationAsync<CreateAttribute>(criteria, isSync).ConfigureAwait(
false);
122 public async Task CreateChildAsync(params
object[] parameters)
124 await CallMethodTryAsyncDI<CreateChildAttribute>(
false, parameters).ConfigureAwait(
false);
127 public async Task FetchAsync(
object criteria,
bool isSync)
129 await InvokeOperationAsync<FetchAttribute>(criteria, isSync).ConfigureAwait(
false);
132 public async Task FetchChildAsync(params
object[] parameters)
134 await CallMethodTryAsyncDI<FetchChildAttribute>(
false, parameters).ConfigureAwait(
false);
138 public async Task UpdateAsync(
bool isSync)
140 if (Instance is Core.BusinessBase busObj)
142 if (busObj.IsDeleted)
147 await InvokeOperationAsync<DeleteSelfAttribute>(EmptyCriteria.Instance, isSync).ConfigureAwait(
false);
156 await InvokeOperationAsync<InsertAttribute>(EmptyCriteria.Instance, isSync).ConfigureAwait(
false);
161 await InvokeOperationAsync<UpdateAttribute>(EmptyCriteria.Instance, isSync).ConfigureAwait(
false);
171 await InvokeOperationAsync<UpdateAttribute>(EmptyCriteria.Instance, isSync).ConfigureAwait(
false);
176 public async Task UpdateChildAsync(params
object[] parameters)
179 if (Instance is Core.BusinessBase busObj)
181 if (busObj.IsDeleted)
186 await CallMethodTryAsyncDI<DeleteSelfChildAttribute>(
false, parameters).ConfigureAwait(
false);
195 await CallMethodTryAsyncDI<InsertChildAttribute>(
false, parameters).ConfigureAwait(
false);
200 await CallMethodTryAsyncDI<UpdateChildAttribute>(
false, parameters).ConfigureAwait(
false);
206 else if (Instance is Core.ICommandObject)
209 await CallMethodTryAsyncDI<ExecuteChildAttribute>(
false, parameters).ConfigureAwait(
false);
216 await CallMethodTryAsyncDI<UpdateChildAttribute>(
false, parameters).ConfigureAwait(
false);
221 public async Task ExecuteAsync(
bool isSync)
223 await InvokeOperationAsync<ExecuteAttribute>(EmptyCriteria.Instance, isSync).ConfigureAwait(
false);
226 public async Task DeleteAsync(
object criteria,
bool isSync)
228 await InvokeOperationAsync<DeleteAttribute>(criteria, isSync).ConfigureAwait(
false);
232 internal class DataPortalMethodNames
234 public static readonly DataPortalMethodNames
Default =
new DataPortalMethodNames();
235 public string OnDataPortalInvoke {
get;
set; } =
"DataPortal_OnDataPortalInvoke";
236 public string OnDataPortalInvokeComplete {
get;
set; } =
"DataPortal_OnDataPortalInvokeComplete";
237 public string OnDataPortalException {
get;
set; } =
"DataPortal_OnDataPortalException";
Enables simple invocation of methods against the contained object using late binding.
object CallMethodIfImplemented(string method)
Uses reflection to dynamically invoke a method if that method is implemented on the target object.
object Instance
Object instance managed by LateBoundObject.
bool IsBusy
Gets a value indicating whether the object, or any of the object's child objects, are busy running an...
Defines the common properties required objects that track their own status.
@ Default
Default value, rule can run in any context