|
@@ -2,8 +2,10 @@
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
+using System.Threading.Tasks;
|
|
|
using System.Timers;
|
|
|
using InABox.Core;
|
|
|
+using IQueryProvider = InABox.Core.IQueryProvider;
|
|
|
|
|
|
namespace InABox.Clients
|
|
|
{
|
|
@@ -58,8 +60,84 @@ namespace InABox.Clients
|
|
|
public CoreTable GetOrDefault(string name) => Results.GetValueOrDefault(name);
|
|
|
}
|
|
|
|
|
|
+ public class ClientQueryProvider<TEntity> : IQueryProvider<TEntity>
|
|
|
+ where TEntity : Entity, IRemotable, new()
|
|
|
+ {
|
|
|
+ #region Non-generic
|
|
|
+
|
|
|
+ public CoreTable Query(IFilter? filter = null, IColumns? columns = null, ISortOrder? sort = null, CoreRange? range = null)
|
|
|
+ {
|
|
|
+ return new Client<TEntity>().Query(filter, columns, sort, range);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ public CoreTable Query(Filter<TEntity>? filter = null, Columns<TEntity>? columns = null, SortOrder<TEntity>? sort = null, CoreRange? range = null)
|
|
|
+ {
|
|
|
+ return Client.Query(filter, columns, sort, range);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Query(Filter<TEntity>? filter, Columns<TEntity>? columns, SortOrder<TEntity>? sort, CoreRange? range, Action<CoreTable?, Exception?> action)
|
|
|
+ {
|
|
|
+ Client.Query(filter, columns, sort, range, action);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Save(TEntity entity, string auditNote)
|
|
|
+ {
|
|
|
+ Client.Save(entity, auditNote);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Save(IEnumerable<TEntity> entities, string auditNote)
|
|
|
+ {
|
|
|
+ Client.Save(entities, auditNote);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Save(TEntity entity, string auditnote, Action<TEntity, Exception?> callback)
|
|
|
+ {
|
|
|
+ Client.Save(entity, auditnote, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Save(IEnumerable<TEntity> entities, string auditnote, Action<IEnumerable<TEntity>, Exception?> callback)
|
|
|
+ {
|
|
|
+ Client.Save(entities, auditnote, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Delete(TEntity entity, string auditNote)
|
|
|
+ {
|
|
|
+ Client.Delete(entity, auditNote);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Delete(IEnumerable<TEntity> entities, string auditNote)
|
|
|
+ {
|
|
|
+ Client.Delete(entities, auditNote);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Delete(TEntity entity, string auditnote, Action<TEntity, Exception?> callback)
|
|
|
+ {
|
|
|
+ Client.Delete(entity, auditnote, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Delete(IEnumerable<TEntity> entities, string auditnote, Action<IList<TEntity>, Exception?> callback)
|
|
|
+ {
|
|
|
+ Client.Delete(entities, auditnote, callback);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public abstract class Client
|
|
|
{
|
|
|
+ #region IQueryProvider Factory
|
|
|
+
|
|
|
+ private class _Factory : IQueryProviderFactory
|
|
|
+ {
|
|
|
+ public IQueryProvider Create(Type T)
|
|
|
+ {
|
|
|
+ return (typeof(ClientQueryProvider<>).MakeGenericType(T) as IQueryProvider)!;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static IQueryProviderFactory Factory { get; } = new _Factory();
|
|
|
+
|
|
|
+ #endregion
|
|
|
|
|
|
public abstract CoreTable Query(IFilter? filter = null, IColumns? columns = null, ISortOrder? sortOrder = null, CoreRange? range = null);
|
|
|
public abstract void Save(Entity entity, string auditNote);
|
|
@@ -183,6 +261,12 @@ namespace InABox.Clients
|
|
|
new Client<TEntity>().Delete(entities, auditNote);
|
|
|
}
|
|
|
|
|
|
+ public static void Delete<TEntity>(IEnumerable<TEntity> entities, string auditNote, Action<IList<TEntity>, Exception?> callback)
|
|
|
+ where TEntity : Entity, IRemotable, new()
|
|
|
+ {
|
|
|
+ new Client<TEntity>().Delete(entities, auditNote, callback);
|
|
|
+ }
|
|
|
+
|
|
|
public static void QueryMultiple(
|
|
|
Action<Dictionary<string, CoreTable>?, Exception?> callback,
|
|
|
Dictionary<string, IQueryDef> queries)
|
|
@@ -369,15 +453,7 @@ namespace InABox.Clients
|
|
|
{
|
|
|
#region IQueryProvider
|
|
|
|
|
|
- private class ClientQueryProvider : IQueryProvider<TEntity>
|
|
|
- {
|
|
|
- public CoreTable Query(Filter<TEntity>? filter = null, Columns<TEntity>? columns = null, SortOrder<TEntity>? sort = null, CoreRange? range = null)
|
|
|
- {
|
|
|
- return Client.Query(filter, columns, sort, range);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static IQueryProvider<TEntity> Provider { get; private set; } = new ClientQueryProvider();
|
|
|
+ public static IQueryProvider<TEntity> Provider { get; private set; } = new ClientQueryProvider<TEntity>();
|
|
|
|
|
|
#endregion
|
|
|
|