using System;
using System.Collections.Generic;
using CMS.CMSHelper;
using CMS.DataCom;
using CMS.EventLog;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
using CMS.UIControls;
///
/// A control that displays Data.com company details.
///
public partial class CMSModules_ContactManagement_Controls_UI_DataCom_Company : CMSAdminControl
{
#region "Inner classes"
///
/// Represents a Data.com company attribute name/display value pair.
///
public class RepeaterDataItem
{
///
/// A Data.com company attribute name.
///
public string AttributeName;
///
/// A Data.com company attribute display value.
///
public string AttributeValue;
}
#endregion
#region "Variables"
///
/// The Data.com company to display.
///
private Company mCompany;
#endregion
#region "Properties"
///
/// Gets or sets the Data.com company to display.
///
public Company Company
{
get
{
return mCompany;
}
set
{
mCompany = value;
}
}
#endregion
#region "Life cycle events"
protected override void OnPreRender(EventArgs e)
{
if (Company != 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 company, and returns it.
///
/// A list of localized attribute name/display value pairs for the specified Data.com company.
private List CreateDataSource()
{
IDataComConfiguration configuration = DataComHelper.GetConfiguration(CMSContext.CurrentSiteID);
IEntityAttributeFormatter formatter = DataComHelper.GetEntityAttributeFormatter();
List items = new List();
EntityInfo entityInfo = DataComHelper.GetCompanyEntityInfo(configuration);
IEntityAttributeMapperFactory entityAttributeFactory = DataComHelper.GetCompanyAttributeMapperFactory();
foreach (EntityAttributeInfo entityAttributeInfo in entityInfo.Items)
{
string entityAttributeValue = String.Empty;
EntityAttributeMapperBase entityAttribute = entityAttributeFactory.CreateEntityAttributeMapper(entityAttributeInfo.Name, entityInfo);
if (entityAttribute != null)
{
entityAttributeValue = entityAttribute.GetEntityAttributeDisplayValue(Company, 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", "CompanyControl", exception);
}
#endregion
}