PsQueueItem.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using qdr.fnd.core.pqueue.Enums;
  2. using Quadarax.Foundation.Core.Data;
  3. namespace qdr.fnd.core.pqueue
  4. {
  5. public class PsQueueItem : IPsQueueItem
  6. {
  7. #region *** Properties ***
  8. /// <inheritdoc />
  9. public string Id { get; protected set; }
  10. /// <inheritdoc />
  11. public string Owner { get; protected set; }
  12. /// <inheritdoc />
  13. public string OwnerRef { get; protected set; }
  14. /// <inheritdoc />
  15. public int Priority { get; internal set; }
  16. /// <inheritdoc />
  17. public DateTime ValidFrom { get; protected internal set; }
  18. /// <inheritdoc />
  19. public DateTime? ValidTo { get; protected internal set; }
  20. /// <inheritdoc />
  21. public DateTime Created { get; protected set; }
  22. /// <inheritdoc />
  23. public DateTime? Started { get; internal set; }
  24. /// <inheritdoc />
  25. public DateTime? Finished { get; internal set; }
  26. /// <inheritdoc />
  27. public PsStatusEnum Status { get; internal set; }
  28. /// <inheritdoc />
  29. public bool IsStatusTransient { get; internal set; }
  30. /// <inheritdoc />
  31. public int AttemptsLeft { get; internal set; }
  32. /// <inheritdoc />
  33. public int AtteptsInitial { get; internal set; }
  34. /// <inheritdoc />
  35. public string ProcessProviderClass { get; protected set; }
  36. /// <inheritdoc />
  37. public IEnumerable<ITypedArgument> Arguments { get; protected set; }
  38. /// <inheritdoc />
  39. public IEnumerable<IError> Log { get; protected set;}
  40. /// <inheritdoc />
  41. public IEnumerable<PsStatusHistory> StatusJournal { get; protected set; }
  42. #endregion
  43. #region *** Constructors ***
  44. public PsQueueItem(string id) : this(id, string.Empty, string.Empty, string.Empty, DateTime.Now, null)
  45. {
  46. }
  47. public PsQueueItem(string id, string owner, string ownerRef, string providerClass, DateTime created, ITypedArgument[]? arguments, int initialAttempts = 0)
  48. {
  49. Id = id;
  50. Status = PsStatusEnum.New;
  51. IsStatusTransient = false;
  52. Owner = owner;
  53. OwnerRef = ownerRef;
  54. ProcessProviderClass = providerClass;
  55. Created = created;
  56. AtteptsInitial = initialAttempts;
  57. Arguments = arguments == null ? new List<ITypedArgument>() : new List<ITypedArgument>(arguments);
  58. Log = new List<IError>();
  59. StatusJournal = new List<PsStatusHistory>();
  60. }
  61. #endregion
  62. #region *** Public operations ***
  63. public void SetStatus(PsStatusEnum? status, bool isTransient, string message)
  64. {
  65. if (string.IsNullOrEmpty(message))
  66. throw new ArgumentNullException(nameof(message));
  67. ((List<PsStatusHistory>)StatusJournal).Add(
  68. new PsStatusHistory(Status, IsStatusTransient, message)
  69. );
  70. Status = status ?? Status;
  71. IsStatusTransient = isTransient;
  72. }
  73. #endregion
  74. }
  75. }