BaseStorageProvider.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using qdr.fnd.core.pqueue.Enums;
  2. using qdr.fnd.core.pqueue.Exceptions;
  3. using Quadarax.Foundation.Core.Data;
  4. using Quadarax.Foundation.Core.Logging;
  5. using Quadarax.Foundation.Core.Object;
  6. using Quadarax.Foundation.Core.Value.Generators;
  7. namespace qdr.fnd.core.pqueue.Storages
  8. {
  9. public abstract class BaseStorageProvider : DisposableObject, IPsQueueStorage
  10. {
  11. #region *** Properties ***
  12. protected ILog? Log => _log;
  13. #endregion
  14. #region *** Private Fields ***
  15. private ILog? _log;
  16. private IIdGenerator<string> _tranGenerator;
  17. #endregion
  18. #region *** Constructors ***
  19. protected BaseStorageProvider(ILogger? logger)
  20. {
  21. _log = logger?.GetLogger(GetType().Name);
  22. _tranGenerator = new TinyHash(10);
  23. }
  24. #endregion
  25. #region Implementation of IPsQueueStorage
  26. /// <inheritdoc />
  27. public string CreateItem(string owner, string ownerRef, string providerClass, int initialAttempts, DateTime? created)
  28. {
  29. if (string.IsNullOrWhiteSpace(owner))
  30. throw new ArgumentNullException(nameof(owner));
  31. if (string.IsNullOrWhiteSpace(ownerRef))
  32. throw new ArgumentNullException(nameof(ownerRef));
  33. if (string.IsNullOrWhiteSpace(providerClass))
  34. throw new ArgumentNullException(nameof(providerClass));
  35. if (created == null)
  36. created = DateTime.Now;
  37. var id = _tranGenerator.NewId();
  38. var newId = OnCreateItem(id, owner, ownerRef, providerClass, initialAttempts, created.Value, id);
  39. _log?.Log(LogSeverityEnum.Trace, $"Item [id={id}, owner={owner}, ownerRef{ownerRef}] created");
  40. return newId;
  41. }
  42. protected abstract string OnCreateItem(string id, string owner, string ownerRef, string providerClass, int initialAttempts, DateTime created, string s);
  43. /// <inheritdoc />
  44. public void DeleteItem(string itemId)
  45. {
  46. if (string.IsNullOrWhiteSpace(itemId))
  47. throw new ArgumentNullException(nameof(itemId));
  48. if (!ContainsItem(itemId))
  49. throw new PSStorageException(PSStorageException.ErrorCodes.PsStorageItemNotFound, itemId);
  50. OnDeleteItem(itemId);
  51. }
  52. protected abstract void OnDeleteItem(string itemId);
  53. /// <inheritdoc />
  54. public void UpdateItemPriority(string itemId, int priority)
  55. {
  56. throw new NotImplementedException();
  57. }
  58. /// <inheritdoc />
  59. public void UpdateItemValidity(string itemId, DateTime validForm, DateTime? validTo)
  60. {
  61. throw new NotImplementedException();
  62. }
  63. /// <inheritdoc />
  64. public void UpdateItemStatus(string itemId, PsStatusEnum? status, bool isTransient)
  65. {
  66. throw new NotImplementedException();
  67. }
  68. /// <inheritdoc />
  69. public void UpdateItemAttempts(string itemId, int attemptsLeft)
  70. {
  71. throw new NotImplementedException();
  72. }
  73. /// <inheritdoc />
  74. public void UpdateItemStarted(string itemId, DateTime? started)
  75. {
  76. throw new NotImplementedException();
  77. }
  78. /// <inheritdoc />
  79. public void UpdateItemFinished(string itemId, DateTime? finished)
  80. {
  81. throw new NotImplementedException();
  82. }
  83. /// <inheritdoc />
  84. public void CreateItemAttribute(string itemId, string name, string? value, string valueTypeClass, bool isOutput)
  85. {
  86. throw new NotImplementedException();
  87. }
  88. /// <inheritdoc />
  89. public void UpdateItemAttribute(string itemId, string name, string value)
  90. {
  91. throw new NotImplementedException();
  92. }
  93. /// <inheritdoc />
  94. public void DeleteItemAttribute(string itemId, string name)
  95. {
  96. throw new NotImplementedException();
  97. }
  98. /// <inheritdoc />
  99. public void AppendLog(string transactionId, string itemId, string message, int code, ErrorLevelEnum messageType)
  100. {
  101. throw new NotImplementedException();
  102. }
  103. /// <inheritdoc />
  104. public void AppendStatusJournal(string itemId, PsStatusEnum status, bool isTransient, string message)
  105. {
  106. throw new NotImplementedException();
  107. }
  108. /// <inheritdoc />
  109. public IQueryable<IPsQueueItem> Query(string? owner, string? ownerRef, params Tuple<bool, PsStatusEnum>[] status)
  110. {
  111. throw new NotImplementedException();
  112. }
  113. /// <inheritdoc />
  114. public IPsQueueItem GetItem(string itemId)
  115. {
  116. throw new NotImplementedException();
  117. }
  118. /// <inheritdoc />
  119. public abstract bool ContainsItem(string itemId);
  120. #endregion
  121. }
  122. }