Metadata.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System.Text.Json.Serialization;
  2. namespace qdr.app.studiou.orders2printpack.EmailStorage
  3. {
  4. /// <summary>
  5. /// Root metadata container that holds information about the overall processing system
  6. /// and maintains a collection of individual email items. This is the main data structure
  7. /// that gets serialized to/from the metadata.json file.
  8. /// </summary>
  9. public class Metadata
  10. {
  11. /// <summary>
  12. /// Timestamp when this metadata file was first created.
  13. /// This helps track the age of the processing batch and provides audit information.
  14. /// </summary>
  15. [JsonRequired]
  16. [JsonPropertyName("metadata-created")]
  17. public DateTime Created { get; set; } = DateTime.Now;
  18. /// <summary>
  19. /// Timestamp of the last modification to this metadata.
  20. /// Updated whenever items are added, removed, or their state changes.
  21. /// Null when no modifications have been made since creation.
  22. /// </summary>
  23. [JsonPropertyName("metadata-modified")]
  24. public DateTime? Modified { get; set; } = null;
  25. /// <summary>
  26. /// Collection of individual email items being processed.
  27. /// Each item represents one recipient with their associated files and processing state.
  28. /// </summary>
  29. [JsonRequired]
  30. [JsonPropertyName("items")]
  31. public List<MetadataItem> Items { get; set; } = new List<MetadataItem>();
  32. }
  33. /// <summary>
  34. /// Represents a single email item with all associated processing information.
  35. /// Contains details about the recipient, files, processing state, and email content.
  36. /// This is the core data structure that tracks each individual email through the workflow.
  37. /// </summary>
  38. public class MetadataItem
  39. {
  40. #region Directory and File Information
  41. /// <summary>
  42. /// Name of the directory containing files for this email item.
  43. /// Typically matches or is derived from the recipient's email address.
  44. /// Used to locate the source files for processing.
  45. /// </summary>
  46. [JsonPropertyName("directory-name")]
  47. [JsonRequired]
  48. public string DirectoryName { get; set; } = string.Empty;
  49. /// <summary>
  50. /// Current processing state of this email item.
  51. /// Tracks progression through Ready -> Processing -> Uploading -> Sending -> Sent.
  52. /// Can also be Error if something goes wrong.
  53. /// </summary>
  54. [JsonPropertyName("state")]
  55. [JsonRequired]
  56. public EmailStateEnum State { get; set; } = EmailStateEnum.Ready;
  57. #endregion
  58. #region Recipient Information
  59. /// <summary>
  60. /// Email address of the recipient who will receive the processed files.
  61. /// This is the primary identifier for the email item.
  62. /// </summary>
  63. [JsonPropertyName("email-address")]
  64. [JsonRequired]
  65. public string EmailAddress { get; set; } = string.Empty;
  66. #endregion
  67. #region Email Content
  68. /// <summary>
  69. /// Subject line for the email that will be sent to the recipient.
  70. /// Initially populated from the email template, may be personalized during processing.
  71. /// </summary>
  72. [JsonPropertyName("subject")]
  73. [JsonRequired]
  74. public string Subject { get; set; } = string.Empty;
  75. /// <summary>
  76. /// Body content of the email in HTML or plain text format.
  77. /// Initially from template, gets personalized with download links, passwords, etc.
  78. /// </summary>
  79. [JsonPropertyName("body")]
  80. [JsonRequired]
  81. public string Body { get; set; } = string.Empty;
  82. #endregion
  83. #region File and Attachment Information
  84. /// <summary>
  85. /// Filename of the compressed attachment that will be uploaded and sent.
  86. /// Generated during processing and includes timestamp for uniqueness.
  87. /// Example: "studioufoto_user_at_example_dot_com_20240530_143022.zip"
  88. /// </summary>
  89. [JsonPropertyName("attachment")]
  90. [JsonRequired]
  91. public string FileNameAttachment { get; set; } = string.Empty;
  92. /// <summary>
  93. /// Size of the compressed attachment file in bytes.
  94. /// Populated after compression is complete, used for upload progress tracking.
  95. /// </summary>
  96. [JsonPropertyName("attachment-size")]
  97. [JsonRequired]
  98. public int SizeAttachment { get; set; } = 0;
  99. /// <summary>
  100. /// Number of individual files (typically JPG images) contained within the compressed attachment.
  101. /// Derived from scanning the source directory during metadata update.
  102. /// </summary>
  103. [JsonPropertyName("attachment-content-count")]
  104. [JsonRequired]
  105. public int InternalFilesCount { get; set; } = 0;
  106. #endregion
  107. #region Business Logic
  108. /// <summary>
  109. /// Comma-separated list of order numbers extracted from the filenames.
  110. /// Used for business reference and included in email communications.
  111. /// Example: "1001,1002,1003" extracted from files like "1001_photo1.jpg", "1002_photo1.jpg"
  112. /// </summary>
  113. [JsonPropertyName("orders")]
  114. [JsonRequired]
  115. public string Orders { get; set; } = string.Empty;
  116. #endregion
  117. #region Upload and Download Information
  118. /// <summary>
  119. /// Permanent link URL where the recipient can download their files.
  120. /// Generated by the Temporary Shared Storage service after successful upload.
  121. /// This link is included in the email sent to the recipient.
  122. /// </summary>
  123. [JsonPropertyName("upload-permalink")]
  124. public string UploadPermalink { get; set; } = string.Empty;
  125. /// <summary>
  126. /// Password required to access the download link.
  127. /// Generated during upload process for security.
  128. /// Included in the email so recipient can access their files.
  129. /// </summary>
  130. [JsonPropertyName("download-password")]
  131. public string DownloadPassword { get; set; } = string.Empty;
  132. #endregion
  133. #region Audit and Tracking
  134. /// <summary>
  135. /// Timestamp when this item completed processing (compression and upload).
  136. /// Null until processing is complete, used for audit and performance tracking.
  137. /// </summary>
  138. [JsonPropertyName("processed-date")]
  139. public DateTime? ProcessedDate { get; set; }
  140. /// <summary>
  141. /// Timestamp when the email was successfully sent to the recipient.
  142. /// Null until email sending is complete, marks final completion of the workflow.
  143. /// </summary>
  144. [JsonPropertyName("sent-date")]
  145. public DateTime? SentDate { get; set; }
  146. /// <summary>
  147. /// Error message if processing failed at any stage.
  148. /// Null when no errors have occurred, populated when State is set to Error.
  149. /// Used for debugging and manual intervention.
  150. /// </summary>
  151. [JsonPropertyName("error-message")]
  152. public string? ErrorMessage { get; set; }
  153. #endregion
  154. }
  155. }