Table of Contents

Class AbstractInfoProvider<TInfo, TProvider, TQuery>

Namespace
CMS.DataEngine
Assembly
CMS.DataEngine.dll

Abstract info class provider.

public abstract class AbstractInfoProvider<TInfo, TProvider, TQuery> : IInfoProvider, ICustomizableProvider, IBulkOperationProvider, IWebFarmProvider, IInfoValidator<TInfo> where TInfo : AbstractInfoBase<TInfo>, new() where TProvider : AbstractInfoProvider<TInfo, TProvider, TQuery> where TQuery : ObjectQueryBase<TQuery, TInfo>, new()

Type Parameters

TInfo
TProvider
TQuery
Inheritance
object
AbstractInfoProvider<TInfo, TProvider, TQuery>
Implements
Derived
Extension Methods

Constructors

AbstractInfoProvider(ObjectTypeInfo)

Initializes a new instance of the AbstractInfoProvider<TInfo, TProvider, TQuery> class using the typeInfo provided.

protected AbstractInfoProvider(ObjectTypeInfo typeInfo)

Parameters

typeInfo ObjectTypeInfo

Object type information.

Remarks

Associate the InfoCacheAttribute with TInfo to configure the info cache. If not configured, default settings with UseWeakReferences set to true are used.

AbstractInfoProvider(bool)

Initializes a new instance of the AbstractInfoProvider<TInfo, TProvider, TQuery> class.

protected AbstractInfoProvider(bool initialize)

Parameters

initialize bool

Indicates if provider together with hashtables should be initialized.

Remarks

Associate the InfoCacheAttribute with TInfo to configure the info cache. If not configured, default settings with UseWeakReferences set to true are used.

Fields

infos

Info tables.

protected readonly CMSStatic<ProviderDictionaryCollection> infos

Field Value

CMSStatic<ProviderDictionaryCollection>

Remarks

This API supports the framework infrastructure and is not intended to be used directly from your code.

Properties

DataSource

Data source for the provider

public DataQuerySource DataSource { get; set; }

Property Value

DataQuerySource

HashtableSettings

Gets hashtable settings

public HashtableSettings HashtableSettings { get; }

Property Value

HashtableSettings

InfoObject

Info object instance the provider is working with.

protected TInfo InfoObject { get; set; }

Property Value

TInfo

InvalidCodenameErrorMessageKey

Resource key name used to indicate an invalid codename.

protected virtual string InvalidCodenameErrorMessageKey { get; }

Property Value

string

IsValid

Indicates if the provider instance is up-to-date and can be used to manage object instances.

public virtual bool IsValid { get; }

Property Value

bool

ProviderObject

Gets or sets the provider instance.

Since the providers are managed by IoC container, setting the provider instance must be performed before the IoC container initialization finishes (i.e. during application pre-initialization).

public static TProvider ProviderObject { get; set; }

Property Value

TProvider

Remarks

In unit testing scenarios where IoC container is not available the Fake<TInfo, TProvider>(new TestingProvider()); method must be used to set the provider instance.

TypeInfo

Object type information.

public ObjectTypeInfo TypeInfo { get; protected set; }

Property Value

ObjectTypeInfo

Methods

BeginTransaction()

Creates a new transaction over this provider.

protected ITransactionScope BeginTransaction()

Returns

ITransactionScope

BulkDelete(IWhereCondition, BulkDeleteSettings)

Bulk deletes info objects based on the given condition.

public void BulkDelete(IWhereCondition where, BulkDeleteSettings settings = null)

Parameters

where IWhereCondition

Where condition for the objects which should be deleted.

settings BulkDeleteSettings

Configuration settings

Remarks

Note that the delete process of individual object types within dependencies does not run within transaction. If it fails, some data may be cleared and not rolled back. If you require transaction, wrap the call of this method to CMSTransactionScope.

Method is not executing any customizations for remove dependencies routine (custom code in RemoveObjectDependencies(bool, bool) or 'removedependencies' query). All customizations must be called prior this method or handled within BulkDelete event.

Exceptions

InvalidOperationException

Thrown when ObjectType cannot be deleted by current provider.

BulkInsertInfos(IEnumerable<BaseInfo>)

Bulk inserts the given list of info objects

public void BulkInsertInfos(IEnumerable<BaseInfo> objects)

Parameters

objects IEnumerable<BaseInfo>

