Exemplo n.º 1
0
        /// <summary>
        /// Translate an exception into an error message
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static WebPublishMessage ExceptionToErrorMessage(Exception e)
        {
            // parse out extended error info for use in error message construction
            string message = e.Message;

            if (e is SiteDestinationException && (e as SiteDestinationException).DestinationExtendedMessage != null)
            {
                message = (e as SiteDestinationException).DestinationExtendedMessage;
            }
            else if (e.InnerException != null)
            {
                message = e.InnerException.Message;
            }
            else
            {
                message = e.Message;
            }

            // trace for diagnostics
            Trace.WriteLine(e.ToString());

            // re-throw the exception so we can do normal processing
            try
            {
                throw e;
            }
            catch (LoginException)
            {
                return(new WebPublishMessage(MessageId.LoginFailed));
            }
            catch (NoSuchDirectoryException ex)
            {
                WebPublishMessage msg = new WebPublishMessage(MessageId.NoSuchPublishFolder, ex.Path);
                return(msg);
            }
            catch (SiteDestinationException ex)
            {
                if (ex.DestinationErrorCode == ERROR_INTERNET.NAME_NOT_RESOLVED)
                {
                    return(new WebPublishMessage(MessageId.InvalidHostname));
                }
                else if (ex.DestinationErrorCode == ERROR_INTERNET.CANNOT_CONNECT)
                {
                    return(new WebPublishMessage(MessageId.FtpServerUnavailable));
                }
                else if (ex.DestinationErrorCode == ERROR_INTERNET.TIMEOUT)
                {
                    return(new WebPublishMessage(MessageId.ConnectionTimeout));
                }
                else
                {
                    return(new WebPublishMessage(MessageId.PublishFailed, message));
                }
            }
            catch (Exception)
            {
                return(new WebPublishMessage(MessageId.PublishFailed, message));
            }
        }
        /// <summary>
        /// Translate an exception into an error message
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static WebPublishMessage ExceptionToErrorMessage(Exception e)
        {
            // parse out extended error info for use in error message construction
            string message = e.Message;
            if (e is SiteDestinationException && (e as SiteDestinationException).DestinationExtendedMessage != null)
            {
                message = (e as SiteDestinationException).DestinationExtendedMessage;
            }
            else if (e.InnerException != null)
            {
                message = e.InnerException.Message;
            }
            else
            {
                message = e.Message;
            }

            // trace for diagnostics
            Trace.WriteLine(e.ToString());

            // re-throw the exception so we can do normal processing
            try
            {
                throw e;
            }
            catch (LoginException)
            {
                return new WebPublishMessage(MessageId.LoginFailed);
            }
            catch (NoSuchDirectoryException ex)
            {
                WebPublishMessage msg = new WebPublishMessage(MessageId.NoSuchPublishFolder, ex.Path);
                return msg;
            }
            catch (SiteDestinationException ex)
            {
                if (ex.DestinationErrorCode == ERROR_INTERNET.NAME_NOT_RESOLVED)
                {
                    return new WebPublishMessage(MessageId.InvalidHostname);
                }
                else if (ex.DestinationErrorCode == ERROR_INTERNET.CANNOT_CONNECT)
                {
                    return new WebPublishMessage(MessageId.FtpServerUnavailable);
                }
                else if (ex.DestinationErrorCode == ERROR_INTERNET.TIMEOUT)
                {
                    return new WebPublishMessage(MessageId.ConnectionTimeout);
                }
                else
                {
                    return new WebPublishMessage(MessageId.PublishFailed, message);
                }
            }
            catch (Exception)
            {
                return new WebPublishMessage(MessageId.PublishFailed, message);
            }
        }