Esempio n. 1
0
        private static HttpStatusCode GetHttpStatusCode(DSSException e)
        {
            switch (e.GetType().Name)
            {
            case "UnsupportedLanguageException": return(HttpStatusCode.BadRequest);

            case "UnrecognizedTraitCriterionException": return(HttpStatusCode.BadRequest);

            case "UnrecognizedScopingEntityException": return(HttpStatusCode.BadRequest);

            case "UnrecognizedScopedEntityException": return(HttpStatusCode.BadRequest);

            case "UnrecognizedLanguageException": return(HttpStatusCode.BadRequest);

            case "RequiredDataNotProvidedException": return(HttpStatusCode.BadRequest);

            case "InvalidTimeZoneOffsetException": return(HttpStatusCode.BadRequest);

            case "InvalidDataFormatException": return(HttpStatusCode.BadRequest);

            case "InvalidTraitCriterionDataFormatException": return(HttpStatusCode.BadRequest);

            case "InvalidDriDataFormatException": return(HttpStatusCode.BadRequest);

            case "EvaluationException": return(HttpStatusCode.InternalServerError);

            case "DSSRuntimeException": return(HttpStatusCode.InternalServerError);

            default: return(HttpStatusCode.InternalServerError);
            }
        }
Esempio n. 2
0
        public static HttpResponseMessage ToHttpResponseMessage(this DSSException e)
        {
            var rm = new HttpResponseMessage(GetHttpStatusCode(e));

            rm.Content = new StringContent(e.SerializeToString(), Encoding.Unicode, "application/xml");

            return(rm);
        }
        /// <summary>
        /// Constructs a new instance of the DSSExceptionWrapper.
        /// </summary>
        /// <param name="exception">The DSSException instance to be wrapped.</param>
        /// <param name="innerException">An optional inner exception.</param>
        public DSSExceptionWrapper(DSSException exception, Exception innerException) : base(exception.GetMessage(), innerException)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            Exception = exception;
        }
        /// <summary>
        /// Converts the errorMessage property of a DSSException to a single string for use as the message of a C# exception.
        /// </summary>
        /// <param name="exception">The DSSException containing the message.</param>
        /// <returns>A single string containing the concatenated list of messages in the given exception, separated by carriage-return;line-feed characters.</returns>
        public static string GetMessage(this DSSException exception)
        {
            if (exception.errorMessage == null)
            {
                return(null);
            }

            return(String.Join("\r\n", exception.errorMessage));
        }
Esempio n. 5
0
        public static string SerializeToString(this DSSException e)
        {
            var serializer = new XmlSerializer(e.GetType());

            var sb = new StringBuilder();

            using (var writer = new StringWriter(sb))
            {
                serializer.Serialize(writer, e);
            }

            return(sb.ToString());
        }
 /// <summary>
 /// Constructs a new instance of the DSSExceptionWrapper.
 /// </summary>
 /// <param name="exception">The DSSException instance to be wrapped.</param>
 public DSSExceptionWrapper(DSSException exception) : this(exception, null)
 {
 }