List of objects

Remarks

Info object ID is not set during the bulk insert operation

BulkInsertInfos(IEnumerable<TInfo>, BulkInsertSettings)

Bulk inserts the given list of info objects.

public void BulkInsertInfos(IEnumerable<TInfo> objects, BulkInsertSettings settings = null)

Parameters

objects IEnumerable<TInfo>

List of objects

settings BulkInsertSettings

Configuration for the bulk insert, e.g. timeout. If null, default configuration is used.

Remarks

Info object ID is not set during the bulk insert operation.

CheckObject(TInfo)

Checks if the given info object is not null. Throws an exception if it is.

protected static void CheckObject(TInfo info)

Parameters

info TInfo

Info object to check

CheckUniqueCodeName(TInfo)

Checks if the object has unique code name. Returns true if the object has unique code name.

public virtual bool CheckUniqueCodeName(TInfo infoObj)

Parameters

infoObj TInfo

Info object to check

Returns

bool

ClearHashtables(bool)

Clears the object's hashtables.

protected virtual void ClearHashtables(bool logTasks)

Parameters

logTasks bool

If true, web farm tasks are logged

CreateDefaultBulkInsertSettings()

Creates bulk insert settings. By default Microsoft.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints and Microsoft.Data.SqlClient.SqlBulkCopyOptions.TableLock flags are set.

protected virtual BulkInsertSettings CreateDefaultBulkInsertSettings()

Returns

BulkInsertSettings

CreateInfo(DataRow, bool)

Creates a new info object.

protected virtual TInfo CreateInfo(DataRow dr = null, bool useGenerator = true)

Parameters

dr DataRow

Data to use to create new object

useGenerator bool

If true, the process allows using the generator to differentiate between particular info types based on data

Returns

TInfo

CreateWebFarmTask(string, string)

Creates web farm task specific for current object and action name

public virtual void CreateWebFarmTask(string actionName, string data)

Parameters

actionName string

Action name

data string

Custom task data

CreateWebFarmTask(string, string, byte[], string)

Creates web farm task specific for current object and action name

public virtual void CreateWebFarmTask(string actionName, string data, byte[] binary, string filePath)

Parameters

actionName string

Action name

data string

Custom task data

binary byte[]

Binary value

filePath string

File path

DeleteInfo(TInfo)

Deletes the object from the database.

protected virtual void DeleteInfo(TInfo info)

Parameters

info TInfo

Object to delete.

DeleteInfoAsync(TInfo, CancellationToken)

Deletes the object from the database.

protected virtual Task DeleteInfoAsync(TInfo info, CancellationToken cancellationToken)

Parameters

info TInfo

Object to delete.

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task

DeleteObjectFromHashtables(TInfo)

Deletes the object instance from the hashtables.

protected virtual void DeleteObjectFromHashtables(TInfo info)

Parameters

info TInfo

Object to delete

Exceptions

ArgumentNullException

When info is null

GetDeleteQuery()

Gets the object query that deletes all items matching the query parameters

protected TQuery GetDeleteQuery()

Returns

TQuery

GetInfoByCodeName(string, bool)

Gets an instance of info object based on the given code name.

protected virtual TInfo GetInfoByCodeName(string codeName, bool useHashtable = true)

Parameters

codeName string

Code name

useHashtable bool

If true, the object is taken through the hashtable

Returns

TInfo

GetInfoByCodeNameAsync(string, bool, CancellationToken)

Asynchronously gets an instance of info object based on the given code name.

protected virtual Task<TInfo> GetInfoByCodeNameAsync(string codeName, bool useHashtable, CancellationToken cancellationToken)

Parameters

codeName string

Code name

useHashtable bool

If true, the object is taken through the hashtable

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<TInfo>

GetInfoByFullName(string, bool)

Gets an instance of info object based on the given full name.

protected virtual TInfo GetInfoByFullName(string fullName, bool useHashtable = true)

Parameters

fullName string

Full name to get the info object by.

useHashtable bool

Indicates whether the info object can be retrieved from the hashtable cache.

Returns

TInfo

GetInfoByGuid(Guid, bool)

Gets an instance of info object based on the given GUID.

protected virtual TInfo GetInfoByGuid(Guid guid, bool useHashtable = true)

Parameters

guid Guid

Object GUID

useHashtable bool

If true, the object is taken through the hashtable

