Class
InMemoryDocumentRepositoryBase<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:

cs-api-definition
public abstract class InMemoryDocumentRepositoryBase<TDocument> where TDocument : class

Inheritance: objectInMemoryDocumentRepositoryBase<TDocument>

Derived Classes: InMemoryFixedDocumentRepositoryInMemoryFlowDocumentRepositoryInMemoryWorkbookRepository

Constructors

InMemoryDocumentRepositoryBase(TimeSpan?)

Initializes a new instance with no documents.

Declaration

cs-api-definition
protected InMemoryDocumentRepositoryBase(TimeSpan? importTimeout)

Parameters

importTimeout

TimeSpan?

Timeout for import operations, or null to allow unlimited time.

Fields

currentDocumentId

The ID of the currently active document.

Declaration

cs-api-definition
protected string currentDocumentId

Field Value

string

documentInfos

Storage for document metadata keyed by document ID.

Declaration

cs-api-definition
protected readonly Dictionary<string, DocumentInfo> documentInfos

Field Value

Dictionary<string, DocumentInfo>

documents

Storage for documents keyed by document ID.

Declaration

cs-api-definition
protected readonly Dictionary<string, TDocument> documents

Field Value

Dictionary<string, TDocument>

importTimeout

The timeout for import operations, or null for no timeout.

Declaration

cs-api-definition
protected readonly TimeSpan? importTimeout

Field Value

TimeSpan?

Properties

DefaultFormat

Gets the default format for documents created by this repository.

Declaration

cs-api-definition
protected abstract DocumentFormat DefaultFormat { get; }

Property Value

DocumentFormat

DefaultNewDocumentBaseName

Gets the default base name for newly created documents.

Declaration

cs-api-definition
protected abstract string DefaultNewDocumentBaseName { get; }

Property Value

string

DocumentType

Gets the document type managed by this repository.

Declaration

cs-api-definition
public abstract DocumentType DocumentType { get; }

Property Value

DocumentType

SupportsCreation

Declaration

cs-api-definition
public bool SupportsCreation { get; }

Property Value

bool

SupportsMultipleDocuments

Declaration

cs-api-definition
public bool SupportsMultipleDocuments { get; }

Property Value

bool

Methods

Clear()

Removes all documents from the repository.

Declaration

cs-api-definition
public void Clear()

GenerateUniqueId(string)

Generates a unique document ID, appending a numeric suffix if needed.

Declaration

cs-api-definition
protected string GenerateUniqueId(string baseName)

Parameters

baseName

string

The base name for the ID.

Returns

string

A unique document ID.

GetDocument(string)

Gets a document by its ID, or the current document if no ID is specified.

Declaration

cs-api-definition
public TDocument GetDocument(string documentId = null)

Parameters

documentId

string

The document ID, or null to get the current document.

Returns

TDocument

The requested document.

Exceptions

InvalidOperationException

No document ID specified and no current document is set.

KeyNotFoundException

The specified document ID was not found.

GetDocumentAsObject(string)

Declaration

cs-api-definition
public object GetDocumentAsObject(string documentId = null)

Parameters

documentId

string

Returns

object

ListDocuments()

Declaration

cs-api-definition
public IEnumerable<DocumentInfo> ListDocuments()

Returns

IEnumerable<DocumentInfo>

RemoveDocument(string)

Removes a document from the repository.

Declaration

cs-api-definition
public bool RemoveDocument(string documentId)

Parameters

documentId

string

The identifier of the document to remove.

Returns

bool

True if the document was removed; false if not found.

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

cs-api-definition
protected string ResolveDocumentId(string documentId, string defaultBaseName, string paramName = "documentId")

Parameters

documentId

string

The document ID to validate, or null/empty for auto-generation.

defaultBaseName

string

The base name to use when generating a new ID.

paramName

string

The parameter name for exception messages.

Returns

string

The validated or generated document ID.

StoreDocument(string, TDocument, string, DocumentFormat)

Stores a document and its metadata in the repository.

Declaration

cs-api-definition
protected void StoreDocument(string documentId, TDocument document, string name, DocumentFormat format)

Parameters

documentId

string

The document ID.

document

TDocument

The document to store.

name

string

The display name for the document.

format

DocumentFormat

The document format.