|
| 1 | +namespace DocumentTranslationApp.Models; |
| 2 | + |
| 3 | +public enum JobStatus |
| 4 | +{ |
| 5 | + Pending, |
| 6 | + Running, |
| 7 | + Processing, |
| 8 | + Completed, |
| 9 | + Failed, |
| 10 | + Cancelled, |
| 11 | +} |
| 12 | + |
| 13 | +public class TranslationRequest |
| 14 | +{ |
| 15 | + public required string SiteUrl { get; set; } |
| 16 | + public required List<DocumentInfo> Documents { get; set; } |
| 17 | + public required TranslationOptions Options { get; set; } |
| 18 | + public RequestContext? Context { get; set; } |
| 19 | + public string? UserAccessToken { get; set; } // Token from SPFx for On-Behalf-Of flow |
| 20 | +} |
| 21 | + |
| 22 | +public class DocumentInfo |
| 23 | +{ |
| 24 | + public required string Id { get; set; } |
| 25 | + public required string Name { get; set; } |
| 26 | + public required string ServerRelativeUrl { get; set; } |
| 27 | + public long Size { get; set; } |
| 28 | + public required string FileType { get; set; } |
| 29 | + public bool IsSupported { get; set; } |
| 30 | + public string? ErrorMessage { get; set; } |
| 31 | +} |
| 32 | + |
| 33 | +public class TranslationOptions |
| 34 | +{ |
| 35 | + public string? SourceLanguage { get; set; } // Optional for auto-detect |
| 36 | + public required List<string> TargetLanguages { get; set; } |
| 37 | +} |
| 38 | + |
| 39 | +public class RequestContext |
| 40 | +{ |
| 41 | + public required string UserId { get; set; } |
| 42 | + public required string WebId { get; set; } |
| 43 | + public required string TenantId { get; set; } // Required for On-Behalf-Of flow |
| 44 | + public required string ListId { get; set; } |
| 45 | +} |
| 46 | + |
| 47 | +public class TranslationResult |
| 48 | +{ |
| 49 | + public bool Success { get; set; } |
| 50 | + public required string JobId { get; set; } |
| 51 | + public required string Message { get; set; } |
| 52 | + public int EstimatedDocuments { get; set; } |
| 53 | + public List<string>? Errors { get; set; } |
| 54 | +} |
| 55 | + |
| 56 | +public class TranslatedDocument |
| 57 | +{ |
| 58 | + public required string OriginalName { get; set; } |
| 59 | + public required string TargetLanguage { get; set; } |
| 60 | + public required string TranslatedName { get; set; } |
| 61 | + public required string ServerRelativeUrl { get; set; } |
| 62 | + public int CharacterCount { get; set; } |
| 63 | +} |
| 64 | + |
| 65 | +public class FailedDocument |
| 66 | +{ |
| 67 | + public required string Name { get; set; } |
| 68 | + public required string TargetLanguage { get; set; } |
| 69 | + public required string Error { get; set; } |
| 70 | +} |
| 71 | + |
| 72 | +public class TranslationJobStatus |
| 73 | +{ |
| 74 | + public required string JobId { get; set; } |
| 75 | + public JobStatus Status { get; set; } |
| 76 | + public int Progress { get; set; } |
| 77 | + public string? Message { get; set; } |
| 78 | + public List<TranslatedDocument> CompletedDocuments { get; set; } = new(); |
| 79 | + public List<FailedDocument> FailedDocuments { get; set; } = new(); |
| 80 | + public int TotalDocuments { get; set; } |
| 81 | + public long TotalCharacterCharged { get; set; } |
| 82 | + public DateTime CreatedAt { get; set; } |
| 83 | + public DateTime? CompletedAt { get; set; } |
| 84 | +} |
| 85 | + |
| 86 | +public class ProcessingJob |
| 87 | +{ |
| 88 | + public required string JobId { get; set; } |
| 89 | + public required string SiteUrl { get; set; } |
| 90 | + public required List<DocumentInfo> Documents { get; set; } |
| 91 | + public required TranslationOptions Options { get; set; } |
| 92 | + public RequestContext? Context { get; set; } |
| 93 | + public JobStatus Status { get; set; } |
| 94 | + public int Progress { get; set; } |
| 95 | + public string? Message { get; set; } |
| 96 | + public List<TranslatedDocument> CompletedDocuments { get; set; } = new(); |
| 97 | + public List<FailedDocument> FailedDocuments { get; set; } = new(); |
| 98 | + public int TotalDocuments { get; set; } |
| 99 | + public long TotalCharacterCharged { get; set; } |
| 100 | + public DateTime CreatedAt { get; set; } |
| 101 | + public DateTime? CompletedAt { get; set; } |
| 102 | + public string? ErrorMessage { get; set; } |
| 103 | + public string? UserAccessToken { get; set; } // Store user token for On-Behalf-Of flow |
| 104 | + public string? AzureTranslationJobId { get; set; } // Azure Document Translation API job ID |
| 105 | + public int RetryCount { get; set; } = 0; |
| 106 | + public int MaxRetries { get; set; } = 3; |
| 107 | +} |
| 108 | + |
| 109 | +public class DocumentContent |
| 110 | +{ |
| 111 | + public required string FileName { get; set; } |
| 112 | + public required byte[] Bytes { get; set; } |
| 113 | + public required string FileType { get; set; } |
| 114 | + public required string ContentType { get; set; } |
| 115 | +} |
| 116 | + |
| 117 | +// Azure Document Translation API Models |
| 118 | +public class AzureTranslationBatchRequest |
| 119 | +{ |
| 120 | + public required List<AzureTranslationInput> Inputs { get; set; } |
| 121 | +} |
| 122 | + |
| 123 | +public class AzureTranslationInput |
| 124 | +{ |
| 125 | + public required AzureTranslationSource Source { get; set; } |
| 126 | + public required List<AzureTranslationTarget> Targets { get; set; } |
| 127 | +} |
| 128 | + |
| 129 | +public class AzureTranslationSource |
| 130 | +{ |
| 131 | + public required string SourceUrl { get; set; } |
| 132 | + public string? Language { get; set; } // Optional for auto-detect |
| 133 | + public string StorageSource { get; set; } = "AzureBlob"; |
| 134 | +} |
| 135 | + |
| 136 | +public class AzureTranslationTarget |
| 137 | +{ |
| 138 | + public required string TargetUrl { get; set; } |
| 139 | + public required string Language { get; set; } |
| 140 | + public string StorageSource { get; set; } = "AzureBlob"; |
| 141 | +} |
| 142 | + |
| 143 | +public class AzureTranslationBatchResponse |
| 144 | +{ |
| 145 | + public required string Id { get; set; } |
| 146 | + public required DateTime CreatedDateTimeUtc { get; set; } |
| 147 | + public required DateTime LastActionDateTimeUtc { get; set; } |
| 148 | + public required string Status { get; set; } |
| 149 | + public required AzureTranslationSummary Summary { get; set; } |
| 150 | +} |
| 151 | + |
| 152 | +public class AzureTranslationSummary |
| 153 | +{ |
| 154 | + public int Total { get; set; } |
| 155 | + public int Failed { get; set; } |
| 156 | + public int Success { get; set; } |
| 157 | + public int InProgress { get; set; } |
| 158 | + public int NotYetStarted { get; set; } |
| 159 | + public int Cancelled { get; set; } |
| 160 | + public long TotalCharacterCharged { get; set; } |
| 161 | +} |
| 162 | + |
| 163 | +public class AzureBlobItem |
| 164 | +{ |
| 165 | + public required string Name { get; set; } |
| 166 | + public required MemoryStream Stream { get; set; } |
| 167 | + public required string Url { get; set; } |
| 168 | +} |
| 169 | + |
| 170 | +public class DocumentTranslationJobStatus |
| 171 | +{ |
| 172 | + public string JobId { get; set; } = string.Empty; |
| 173 | + public string Status { get; set; } = string.Empty; |
| 174 | + public DateTime CreatedDateTime { get; set; } |
| 175 | + public DateTime LastUpdatedDateTime { get; set; } |
| 176 | + public string? ExpirationDateTime { get; set; } |
| 177 | + public List<DocumentTranslationResult> Results { get; set; } = new(); |
| 178 | + public List<DocumentTranslationError> Errors { get; set; } = new(); |
| 179 | + |
| 180 | + public long TotalCharacterCharged { get; set; } |
| 181 | + |
| 182 | + // Task summary information |
| 183 | + public int TasksCompleted { get; set; } |
| 184 | + public int TasksFailed { get; set; } |
| 185 | + public int TasksInProgress { get; set; } |
| 186 | + public int TasksTotal { get; set; } |
| 187 | + |
| 188 | + // Top-level error information (for ValidationFailed status) |
| 189 | + public string? ErrorCode { get; set; } |
| 190 | + public string? ErrorMessage { get; set; } |
| 191 | + public string? ErrorTarget { get; set; } |
| 192 | + |
| 193 | +} |
| 194 | + |
| 195 | +public class DocumentTranslationResult |
| 196 | +{ |
| 197 | + public required string DocumentId { get; set; } |
| 198 | + public required string Status { get; set; } |
| 199 | + public string? Path { get; set; } |
| 200 | + public string? TranslatedDocumentLocation { get; set; } |
| 201 | +} |
| 202 | + |
| 203 | +public class AppInfo |
| 204 | +{ |
| 205 | + public required string ClientId { get; set; } |
| 206 | + public required string ClientSecret { get; set; } |
| 207 | +} |
| 208 | + |
| 209 | +// Configuration Models |
| 210 | +public class TranslationConfiguration |
| 211 | +{ |
| 212 | + public int MaxFileSizeBytes { get; set; } = 40 * 1024 * 1024; // 40MB (Azure limit) |
| 213 | + public int MaxDocumentsPerJob { get; set; } = 50; |
| 214 | + public int JobTimeoutMinutes { get; set; } = 60; |
| 215 | + public List<string> SupportedFileTypes { get; set; } = new() |
| 216 | + { |
| 217 | + ".docx", ".xlsx", ".pptx", ".pdf", ".html", ".htm", |
| 218 | + ".txt", ".md", ".msg", ".odt", ".ods", ".odp" |
| 219 | + }; |
| 220 | + public string SourceContainerName { get; set; } = "translation-source"; |
| 221 | + public string TargetContainerPrefix { get; set; } = "translation-target-"; |
| 222 | + public bool DeleteBlobsAfterProcessing { get; set; } = true; |
| 223 | + public int BlobSasExpiryHours { get; set; } = 2; |
| 224 | + public int StatusPollingIntervalSeconds { get; set; } = 5; |
| 225 | +} |
| 226 | + |
| 227 | +/// <summary> |
| 228 | +/// Represents an error that occurred during document translation. |
| 229 | +/// </summary> |
| 230 | +public class DocumentTranslationError |
| 231 | +{ |
| 232 | + public string Code { get; set; } = string.Empty; |
| 233 | + public string Message { get; set; } = string.Empty; |
| 234 | + public string? Target { get; set; } |
| 235 | +} |
0 commit comments