IQueryProvider.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace InABox.Core
  5. {
  6. public interface IQueryProvider
  7. {
  8. CoreTable Query(IFilter? filter = null, IColumns? columns = null, ISortOrder? sort = null, CoreRange? range = null);
  9. }
  10. public interface IQueryProvider<T> : IQueryProvider
  11. {
  12. CoreTable Query(Filter<T>? filter = null, Columns<T>? columns = null, SortOrder<T>? sort = null, CoreRange? range = null);
  13. void Query(Filter<T>? filter, Columns<T>? columns, SortOrder<T>? sort, CoreRange? range, Action<CoreTable?, Exception?> action);
  14. void Save(T entity, string auditNote);
  15. void Save(IEnumerable<T> entities, string auditNote);
  16. void Save(T entity, string auditnote, Action<T, Exception?> callback);
  17. void Save(IEnumerable<T> entities, string auditnote, Action<IEnumerable<T>, Exception?> callback);
  18. void Delete(T entity, string auditNote);
  19. void Delete(IEnumerable<T> entities, string auditNote);
  20. void Delete(T entity, string auditnote, Action<T, Exception?> callback);
  21. void Delete(IEnumerable<T> entities, string auditnote, Action<IList<T>, Exception?> callback);
  22. }
  23. public interface IQueryProviderFactory
  24. {
  25. IQueryProvider Create(Type T);
  26. IQueryProvider<T> Create<T>()
  27. where T : BaseObject, new()
  28. {
  29. return (Create(typeof(T)) as IQueryProvider<T>)!;
  30. }
  31. }
  32. public static class QueryProviderFactoryExtensions
  33. {
  34. public static CoreTable Query<T>(this IQueryProviderFactory factory, Filter<T>? filter = null, Columns<T>? columns = null, SortOrder<T>? sort = null, CoreRange? range = null)
  35. where T : BaseObject, new()
  36. {
  37. return factory.Create<T>().Query(filter, columns, sort, range);
  38. }
  39. public static void Query<T>(this IQueryProviderFactory factory, Filter<T>? filter, Columns<T>? columns, SortOrder<T>? sort, CoreRange? range, Action<CoreTable?, Exception?> action)
  40. where T : BaseObject, new()
  41. {
  42. factory.Create<T>().Query(filter, columns, sort, range, action);
  43. }
  44. public static void Save<T>(this IQueryProviderFactory factory, T entity, string auditNote)
  45. where T : BaseObject, new()
  46. {
  47. factory.Create<T>().Save(entity, auditNote);
  48. }
  49. public static void Save<T>(this IQueryProviderFactory factory, IEnumerable<T> entities, string auditNote)
  50. where T : BaseObject, new()
  51. {
  52. factory.Create<T>().Save(entities, auditNote);
  53. }
  54. public static void Delete<T>(this IQueryProviderFactory factory, T entity, string auditNote)
  55. where T : BaseObject, new()
  56. {
  57. factory.Create<T>().Delete(entity, auditNote);
  58. }
  59. }
  60. }