private string _text; // NOTE: message or format text

        #endregion Fields

        #region Constructors

        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        public MessageDescription(string format, Link link, IList<MessageObjectContext> objects)
        {
            Debug.Assert(!string.IsNullOrEmpty(format));
            _text = format;
            _link = link;

            _objects = objects;
        }
 internal MessageDetail(MessageType type, string format, Link link, params DataObject[] args)
 {
     _Initialize(type, link, format, args);
 }
 public MessageDetail(MessageType type, string text, Link link)
 {
     _Initialize(type, text, link);
 }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        private Link _InitializeHelpLink(string helpLink)
        {
            Link link = null;
            if (!string.IsNullOrEmpty(helpLink))
            {
                string linkCaption = (string)App.Current.FindResource("MessageDetailsHelpLinkCaption");
                link = new Link(linkCaption, helpLink, LinkType.Url);
            }

            return link;
        }
        private void _Initialize(MessageType type, Link link, string format, params DataObject[] args)
        {
            Debug.Assert(!string.IsNullOrEmpty(format));

            List <MessageObjectContext> objects = null;
            if (null != args)
            {
                if (0 < args.Length)
                {
                    objects = new List<MessageObjectContext>(args.Length);
                    for (int i = 0; i < args.Length; ++i)
                        objects.Add(new MessageObjectContext(args[i]));
                }
            }

            _type = type;
            _description = new MessageDescription(format, link, objects);
        }
        private void _Initialize(MessageType type, string text, Link link)
        {
            Debug.Assert(!string.IsNullOrEmpty(text));

            _type = type;
            _description = new MessageDescription(text, link, null);
        }
        /// <summary>
        /// Shows license error with the specified message format.
        /// </summary>
        /// <param name="messageFormat">Message format to be used for showing error.</param>
        private void _ShowLicenseError(string messageFormat)
        {
            var linkText = _application.FindString("LicenseSubscriptionPage");
            var link = new Link(
                linkText,
                Licenser.Instance.UpgradeLicenseURL,
                LinkType.Url);

            _application.Messenger.AddMessage(
                MessageType.Warning,
                messageFormat,
                link);
        }
        /// <summary>
        /// Reports error occured due to failure of the specified service.
        /// </summary>
        /// <param name="service">The name of the failed service.</param>
        /// <param name="exception">The exception occured during reports building.</param>
        private void _ReportServiceError(string service, Exception exception)
        {
            Debug.Assert(exception != null);
            Debug.Assert(service != null);

            Logger.Error(exception);

            Link link = null;
            string message = string.Empty;
            if (exception is AuthenticationException || exception is CommunicationException)
            {
                message = SendRoutesHelper.AddServiceMessageWithDetail(service, exception);

                if (exception is AuthenticationException)
                {
                    link = new Link((string)_app.FindResource("LicencePanelText"),
                       ESRI.ArcLogistics.App.Pages.PagePaths.LicensePagePath,
                       ESRI.ArcLogistics.App.LinkType.Page);
                }
            }
            else
                message = Properties.Resources.UnknownError;

            var details = new List<MessageDetail>() { new MessageDetail(MessageType.Error, message, link) };
            _app.Messenger.AddError(Properties.Resources.SendingFailedMessage, details);
        }
        /// <summary>
        /// Handles the specified exception by adding corresponding message to
        /// the application messenger object.
        /// </summary>
        /// <param name="exceptionToHandle">The reference to the exception
        /// object to be handled.</param>
        /// <param name="serviceName">Name of service which caused exception.</param>
        /// <returns>True if the exception was handled and need not to
        /// be rethrown.</returns>
        public bool HandleException(Exception exceptionToHandle, string serviceName)
        {
            Debug.Assert(exceptionToHandle != null);
            Debug.Assert(serviceName != null);

            if (_IsItUriError(exceptionToHandle))
            {
                // Don't show error message if URL error already occured.
                if (!_isUriExceptionOccured)
                {
                    Logger.Error(exceptionToHandle);

                    string message =
                        (string)App.Current.FindResource(SOME_SERVICE_URI_ERROR_MESSAGE);

                    _application.Messenger.AddError(message);

                    _isUriExceptionOccured = true;
                }

                return true;
            }
            else if (exceptionToHandle is CommunicationException)
            {
                // Handle Communication exception.
                string serviceMsg =
                    CommonHelpers.FormatServiceCommunicationError(serviceName,
                    exceptionToHandle as CommunicationException);

                App.Current.Messenger.AddMessage(MessageType.Error, serviceMsg);

                return true;
            }
            else if (exceptionToHandle is AuthenticationException)
            {
                // Handle Authentication exception.
                var exAuthentication = exceptionToHandle as AuthenticationException;

                string errorMessage =
                    App.Current.GetString(SERVICE_AUTH_ERROR_MESSAGE,
                    serviceName, exAuthentication.ServiceName);

                var link = new Link(App.Current.FindString(LICENSE_PANEL_NAME),
                    Pages.PagePaths.LicensePagePath, LinkType.Page);

                App.Current.Messenger.AddMessage(
                    MessageType.Error, errorMessage, link);

                return true;
            }
            else
            {
                // Do nothing.
            }

            return false;
        }
        /// <summary>
        /// Process sending route
        /// </summary>
        /// <param name="route">Sent route</param>
        /// <param name="details">Results message details</param>
        /// <param name="selectedPropertyNames">Names of selected properties</param>
        /// <returns>True if successfully sent</returns>
        private bool _ProcessSendedRouteConfig(Route route, IList<MessageDetail> details,
            IList<string> selectedPropertyNames, ref GrfExportResult exportResult)
        {
            bool result = false;
            Link link = null;
            string message = string.Empty;
            try
            {
                message = _DoSend(route, selectedPropertyNames, ref exportResult);
                result = true;
            }
            catch (SettingsException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                    route.Name, ex.Message);
            }
            catch (IOException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                    route.Name, ex.Message);
            }
            catch (InvalidOperationException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                    route.Name, ex.Message);
            }
            catch (UnauthorizedAccessException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                    route.Name, ex.Message);
            }
            catch (SmtpException ex)
            {
                Logger.Error(ex);
                string innerMessage = Properties.Resources.MailConnectionError;
                message = string.Format(Properties.Resources.SendingFailed,
                    route.Name, innerMessage);
            }
            catch (MailerSettingsException ex)
            {
                Logger.Error(ex);
                message = string.Format(Properties.Resources.SendingFailed,
                    route.Name, ex.Message);

                link = new Link(Properties.Resources.ExportToNavigatorLink,
                                     ExportToNavigatorPreferencesPagePath, LinkType.Page);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                if (ex is AuthenticationException || ex is CommunicationException)
                {
                    string service = (string)_app.FindResource("ServiceNameRouting");
                    message = AddServiceMessageWithDetail(service, ex);

                    if (ex is AuthenticationException)
                    {
                        link = new Link((string)_app.FindResource("LicencePanelText"),
                           ESRI.ArcLogistics.App.Pages.PagePaths.LicensePagePath, LinkType.Page);
                    }
                }
                else
                {
                    string innerMessage = Properties.Resources.UnknownError;
                    message = string.Format(Properties.Resources.SendingFailed,
                        route.Name, innerMessage);
                }
            }

            MessageDetail messageDetail;

            // If route sent successfully - add information details
            // If route was not sent - add error details
            if (result)
            {
                messageDetail = new MessageDetail(MessageType.Information, message);
            }
            else
            {
                if (link == null)
                {
                    messageDetail = new MessageDetail(MessageType.Error, message);
                }
                else
                {
                    messageDetail = new MessageDetail(MessageType.Error, message, link);
                }
            }

            details.Add(messageDetail);

            return result;
        }
        /// <summary>
        /// Helper function - convert Link class to visual element Hyperlink.
        /// </summary>
        public static Hyperlink CreateHiperlink(Link link)
        {
            Hyperlink hyperlink = null;
            if (null != link && !string.IsNullOrEmpty(link.Text) && !string.IsNullOrEmpty(link.LinkRef))
            {
                hyperlink = new Hyperlink(new Run(link.Text));
                switch (link.Type)
                {
                    case LinkType.Page:
                        hyperlink.Command = new NavigationCommandSimple(link.LinkRef);
                        break;

                    case LinkType.Url:
                        hyperlink.Command = new HelpLinkCommand(link.LinkRef);
                        break;

                    default:
                        System.Diagnostics.Debug.Assert(false); // NOTE: not supported
                        break;
                }
            }

            return hyperlink;
        }