Returns

TInfo

GetInfoByGuidAsync(Guid, bool, CancellationToken)

Asynchronously gets an instance of info object based on the given GUID.

protected virtual Task<TInfo> GetInfoByGuidAsync(Guid guid, bool useHashtable, CancellationToken cancellationToken)

Parameters

guid Guid

Object GUID

useHashtable bool

If true, the object is taken through the hashtable

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<TInfo>

GetInfoById(int, bool)

Gets an instance of info object based on ID.

protected virtual TInfo GetInfoById(int id, bool useHashtable = true)

Parameters

id int

Value of the record ID to look for

useHashtable bool

If true, the object is taken through the hashtable

Returns

TInfo

GetInfoByIdAsync(int, bool, CancellationToken)

Asynchronously gets an instance of info object based on ID.

protected virtual Task<TInfo> GetInfoByIdAsync(int id, bool useHashtable, CancellationToken cancellationToken)

Parameters

id int

Value of the record ID to look for

useHashtable bool

If true, the object is taken through the hashtable

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<TInfo>

GetInfosByIds(IEnumerable<int>)

Gets the list of info objects by their IDs.

protected virtual SafeDictionary<int, BaseInfo> GetInfosByIds(IEnumerable<int> ids)

Parameters

ids IEnumerable<int>

List of IDs to get

Returns

SafeDictionary<int, BaseInfo>

GetObjectQuery()

Gets the object query for the provider

protected TQuery GetObjectQuery()

Returns

TQuery

GetObjectQueryInternal()

Gets the object query for the provider

protected abstract TQuery GetObjectQueryInternal()

Returns

TQuery

Init(ObjectTypeInfo, HashtableSettings)

Initializes the provider with the given type info and hashtable settings.

protected void Init(ObjectTypeInfo typeInfo = null, HashtableSettings settings = null)

Parameters

typeInfo ObjectTypeInfo

Type info of the objects which the provider manages.

settings HashtableSettings

Hashtable settings for internal provider cache.

InitHashtableSettings(ObjectTypeInfo, HashtableSettings)

Initializes the HashtableSettings based on typeInfo and using settings as default values.

protected void InitHashtableSettings(ObjectTypeInfo typeInfo, HashtableSettings settings = null)

Parameters

typeInfo ObjectTypeInfo

Object type information.

settings HashtableSettings

Hashtable settings; if not specified the settings are initialized with UseWeakReferences set to true.

Exceptions

ArgumentNullException

Thrown when typeInfo is null.

InitTypeInfoAndRegister(ObjectTypeInfo)

Initializes the provider variables.

protected void InitTypeInfoAndRegister(ObjectTypeInfo typeInfo)

Parameters

typeInfo ObjectTypeInfo

Object type information

Invalidate()

Sets this provider as invalid

public void Invalidate()

LoadAllInfos()

Loads all infos to the hashtable

[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(27, 0)]
protected void LoadAllInfos()

LoadInfos()

Loads all objects from the database to memory.

protected void LoadInfos()

ProcessWebFarmTask(string, string, byte[])

Runs the processing of specific web farm task for current provider

public virtual void ProcessWebFarmTask(string actionName, string data, byte[] binary)

Parameters

actionName string

Action name

data string

Custom task data

binary byte[]

Binary data

ProcessWebFarmTaskInternal(string, string, byte[])

Runs the processing of specific web farm task for current provider

protected virtual void ProcessWebFarmTaskInternal(string actionName, string data, byte[] binary)

Parameters

actionName string

Action name

data string

Custom task data

binary byte[]

Binary data

RegisterObjectInHashtables(TInfo)

Registers the object instance within the hashtables.

protected virtual void RegisterObjectInHashtables(TInfo info)

Parameters

info TInfo

Object to register

RemoveOriginalCodeNameFromHashtable(TInfo)

Removes the original object code name from the hashtable

protected virtual void RemoveOriginalCodeNameFromHashtable(TInfo info)

Parameters

info TInfo

Object to remove

SetAsDefaultProvider()

Sets this provider instance as the default provider.

Since the providers are managed by IoC container, setting the provider instance must be performed before the IoC container initialization finishes (i.e. during application pre-initialization).

public void SetAsDefaultProvider()

Remarks

In unit testing scenarios where IoC container is not available the Fake<TInfo, TProvider>(new TestingProvider()); method must be used to set the provider instance.

