๐Ÿ“ Documentation: TempDocumentData.cs

Assembly: IrbyImaging.DomainClasses
Author: kvamshi
Created: 01-11-2022
Last Modified: 06-14-2022


๐Ÿ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Domain Model: TempDocumentData
    3.1. Class Declaration & Mapping
    3.2. Property Reference Table
  4. Usage Examples
    4.1. Creating & Saving Entities
    4.2. Retrieving & Processing
  5. UML Class Diagram
  6. Best Practices & Considerations
  7. 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.DataAnnotations for EF mapping
  • System namespaces for core types (e.g., Guid, DateTime)

Note: The ImagingType property references an enum defined elsewhere in the IrbyImaging.DomainClasses assembly.


๐Ÿ› 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 the irby.TempDocumentData table.
  • [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 IsDeleted to 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 ImageContents in 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!