using System.Collections.Concurrent; using qdr.fnd.core.pqueue.Enums; using Quadarax.Foundation.Core.Data; using Quadarax.Foundation.Core.Logging; using Quadarax.Foundation.Core.Object; using Quadarax.Foundation.Core.Value.Generators; namespace qdr.fnd.core.pqueue.Storages { public abstract class BaseStorageProvider : DisposableObject, IPsQueueStorage { #region *** Properties *** #endregion #region *** Private Fields *** private IDictionary> _tranScopes = new ConcurrentDictionary>(); private ILog? _log; private IIdGenerator? _tranGenerator; #endregion #region *** Constructors *** protected BaseStorageProvider(ILogger? logger) { _log = logger?.GetLogger(GetType().Name); _tranGenerator = new TinyHash(10); } #endregion #region *** Operations *** #region **** Transaction **** /// public string CreateTransaction() { throw new NotImplementedException(); } /// public void CommitTransaction(string transactionId) { throw new NotImplementedException(); } /// public void RollbackTransaction(string transactionId) { throw new NotImplementedException(); } #endregion /// public string CreateItem(string transactionId, string owner, string ownerRef, string providerClass, DateTime? created) { throw new NotImplementedException(); } /// public void DeleteItem(string transactionId, string itemId) { throw new NotImplementedException(); } /// public void UpdateItemPriority(string transactionId, string itemId, int priority) { throw new NotImplementedException(); } /// public void UpdateItemValidity(string transactionId, string itemId, DateTime validForm, DateTime? validTo) { throw new NotImplementedException(); } /// public void UpdateItemStatus(string transactionId, string itemId, PsStatusEnum? status, bool isTransient) { throw new NotImplementedException(); } /// public void UpdateItemAttempts(string transactionId, string itemId, int attemptsLeft) { throw new NotImplementedException(); } /// public void UpdateItemStarted(string transactionId, string itemId, DateTime? started) { throw new NotImplementedException(); } /// public void UpdateItemFinished(string transactionId, string itemId, DateTime? finished) { throw new NotImplementedException(); } /// public void CreateItemAttribute(string transactionId, string itemId, string name, string? value, string valueTypeClass, bool isOutput) { throw new NotImplementedException(); } /// public void UpdateItemAttribute(string transactionId, string itemId, string name, string value) { throw new NotImplementedException(); } /// public void DeleteItemAttribute(string transactionId, string itemId, string name) { throw new NotImplementedException(); } /// public void AppendLog(string transactionId, string itemId, string message, int code, ErrorLevelEnum messageType) { throw new NotImplementedException(); } /// public void AppendStatusJournal(string transactionId, string itemId, PsStatusEnum status, bool isTransient, string message) { throw new NotImplementedException(); } /// public IQueryable Query(string? owner, string? ownerRef, params Tuple[] status) { throw new NotImplementedException(); } /// public IPsQueueItem GetItem(string? transactionId, string itemId) { throw new NotImplementedException(); } #endregion #region *** Private Operations *** #region Overrides of DisposableObject /// protected override void OnDisposing() { // rollback all transactions foreach (var tranId in _tranScopes.Keys.ToArray()) { if(_tranScopes.ContainsKey(tranId)) RollbackTransaction(tranId); } // cleanup rest of transaction scopes _tranScopes.Clear(); // cleanup logger _log = null; // cleanup id generator _tranGenerator = null; } protected void Log(LogSeverityEnum severity, string? transactionId, string itemId, string message, Exception? ex = null) { if (!string.IsNullOrWhiteSpace(transactionId)) message = $"[TRX: {transactionId}; ID: {itemId}] {message}"; _log?.Log(severity, message, ex); } protected void Log(LogSeverityEnum severity, string message, Exception? ex = null) { Log(severity, null, string.Empty, message, ex); } #endregion #endregion } }