SetInfo(TInfo)

Inserts or updates the object to the database.

protected virtual void SetInfo(TInfo info)

Parameters

info TInfo

Object to insert or update.

SetInfoAsync(TInfo, CancellationToken)

Asynchronously inserts or updates the object to the database.

protected Task SetInfoAsync(TInfo info, CancellationToken cancellationToken)

Parameters

info TInfo

Object to insert or update.

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task

UpdateData(IWhereCondition, IEnumerable<KeyValuePair<string, object>>, bool)

Updates the data in the database based on the given where condition.

[Obsolete("Use UpdateData(IEnumerable<KeyValuePair<string, object>>, IWhereCondition, bool) instead.")]
[ObsoleteSince(27, 0)]
protected virtual void UpdateData(IWhereCondition where, IEnumerable<KeyValuePair<string, object>> values, bool useAPI = false)

Parameters

where IWhereCondition

Where condition

values IEnumerable<KeyValuePair<string, object>>

New values for the data as an enumeration of column names and their corresponding values.

useAPI bool

If true, data is updated using the API. If false, with bulk update query

UpdateData(IEnumerable<KeyValuePair<string, object>>, IWhereCondition, bool)

Bulk updates info objects based on the given condition using the values provided.

protected virtual void UpdateData(IEnumerable<KeyValuePair<string, object>> values, IWhereCondition where, bool useApi = false)

Parameters

values IEnumerable<KeyValuePair<string, object>>

New values for the data as an enumeration of column names and their corresponding values.

where IWhereCondition

Where condition filtering the objects to be updated, or null.

useApi bool

Specifies whether to perform the update using the API, or using a DB query.

Exceptions

ArgumentNullException

Thrown when values is null.

UpdateData(string, QueryDataParameters, IWhereCondition)

Updates the data in the database based on the given condition using the updateExpression provided.

protected virtual void UpdateData(string updateExpression, QueryDataParameters updateParameters, IWhereCondition where)

Parameters

updateExpression string

Update expression (e.g. [Column] = [Column] * 2 or [Column] = @ParameterValue).

updateParameters QueryDataParameters

Parameters for the update expression, or null.

where IWhereCondition

Where condition filtering the objects to be updated, or null.

Remarks

Unlike the UpdateData(string, QueryDataParameters, string) method override, the updateParameters contains query data parameters for the update expression only. Where condition query data parameters must be supplied in the where itself.

It is strongly recommended to use query data parameters for specifying values for the update expression to prevent possible vulnerabilities.

Exceptions

ArgumentException

Thrown when updateExpression is null or empty.

UpdateData(string, QueryDataParameters, string)

Updates the data in the database based on the given condition using the updateExpression provided.

[Obsolete("Use UpdateData(string, QueryDataParameters, IWhereCondition) instead.")]
[ObsoleteSince(27, 0)]
protected virtual void UpdateData(string updateExpression, QueryDataParameters parameters, string where)

Parameters

updateExpression string

Update expression (e.g. [Column] = [Column] * 2 or [Column] = @ParameterValue).

parameters QueryDataParameters

Parameters for the update expression and where condition, or null.

where string

Where condition filtering the objects to be updated, or null.

UpdateObjectInHashtables(TInfo)

Updates the object instance in the hashtables. Update is different than RegisterObjectInHashtables(TInfo), because it logs task about changing object.

protected virtual void UpdateObjectInHashtables(TInfo info)

Parameters

info TInfo

Object to update

Validate(TInfo)

Validates whether the info object's state satisfies domain specific constraints and returns the validation result.

public virtual InfoValidationResult Validate(TInfo info)

Parameters

info TInfo

Info object to be validated.

Returns

InfoValidationResult

Returns validation result with IsValid set to true, if info is valid. Otherwise returns result with the flag set to false and a corresponding error message.

Remarks

Implement IInfoValidator<TInfo> and register it into the system to perform domain specific validation for TInfo. The system invokes the registered validators as part of validation performed by this method.

The default implementation validates the code name to contain only allowed characters and to be unique.

Exceptions

ArgumentNullException

Thrown when info is null.

See Also

ValidateCodeName(TInfo)

Validates the object code name. Returns true if the code name is valid.

public virtual bool ValidateCodeName(TInfo info)

Parameters

info TInfo

Object to check

Returns

bool