ClassInMemoryDocumentRepositoryBase<TDocument>
Base class for in-memory document repositories that manage multiple documents. Provides common functionality for document storage, ID management, and metadata tracking.
Definition
Namespace:Telerik.Documents.AI.Tools.Core
Assembly:Telerik.Documents.AI.Tools.Core.dll
Type Parameters:
TDocument
The type of document managed by this repository.
Syntax:
public abstract class InMemoryDocumentRepositoryBase<TDocument> where TDocument : class
Inheritance: objectInMemoryDocumentRepositoryBase<TDocument>
Derived Classes:
Constructors
InMemoryDocumentRepositoryBase(TimeSpan?)
Initializes a new instance with no documents.
Declaration
protected InMemoryDocumentRepositoryBase(TimeSpan? importTimeout)
Parameters
importTimeout
Timeout for import operations, or null to allow unlimited time.
Fields
currentDocumentId
The ID of the currently active document.
documentInfos
Storage for document metadata keyed by document ID.
Declaration
protected readonly Dictionary<string, DocumentInfo> documentInfos
Field Value
documents
Storage for documents keyed by document ID.
Declaration
protected readonly Dictionary<string, TDocument> documents
Field Value
Dictionary<string, TDocument>
importTimeout
The timeout for import operations, or null for no timeout.
Properties
DefaultFormat
Gets the default format for documents created by this repository.
Declaration
protected abstract DocumentFormat DefaultFormat { get; }
Property Value
DefaultNewDocumentBaseName
Gets the default base name for newly created documents.
Declaration
protected abstract string DefaultNewDocumentBaseName { get; }
Property Value
DocumentType
Gets the document type managed by this repository.
Declaration
public abstract DocumentType DocumentType { get; }
Property Value
Methods
GenerateUniqueId(string)
Generates a unique document ID, appending a numeric suffix if needed.
GetDocument(string)
Gets a document by its ID, or the current document if no ID is specified.
Declaration
public TDocument GetDocument(string documentId = null)
Parameters
documentId
The document ID, or null to get the current document.
Returns
TDocument
The requested document.
Exceptions
No document ID specified and no current document is set.
The specified document ID was not found.
ListDocuments()
Declaration
public IEnumerable<DocumentInfo> ListDocuments()
Returns
RemoveDocument(string)
Removes a document from the repository.
ResolveDocumentId(string, string, string)
Resolves and validates a document ID according to Option 3 rules:
- If null/empty, generates a unique ID using the provided base name
- If provided and already exists, throws ArgumentException
- If provided and unique, returns it as-is
Declaration
protected string ResolveDocumentId(string documentId, string defaultBaseName, string paramName = "documentId")
Parameters
documentId
The document ID to validate, or null/empty for auto-generation.
defaultBaseName
The base name to use when generating a new ID.
paramName
The parameter name for exception messages.
Returns
The validated or generated document ID.
StoreDocument(string, TDocument, string, DocumentFormat)
Stores a document and its metadata in the repository.
Declaration
protected void StoreDocument(string documentId, TDocument document, string name, DocumentFormat format)
Parameters
documentId
The document ID.
document
TDocument
The document to store.
name
The display name for the document.
format
The document format.