예제 #1
0
        private static bool CanHandleException(ExceptionProperties exception)
        {
            if (exception.IdProperty == null || exception.IdProperty.CanRead == false)
            {
                return(false);
            }
            if (exception.MessageTemplateNameProperty == null || exception.MessageTemplateNameProperty.CanRead == false)
            {
                return(false);
            }
            if (exception.ParametersProperty == null || exception.ParametersProperty.CanRead == false)
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        public static FaultException GetClientException(Exception exception, string userLanguage)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            if (String.IsNullOrEmpty(userLanguage))
            {
                throw new ArgumentException("userLanguage");
            }

            XmlDocument exceptionXml = null;

            ClientException clientEx = exception as ClientException;

            if (clientEx != null)
            {
                exceptionXml = CreateHandledException(clientEx, clientEx.Id, clientEx.MessageTemplateName, clientEx.Parameters);
            }
            else
            {
                ExceptionProperties prop = new ExceptionProperties(exception);
                if (prop.MessageType == ExceptionMessageType.Extended && CanHandleException(prop))
                {
                    exceptionXml = CreateHandledException(prop.Source, prop.Id, prop.MessageTemplateName, prop.Parameters);
                }
                else if (prop.MessageType == ExceptionMessageType.Simple)
                {
                    exceptionXml = CreateSimpleHandledException(prop.Source);
                }
                else
                {
                    exceptionXml = CreateUnhandledException(exception);
                }
            }
            FilterLanguageMessages(userLanguage, exceptionXml);

            return(new FaultException(exceptionXml.OuterXml));
        }