๐ Documentation: TempDocumentData.cs
Assembly: IrbyImaging.DomainClasses
Author: kvamshi
Created: 01-11-2022
Last Modified: 06-14-2022
๐ Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Domain Model:
TempDocumentData
3.1. Class Declaration & Mapping
3.2. Property Reference Table - Usage Examples
4.1. Creating & Saving Entities
4.2. Retrieving & Processing - UML Class Diagram
- Best Practices & Considerations
- Conclusion
๐ Overview & Purpose
The TempDocumentData class is a domain entity used to temporarily store page-level document information during scanning, OCR processing, indexing, and classification within the Irby Imaging pipeline. Each instance typically represents a single page of a multi-page document, providing:
- ๐ File metadata (e.g., name, content type)
- ๐ Binary data (original image, OCRโprocessed image)
- ๐ Extracted text (OCR)
- ๐ท๏ธ Indexing & classification flags
This design allows asynchronous, fine-grained operations on document pages before moving them to a permanent store.
๐ฆ Dependencies & Technologies
- .NET 6+ / .NET Framework (compatible)
- Entity Framework / Entity Framework Core
System.ComponentModel.DataAnnotationsfor EF mappingSystemnamespaces for core types (e.g.,Guid,DateTime)
Note: The
ImagingTypeproperty references an enum defined elsewhere in theIrbyImaging.DomainClassesassembly.
๐ Domain Model: TempDocumentData
3.1 Class Declaration & Mapping
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace IrbyImaging.DomainClasses
{
[Table("TempDocumentData", Schema = "irby")]
public class TempDocumentData
{
[Key]
public Guid TempDocumentDataId { get; set; }
// ... other properties ...
}
}
[Table("TempDocumentData", Schema = "irby")]
Maps the class to theirby.TempDocumentDatatable.[Key] public Guid TempDocumentDataId
Defines a GUID primary key.
3.2 Property Reference Table
| Property | Type | Description |
|---|---|---|
| TempDocumentDataId | Guid |
๐ Primary key for the temp record. |
| FileName | string |
๐ Original file name (e.g., document.pdf). |
| ContentType | string |
๐ฆ MIME type (e.g., application/pdf, image/png). |
| TotalPages | int |
๐ข Total number of pages in the document. |
| Page | int |
๐ข Zeroโbased or oneโbased page index. |
| ImageContents | byte[] |
๐ท Binary of the page image. |
| ImageOCRContents | byte[] |
๐ท Binary of the OCRโprocessed image (e.g., deskewed, deskinned). |
| ImageOCRText | string |
๐ Extracted OCR text for the page. |
| ReferenceId | Guid |
๐ Foreign key to the main document or parent entity. |
| BatchId | Guid |
๐๏ธ Identifier for the upload/scan batch. |
| IsIndexed | bool |
โ Indicates if the page has been indexed in the search engine. |
| DocumentUploadedBy | string |
๐ค Username or system that uploaded the document. |
| DocumentUploadedDate | DateTime |
๐ Timestamp of the upload. |
| IsLegalDocument | bool |
โ๏ธ Classification flag: legal. |
| IsSafety | bool |
๐ฆบ Classification flag: safety. |
| IsIT | bool |
๐ป Classification flag: IT. |
| ImagingType | enum |
๐ Document type (defined by ImagingType enum). |
| IsHR | bool |
๐ฅ Classification flag: HR. |
| IsAccounting | bool |
๐ฐ Classification flag: accounting. |
| IsBidding | bool |
๐ Classification flag: bidding/procurement. |
| IndexTag | string |
๐ท๏ธ Custom tag used for indexing or categorization. |
| IsDeleted | bool |
๐๏ธ Softโdelete flag. |
| BlobDataId | Guid? |
(Optional) FK to a BlobData entity (commented out). |
โ๏ธ Usage Examples
4.1 Creating & Saving Entities
using var context = new ImagingDbContext();
// Simulate splitting a multi-page PDF:
var fileBytes = File.ReadAllBytes("contract.pdf");
int totalPages = PdfHelper.GetPageCount(fileBytes);
for (int i = 1; i <= totalPages; i++)
{
var pageImage = PdfHelper.RenderPageToImage(fileBytes, i);
var ocrResult = OcrService.Process(pageImage);
var tempPage = new TempDocumentData
{
TempDocumentDataId = Guid.NewGuid(),
FileName = "contract.pdf",
ContentType = "application/pdf",
TotalPages = totalPages,
Page = i,
ImageContents = pageImage,
ImageOCRContents = ocrResult.ImageStream,
ImageOCRText = ocrResult.Text,
ReferenceId = documentId,
BatchId = batchId,
IsIndexed = false,
DocumentUploadedBy = userName,
DocumentUploadedDate = DateTime.UtcNow,
IsLegalDocument = true,
ImagingType = ImagingType.Document,
IndexTag = $"Contract:{documentId}",
IsDeleted = false
};
context.TempDocumentData.Add(tempPage);
}
await context.SaveChangesAsync();
4.2 Retrieving & Processing
// Fetch all un-indexed pages for a document:
var pagesToIndex = await context.TempDocumentData
.Where(td => td.ReferenceId == documentId && !td.IsIndexed)
.OrderBy(td => td.Page)
.ToListAsync();
// Build full-text index or merge OCR text:
string fullText = string.Join("\n\n", pagesToIndex.Select(p => p.ImageOCRText));
// Mark pages as indexed:
pagesToIndex.ForEach(p => p.IsIndexed = true);
await context.SaveChangesAsync();
๐ UML Class Diagram
classDiagram
class TempDocumentData {
+Guid TempDocumentDataId
+string FileName
+string ContentType
+int TotalPages
+int Page
+byte[] ImageContents
+byte[] ImageOCRContents
+string ImageOCRText
+Guid ReferenceId
+Guid BatchId
+bool IsIndexed
+string DocumentUploadedBy
+DateTime DocumentUploadedDate
+bool IsLegalDocument
+bool IsSafety
+bool IsIT
+ImagingType ImagingType
+bool IsHR
+bool IsAccounting
+bool IsBidding
+string IndexTag
+bool IsDeleted
}
๐ก Best Practices & Considerations
- Soft Deletion: Use
IsDeletedto avoid physical deletes; filter out in queries. - Batch Processing: Group inserts/updates in a single transaction for performance.
- Index Maintenance: After marking
IsIndexed = true, consider archiving or moving to a permanent table. - Concurrency: Beware of two processes indexing the same pageโuse optimistic locking if needed.
- Blob Storage: For large files, consider storing
ImageContentsin a blob store and keeping only URIs here.
๐ Conclusion
The TempDocumentData entity is the backbone of Irby Imagingโs pageโwise processing pipeline. By capturing both raw image bytes and OCR outputs alongside rich metadata and classification flags, it enables:
- ๐ค Asynchronous uploads
- ๐ Parallel processing
- ๐ Fineโgrained indexing
- ๐๏ธ Controlled migration to permanent storage
Implement this class in your EF Core/EF context, follow the usage patterns above, and extend classification or processing logic as your project demands!