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
TInfoTProviderTQuery
- Inheritance
-
objectAbstractInfoProvider<TInfo, TProvider, TQuery>
- Implements
-
IInfoValidator<TInfo>
- 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
typeInfoObjectTypeInfoObject 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
initializeboolIndicates 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
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
HashtableSettings
Gets hashtable settings
public HashtableSettings HashtableSettings { get; }
Property Value
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
Methods
BeginTransaction()
Creates a new transaction over this provider.
protected ITransactionScope BeginTransaction()
Returns
BulkDelete(IWhereCondition, BulkDeleteSettings)
Bulk deletes info objects based on the given condition.
public void BulkDelete(IWhereCondition where, BulkDeleteSettings settings = null)
Parameters
whereIWhereConditionWhere condition for the objects which should be deleted.
settingsBulkDeleteSettingsConfiguration 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
objectsIEnumerable<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
objectsIEnumerable<TInfo>List of objects
settingsBulkInsertSettingsConfiguration 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
infoTInfoInfo 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
infoObjTInfoInfo object to check
Returns
- bool
ClearHashtables(bool)
Clears the object's hashtables.
protected virtual void ClearHashtables(bool logTasks)
Parameters
logTasksboolIf 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
CreateInfo(DataRow, bool)
Creates a new info object.
protected virtual TInfo CreateInfo(DataRow dr = null, bool useGenerator = true)
Parameters
drDataRowData to use to create new object
useGeneratorboolIf 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
actionNamestringAction name
datastringCustom 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
actionNamestringAction name
datastringCustom task data
binarybyte[]Binary value
filePathstringFile path
DeleteInfo(TInfo)
Deletes the object from the database.
protected virtual void DeleteInfo(TInfo info)
Parameters
infoTInfoObject to delete.
DeleteInfoAsync(TInfo, CancellationToken)
Deletes the object from the database.
protected virtual Task DeleteInfoAsync(TInfo info, CancellationToken cancellationToken)
Parameters
infoTInfoObject to delete.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
- Task
DeleteObjectFromHashtables(TInfo)
Deletes the object instance from the hashtables.
protected virtual void DeleteObjectFromHashtables(TInfo info)
Parameters
infoTInfoObject to delete
Exceptions
- ArgumentNullException
When info is null
EnsureSystemFields(TInfo)
Ensures the system fields (GUID, name, last modified) for the object.
protected void EnsureSystemFields(TInfo info)
Parameters
infoTInfoInfo object to ensure the fields for.
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
codeNamestringCode name
useHashtableboolIf 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
codeNamestringCode name
useHashtableboolIf true, the object is taken through the hashtable
cancellationTokenCancellationTokenThe 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
fullNamestringFull name to get the info object by.
useHashtableboolIndicates 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
guidGuidObject GUID
useHashtableboolIf 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
guidGuidObject GUID
useHashtableboolIf true, the object is taken through the hashtable
cancellationTokenCancellationTokenThe 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
idintValue of the record ID to look for
useHashtableboolIf 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
idintValue of the record ID to look for
useHashtableboolIf true, the object is taken through the hashtable
cancellationTokenCancellationTokenThe 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
idsIEnumerable<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
typeInfoObjectTypeInfoType info of the objects which the provider manages.
settingsHashtableSettingsHashtable 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
typeInfoObjectTypeInfoObject type information.
settingsHashtableSettingsHashtable settings; if not specified the settings are initialized with UseWeakReferences set to
true.
Exceptions
- ArgumentNullException
Thrown when
typeInfois null.
InitTypeInfoAndRegister(ObjectTypeInfo)
Initializes the provider variables.
protected void InitTypeInfoAndRegister(ObjectTypeInfo typeInfo)
Parameters
typeInfoObjectTypeInfoObject 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.")]
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
actionNamestringAction name
datastringCustom task data
binarybyte[]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
actionNamestringAction name
datastringCustom task data
binarybyte[]Binary data
RegisterObjectInHashtables(TInfo)
Registers the object instance within the hashtables.
protected virtual void RegisterObjectInHashtables(TInfo info)
Parameters
infoTInfoObject to register
RemoveOriginalCodeNameFromHashtable(TInfo)
Removes the original object code name from the hashtable
protected virtual void RemoveOriginalCodeNameFromHashtable(TInfo info)
Parameters
infoTInfoObject 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
infoTInfoObject to insert or update.
SetInfoAsync(TInfo, CancellationToken)
Asynchronously inserts or updates the object to the database.
protected Task SetInfoAsync(TInfo info, CancellationToken cancellationToken)
Parameters
infoTInfoObject to insert or update.
cancellationTokenCancellationTokenThe 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.")]
protected virtual void UpdateData(IWhereCondition where, IEnumerable<KeyValuePair<string, object>> values, bool useAPI = false)
Parameters
whereIWhereConditionWhere condition
valuesIEnumerable<KeyValuePair<string, object>>New values for the data as an enumeration of column names and their corresponding values.
useAPIboolIf 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
valuesIEnumerable<KeyValuePair<string, object>>New values for the data as an enumeration of column names and their corresponding values.
whereIWhereConditionWhere condition filtering the objects to be updated, or null.
useApiboolSpecifies whether to perform the update using the API, or using a DB query.
Exceptions
- ArgumentNullException
Thrown when
valuesis 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
updateExpressionstringUpdate expression (e.g.
[Column] = [Column] * 2or[Column] = @ParameterValue).updateParametersQueryDataParametersParameters for the update expression, or null.
whereIWhereConditionWhere 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
updateExpressionis 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.")]
protected virtual void UpdateData(string updateExpression, QueryDataParameters parameters, string where)
Parameters
updateExpressionstringUpdate expression (e.g.
[Column] = [Column] * 2or[Column] = @ParameterValue).parametersQueryDataParametersParameters for the update expression and where condition, or null.
wherestringWhere 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
infoTInfoObject 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
infoTInfoInfo object to be validated.
Returns
- InfoValidationResult
Returns validation result with IsValid set to true, if
infois 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
infois null.
- See Also
-
IInfoValidator<TInfo>
ValidateCodeName(TInfo)
Validates the object code name. Returns true if the code name is valid.
public virtual bool ValidateCodeName(TInfo info)
Parameters
infoTInfoObject to check
Returns
- bool