ConfigurationProvider.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using InABox.Clients;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace InABox.Core
  6. {
  7. public interface IConfigurationProvider<T>
  8. where T : Entity, IRemotable, IPersistent, new()
  9. {
  10. string UserID { get; }
  11. T[] Load(Filter<T> filter);
  12. CoreTable Query(Filter<T> filter, Columns<T> columns, SortOrder<T>? sort = null);
  13. void Save(T entity);
  14. void Save(IEnumerable<T> entities);
  15. void Delete(T entity, Action<Exception?>? callback = null);
  16. }
  17. public class ClientConfigurationProvider<T> : IConfigurationProvider<T>
  18. where T : Entity, IRemotable, IPersistent, new()
  19. {
  20. public static ClientConfigurationProvider<T> Provider = new ClientConfigurationProvider<T>();
  21. public string UserID => ClientFactory.UserID;
  22. public T[] Load(Filter<T> filter)
  23. {
  24. return Client.Query(filter, null).ToArray<T>();
  25. }
  26. public CoreTable Query(Filter<T> filter, Columns<T> columns, SortOrder<T>? sort)
  27. {
  28. return Client.Query(filter, columns, sort);
  29. }
  30. public void Save(T entity)
  31. {
  32. Client.Save(entity, "", (o, e) => { });
  33. }
  34. public void Save(IEnumerable<T> entities)
  35. {
  36. Client.Save(entities, "", (o, e) => { });
  37. }
  38. public void Delete(T entity, Action<Exception?>? callback = null)
  39. {
  40. if(callback != null)
  41. {
  42. Client.Delete(entity, "", (o, e) => { callback(e); });
  43. }
  44. else
  45. {
  46. Client.Delete(entity, "");
  47. }
  48. }
  49. }
  50. }