Class TranslationHelper
- Namespace
- CMS.DataEngine
- Assembly
- CMS.DataEngine.dll
Class to provide objects translation interface ID - CodeName.
public class TranslationHelper
- Inheritance
-
objectTranslationHelper
- Extension Methods
Constructors
TranslationHelper()
Constructor.
public TranslationHelper()
TranslationHelper(DataTable)
Constructor. Creates the helper initialized with given translation table.
public TranslationHelper(DataTable dt)
Parameters
dtDataTableSource data table
Fields
AUTO_PARENTID
Automatic parent ID.
public const int AUTO_PARENTID = -1
Field Value
- int
QUERY_OBJECT_TYPE_COLUMN
Name of the computed column that contains (real) object type of current row. Column is used in data query obtaining code names and other information based on ID and object type. Requested object type can differ from real object type when original and related object types are defined.
public const string QUERY_OBJECT_TYPE_COLUMN = "CMS_TH_T"
Field Value
- string
RECORD_CLASS_NAME_COLUMN
Name of column with object's class name identifier in a record's System.Data.DataRow.
public const string RECORD_CLASS_NAME_COLUMN = "ClassName"
Field Value
- string
RECORD_CODE_NAME_COLUMN
Name of column with object's code name in a record's System.Data.DataRow.
public const string RECORD_CODE_NAME_COLUMN = "CodeName"
Field Value
- string
RECORD_GUID_COLUMN
Name of column with object's GUID in a record's System.Data.DataRow.
public const string RECORD_GUID_COLUMN = "GUID"
Field Value
- string
RECORD_ID_COLUMN
Name of column with object's identifier in a record's System.Data.DataRow.
public const string RECORD_ID_COLUMN = "ID"
Field Value
- string
RECORD_OBJECT_TYPE_COLUMN
Name of column with object's class name in a record's System.Data.DataRow.
public const string RECORD_OBJECT_TYPE_COLUMN = "ObjectType"
Field Value
- string
RECORD_PARENT_ID_COLUMN
Name of column with object's parent identifier in a record System.Data.DataRow.
public const string RECORD_PARENT_ID_COLUMN = "ParentID"
Field Value
- string
TRANSLATION_TABLE
Name of translation table
public const string TRANSLATION_TABLE = "ObjectTranslation"
Field Value
- string
mConnection
Connection object used to access data.
protected IDataConnection mConnection
Field Value
Properties
EventLogService
Service responsible for logging events.
public IEventLogService EventLogService { get; }
Property Value
IDConversion
ID conversion table [objectType.ToLowerInvariant()] -> hash table [OldID -> NewID]
public Hashtable IDConversion { get; }
Property Value
- Hashtable
TranslationTable
Returns the translation table.
public DataTable TranslationTable { get; }
Property Value
- DataTable
UseDisplayNameAsCodeName
If true, display name is used instead of the code name.
public bool UseDisplayNameAsCodeName { get; set; }
Property Value
- bool
Methods
AddIDTranslation(string, int, int)
Adds the ID translation to the translation table.
public void AddIDTranslation(string objectType, int oldId, int newId)
Parameters
objectTypestringObject type
oldIdintOld ID
newIdintNew ID
Clear()
Clears the translation table.
public virtual void Clear()
FilterExistingRecords(IList<int>, string)
Filters the existing records from the given array.
public IList<int> FilterExistingRecords(IList<int> objectIDs, string objectType)
Parameters
objectIDsIList<int>Existing IDs
objectTypestringObject type
Returns
- IList<int>
GetDefaultValue(string)
Gets default value.
public int GetDefaultValue(string objectType)
Parameters
objectTypestringObject type
Returns
- int
Exceptions
- ArgumentException
When provided
objectTypeis null or empty.
GetEmptyTable()
Returns empty translation table.
public static DataTable GetEmptyTable()
Returns
- DataTable
GetID(TranslationParameters)
Returns the object ID for specified record.
public int GetID(TranslationParameters parameters)
Parameters
parametersTranslationParametersParameters used to select record
Returns
- int
Remarks
Object's Guid has priority over code name. However, if there is System.Guid.Empty provided as Guid, only CodeName will be used to identify object.
GetIDFromDB(GetIDParameters, string)
Gets the object ID from the database.
public static int GetIDFromDB(GetIDParameters parameters, string objectType)
Parameters
parametersGetIDParametersGet ID parameters
objectTypestringObject type
Returns
- int
GetIDWithFallback(TranslationParameters)
Returns the object ID for specified record calling GetID(TranslationParameters). If record could not be found, method falls back to GetIDFromDB(GetIDParameters, string) and eventually registers DB object in the helper. If neither attempt results into valid object ID, 0 is returned.
public int GetIDWithFallback(TranslationParameters parameters)
Parameters
parametersTranslationParameterstranslation parameters.
Returns
- int
Remarks
Object's Guid has priority over code name. However, if there is System.Guid.Empty provided as Guid, only CodeName will be used to identify object.
The TranslationTable property contains data records that correspond with the database. For translation records identified using partially correct parameters (either the code name or GUID is different than the value in the database), the actual values are loaded from the database for all fields. An index key referencing the correct data is then created from the partial parameters. The index key is used to obtain the record in future calls.
GetNewID(string, int, string, string, bool)
Gets the new ID for given old ID.
public int GetNewID(string objectType, int oldId, string codeNameColumn, string parentIdColumn, bool useDefaultValue = true)
Parameters
objectTypestringObject type
oldIdintOld ID
codeNameColumnstringCode name column of the class
parentIdColumnstringParent ID column
useDefaultValueboolIndicates if default value should be used for ID
Returns
- int
GetParentType(string)
Gets the parent object type for specified object type.
public static string GetParentType(string objectType)
Parameters
objectTypestringObject type
Returns
- string
GetRecord(TranslationParameters)
Gets the record specified by parameters.
public DataRow GetRecord(TranslationParameters parameters)
Parameters
parametersTranslationParametersParameters used to obtain the record.
Returns
- DataRow
Remarks
Object's Guid has priority over code name. However, if there is System.Guid.Empty provided as Guid, only CodeName will be used to identify object.
GetRecord(string, int)
Gets the record by ID.
public DataRow GetRecord(string objectType, int id)
Parameters
objectTypestringObject type
idintID
Returns
- DataRow
GetSafeClassName(string)
Gets the safe class name.
public static string GetSafeClassName(string className)
Parameters
classNamestringClass name
Returns
- string
GetTranslationsXml(bool)
Gets the translations XML
public string GetTranslationsXml(bool includeRoot)
Parameters
includeRootboolIf true, the root node is included
Returns
- string
RegisterRecord(BaseInfo)
Registers the record for object ID within given translation table.
public void RegisterRecord(BaseInfo infoObject)
Parameters
infoObjectBaseInfoObject instance for which the object ID will be registered.
Remarks
If there was already a record registered for the given object and the parameters are different, the old record is replaced with the new values.
RegisterRecord(int, TranslationParameters)
Registers the record within given translation table.
public void RegisterRecord(int id, TranslationParameters parameters)
Parameters
idintObject ID
parametersTranslationParametersTranslation record values
Remarks
If there was already a record registered for the given object with id and the parameters are different,
the old record is replaced with the new values.
RegisterRecords(IList<int>, string, string[])
Registers the records from the given list.
public void RegisterRecords(IList<int> objectIDs, string objectType, string[] excludedNames = null)
Parameters
objectIDsIList<int>IDs to register
objectTypestringObject type of the target objects
excludedNamesstring[]Excluded object names
RegisterRecords(DataTable, string, string, string[])
Registers the records from the given table.
public void RegisterRecords(DataTable dataTable, string objectType, string idColumnName, string[] excludedNames = null)
Parameters
dataTableDataTableTable with the records
objectTypestringObject type of the target objects
idColumnNamestringName of the column where object IDs are stored
excludedNamesstring[]Excluded object names
RegisterRecords(string, IList<int>, string[])
Registers the records from the given ID list.
public void RegisterRecords(string objectType, IList<int> objectIDs, string[] excludedNames)
Parameters
objectTypestringObject type of the target objects
objectIDsIList<int>List of IDs to register
excludedNamesstring[]Excluded object names
RemoveDefaultValue(string)
Removes default value.
public void RemoveDefaultValue(string objectType)
Parameters
objectTypestringObject type
SetDefaultValue(string, int)
Sets default value.
public void SetDefaultValue(string objectType, int defaultValue)
Parameters
objectTypestringObject type
defaultValueintDefault value