Table of Contents

Class TranslationHelper

Namespace
CMS.DataEngine
Assembly
CMS.DataEngine.dll

Class to provide objects translation interface ID - CodeName.

public class TranslationHelper
Inheritance
object
TranslationHelper
Extension Methods

Constructors

TranslationHelper()

Constructor.

public TranslationHelper()

TranslationHelper(DataTable)

Constructor. Creates the helper initialized with given translation table.

public TranslationHelper(DataTable dt)

Parameters

dt DataTable

Source 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

IDataConnection

Properties

EventLogService

Service responsible for logging events.

public IEventLogService EventLogService { get; }

Property Value

IEventLogService

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

objectType string

Object type

oldId int

Old ID

newId int

New 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

objectIDs IList<int>

Existing IDs

objectType string

Object type

Returns

IList<int>

GetDefaultValue(string)

Gets default value.

public int GetDefaultValue(string objectType)

Parameters

objectType string

Object type

Returns

int

Exceptions

ArgumentException

When provided objectType is 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

parameters TranslationParameters

Parameters 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

parameters GetIDParameters

Get ID parameters

objectType string

Object 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

parameters TranslationParameters

translation 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

objectType string

Object type

oldId int

Old ID

codeNameColumn string

Code name column of the class

parentIdColumn string

Parent ID column

useDefaultValue bool

Indicates 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

objectType string

Object type

Returns

string

GetRecord(TranslationParameters)

Gets the record specified by parameters.

public DataRow GetRecord(TranslationParameters parameters)

Parameters

parameters TranslationParameters

Parameters 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

objectType string

Object type

id int

ID

Returns

DataRow

GetSafeClassName(string)

Gets the safe class name.

public static string GetSafeClassName(string className)

Parameters

className string

Class name

Returns

string

GetTranslationsXml(bool)

Gets the translations XML

public string GetTranslationsXml(bool includeRoot)

Parameters

includeRoot bool

If 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

infoObject BaseInfo

Object 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

id int

Object ID

parameters TranslationParameters

Translation 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

objectIDs IList<int>

IDs to register

objectType string

Object type of the target objects

excludedNames string[]

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

dataTable DataTable

Table with the records

objectType string

Object type of the target objects

idColumnName string

Name of the column where object IDs are stored

excludedNames string[]

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

objectType string

Object type of the target objects

objectIDs IList<int>

List of IDs to register

excludedNames string[]

Excluded object names

RemoveDefaultValue(string)

Removes default value.

public void RemoveDefaultValue(string objectType)

Parameters

objectType string

Object type

SetDefaultValue(string, int)

Sets default value.

public void SetDefaultValue(string objectType, int defaultValue)

Parameters

objectType string

Object type

defaultValue int

Default value