using System; using System.Collections.Generic; using CMS.DataCom; using CMS.EventLog; using CMS.GlobalHelper; using CMS.SettingsProvider; using CMS.UIControls; /// /// A control that displays Data.com contact details. /// public partial class CMSModules_ContactManagement_Controls_UI_DataCom_Contact : CMSAdminControl { #region "Inner classes" /// /// Represents a Data.com contact attribute name/display value pair. /// public class RepeaterDataItem { /// /// A Data.com contact attribute name. /// public string AttributeName; /// /// A Data.com contact attribute display value. /// public string AttributeValue; } #endregion #region "Variables" /// /// The Data.com contact to display. /// private Contact mContact; #endregion #region "Properties" /// /// Gets or sets the Data.com contact to display. /// public Contact Contact { get { return mContact; } set { mContact = value; } } #endregion #region "Life cycle methods" protected override void OnPreRender(EventArgs e) { if (Contact != null) { try { AttributeRepeater.DataSource = CreateDataSource(); AttributeRepeater.DataBind(); } catch (Exception exception) { HandleException(exception); } } base.OnPreRender(e); } #endregion #region "Private methods" /// /// Creates a list of localized attribute name/display value pairs for the specified Data.com contact, and returns it. /// /// A list of localized attribute name/display value pairs for the specified Data.com contact. private List CreateDataSource() { IEntityAttributeFormatter formatter = DataComHelper.GetEntityAttributeFormatter(); List items = new List(); EntityInfo entityInfo = DataComHelper.GetContactEntityInfo(); IEntityAttributeMapperFactory entityAttributeFactory = DataComHelper.GetContactAttributeMapperFactory(); foreach (EntityAttributeInfo entityAttributeInfo in entityInfo.Items) { string entityAttributeValue = String.Empty; EntityAttributeMapperBase entityAttribute = entityAttributeFactory.CreateEntityAttributeMapper(entityAttributeInfo.Name, entityInfo); if (entityAttribute != null) { entityAttributeValue = entityAttribute.GetEntityAttributeDisplayValue(Contact, formatter); } RepeaterDataItem item = new RepeaterDataItem() { AttributeName = ResHelper.LocalizeString(entityAttributeInfo.DisplayName), AttributeValue = entityAttributeValue }; items.Add(item); } return items; } /// /// Displays an error message and logs the specified exception to the event log. /// /// The exception to handle. private void HandleException(Exception exception) { ErrorSummary.Report(exception); EventLogProvider.LogException("Data.com Connector", "ContactControl", exception); } #endregion }