BaseStorageProvider.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System.Collections.Concurrent;
  2. using qdr.fnd.core.pqueue.Enums;
  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. #endregion
  13. #region *** Private Fields ***
  14. private IDictionary<string, IList<IPsQueueItem>> _tranScopes =
  15. new ConcurrentDictionary<string, IList<IPsQueueItem>>();
  16. private ILog? _log;
  17. private IIdGenerator<string>? _tranGenerator;
  18. #endregion
  19. #region *** Constructors ***
  20. protected BaseStorageProvider(ILogger? logger)
  21. {
  22. _log = logger?.GetLogger(GetType().Name);
  23. _tranGenerator = new TinyHash(10);
  24. }
  25. #endregion
  26. #region *** Operations ***
  27. #region **** Transaction ****
  28. /// <inheritdoc />
  29. public string CreateTransaction()
  30. {
  31. throw new NotImplementedException();
  32. }
  33. /// <inheritdoc />
  34. public void CommitTransaction(string transactionId)
  35. {
  36. throw new NotImplementedException();
  37. }
  38. /// <inheritdoc />
  39. public void RollbackTransaction(string transactionId)
  40. {
  41. throw new NotImplementedException();
  42. }
  43. #endregion
  44. /// <inheritdoc />
  45. public string CreateItem(string transactionId, string owner, string ownerRef, string providerClass, DateTime? created)
  46. {
  47. throw new NotImplementedException();
  48. }
  49. /// <inheritdoc />
  50. public void DeleteItem(string transactionId, string itemId)
  51. {
  52. throw new NotImplementedException();
  53. }
  54. /// <inheritdoc />
  55. public void UpdateItemPriority(string transactionId, string itemId, int priority)
  56. {
  57. throw new NotImplementedException();
  58. }
  59. /// <inheritdoc />
  60. public void UpdateItemValidity(string transactionId, string itemId, DateTime validForm, DateTime? validTo)
  61. {
  62. throw new NotImplementedException();
  63. }
  64. /// <inheritdoc />
  65. public void UpdateItemStatus(string transactionId, string itemId, PsStatusEnum? status, bool isTransient)
  66. {
  67. throw new NotImplementedException();
  68. }
  69. /// <inheritdoc />
  70. public void UpdateItemAttempts(string transactionId, string itemId, int attemptsLeft)
  71. {
  72. throw new NotImplementedException();
  73. }
  74. /// <inheritdoc />
  75. public void UpdateItemStarted(string transactionId, string itemId, DateTime? started)
  76. {
  77. throw new NotImplementedException();
  78. }
  79. /// <inheritdoc />
  80. public void UpdateItemFinished(string transactionId, string itemId, DateTime? finished)
  81. {
  82. throw new NotImplementedException();
  83. }
  84. /// <inheritdoc />
  85. public void CreateItemAttribute(string transactionId, string itemId, string name, string? value, string valueTypeClass,
  86. bool isOutput)
  87. {
  88. throw new NotImplementedException();
  89. }
  90. /// <inheritdoc />
  91. public void UpdateItemAttribute(string transactionId, string itemId, string name, string value)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. /// <inheritdoc />
  96. public void DeleteItemAttribute(string transactionId, string itemId, string name)
  97. {
  98. throw new NotImplementedException();
  99. }
  100. /// <inheritdoc />
  101. public void AppendLog(string transactionId, string itemId, string message, int code, ErrorLevelEnum messageType)
  102. {
  103. throw new NotImplementedException();
  104. }
  105. /// <inheritdoc />
  106. public void AppendStatusJournal(string transactionId, string itemId, PsStatusEnum status, bool isTransient, string message)
  107. {
  108. throw new NotImplementedException();
  109. }
  110. /// <inheritdoc />
  111. public IQueryable<IPsQueueItem> Query(string? owner, string? ownerRef, params Tuple<bool, PsStatusEnum>[] status)
  112. {
  113. throw new NotImplementedException();
  114. }
  115. /// <inheritdoc />
  116. public IPsQueueItem GetItem(string? transactionId, string itemId)
  117. {
  118. throw new NotImplementedException();
  119. }
  120. #endregion
  121. #region *** Private Operations ***
  122. #region Overrides of DisposableObject
  123. /// <inheritdoc />
  124. protected override void OnDisposing()
  125. {
  126. // rollback all transactions
  127. foreach (var tranId in _tranScopes.Keys.ToArray())
  128. {
  129. if(_tranScopes.ContainsKey(tranId))
  130. RollbackTransaction(tranId);
  131. }
  132. // cleanup rest of transaction scopes
  133. _tranScopes.Clear();
  134. // cleanup logger
  135. _log = null;
  136. // cleanup id generator
  137. _tranGenerator = null;
  138. }
  139. protected void Log(LogSeverityEnum severity, string? transactionId, string itemId, string message, Exception? ex = null)
  140. {
  141. if (!string.IsNullOrWhiteSpace(transactionId))
  142. message = $"[TRX: {transactionId}; ID: {itemId}] {message}";
  143. _log?.Log(severity, message, ex);
  144. }
  145. protected void Log(LogSeverityEnum severity, string message, Exception? ex = null)
  146. {
  147. Log(severity, null, string.Empty, message, ex);
  148. }
  149. #endregion
  150. #endregion
  151. }
  152. }