using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using CMS.GlobalHelper; using CMS.SalesForce; using CMS.SettingsProvider; using CMS.UIControls; /// /// Displays errors and exceptions related to SalesForce. /// public partial class CMSModules_ContactManagement_Controls_UI_SalesForce_Error : CMSUserControl { #region "Public properties" /// /// Gets or sets the value indicating whether this control will show errors using the page messages. /// public bool MessagesEnabled { get { object enabled = ViewState["MessagesEnabled"]; return enabled == null ? false : (bool)enabled; } set { ViewState["MessagesEnabled"] = value; } } #endregion #region "Public methods" /// /// Displays the specified exception to the user. /// /// The exception to display. public void Report(Exception exception) { SalesForceException forceException = exception as SalesForceException; if (forceException != null) { DisplayError(HTMLHelper.HTMLEncode(forceException.Message)); } else { if (SettingsKeyProvider.DevelopmentMode) { DisplayError(HTMLHelper.HTMLEncode(GetString("sf.exception")), null, HTMLHelper.HTMLEncode(exception.Message ?? exception.ToString())); } else { DisplayError(HTMLHelper.HTMLEncode(GetString("sf.exception"))); } } } /// /// Displays the specified error message to the user. /// /// The error message to display. public void Report(string message) { DisplayError(HTMLHelper.HTMLEncode(message)); } /// /// Displays the specified error message and list of errors to the user. /// /// The error message to display. /// The list of errors to display. public void Report(string message, IEnumerable errorMessages) { StringBuilder builder = new StringBuilder(); if (errorMessages.Any()) { builder.Append(""); } DisplayError(HTMLHelper.HTMLEncode(message), builder.ToString(), null); } #endregion #region "Private methods" private void DisplayError(string message) { DisplayError(message, null, null); } private void DisplayError(string message, string description, string tooltip) { if (MessagesEnabled) { ShowError(message, description, tooltip); } else { HtmlGenericControl paragraph = new HtmlGenericControl("p") { InnerHtml = message }; paragraph.Attributes.Add("class", "Red"); if (!String.IsNullOrEmpty(tooltip)) { paragraph.InnerHtml = String.Format("{0}
{1}", paragraph.InnerHtml, tooltip); } Controls.Add(paragraph); if (!String.IsNullOrEmpty(description)) { Literal literal = new Literal { Text = description }; Controls.Add(literal); } } } #endregion }