/// <summary>
        /// Find this istance in Static ErrorMapping
        /// </summary>
        /// <param name="_flyExceptionType">Internal Exception type</param>
        /// <returns>Founded FlyExceptionObject</returns>
        public static FlyExceptionObject Get(FlyExceptionTypeEnum _flyExceptionType)
        {
            try
            {
                if (ErrorsDescription == null)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(FlyConfiguration.ErrorDescriptionFile);
                    ErrorsDescription = XElement.Load(new XmlNodeReader(doc));
                }
                XElement err = (from el in ErrorsDescription.Elements()
                                where el.Attribute("Code").Value == _flyExceptionType.ToString()
                                select el).FirstOrDefault <XElement>();

                SdmxErrorCodeEnumType tipoErr = SdmxErrorCodeEnumType.InternalServerError;
                Enum.TryParse(err.Attribute("SdmxType").Value, true, out tipoErr);

                XElement Description = (from el in err.Elements()
                                        where el.Name == "Description" && el.Attribute("LocaleIsoCode").Value == "en"
                                        select el).FirstOrDefault <XElement>();

                return(new FlyExceptionObject(_flyExceptionType, tipoErr, (string)Description));
            }
            catch (Exception ex)
            {
                return(new FlyExceptionObject(FlyExceptionTypeEnum.InternalError, SdmxErrorCodeEnumType.InternalServerError, string.Format("No Error description configured --> Error: {0} Message: {1}", _flyExceptionType.ToString(), ex.Message)));
            }
        }
 /// <summary>
 /// Find this istance in Static SDMXExceptionList
 /// </summary>
 /// <param name="_sdmxErrorCodeEnumType">Sdmx Standard Error Type</param>
 /// <returns>Founded SDMXExceptionObject</returns>
 public static SDMXExceptionObject Get(SdmxErrorCodeEnumType _sdmxErrorCodeEnumType)
 {
     try
     {
         return(SDMXExceptionList.Find(em => em._sdmxErrorCodeEnum == _sdmxErrorCodeEnumType));
     }
     catch (Exception)
     {
         return(new SDMXExceptionObject()
         {
             _sdmxErrorCodeEnum = SdmxErrorCodeEnumType.InternalServerError, _sdmxErrorCode = 500, _sdmxErrorText = "Internal Server Error"
         });
     }
 }
Пример #3
0
        /// <summary>
        /// The is client error.
        /// </summary>
        /// <param name="errorCode">
        /// The error code.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool IsClientError(this SdmxErrorCodeEnumType errorCode)
        {
            switch (errorCode)
            {
            case SdmxErrorCodeEnumType.NoResultsFound:
            case SdmxErrorCodeEnumType.Unauthorised:
            case SdmxErrorCodeEnumType.ResponseTooLarge:
            case SdmxErrorCodeEnumType.SyntaxError:
            case SdmxErrorCodeEnumType.SemanticError:
                return(true);

            default:
                return(false);
            }
        }
        /// <summary>
        /// Invokes the service error assert.
        /// </summary>
        /// <param name="wsClient">
        /// The ws client.
        /// </param>
        /// <param name="operation">
        /// The operation.
        /// </param>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="expectedError">
        /// The expected error.
        /// </param>
        /// <param name="compress">
        /// if set to <c>true</c> [compress].
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool InvokeServiceErrorAssert(SdmxWsClient wsClient, SoapOperation operation, FileInfo request, SdmxErrorCodeEnumType expectedError, bool compress = false)
        {
            var response = new FileInfo(Path.GetTempFileName());
            try
            {
                wsClient.InvokeService(operation, request, response, compress);
            }
            catch (WebException e)
            {
                if (CheckErrorResponse(SdmxErrorCode.GetFromEnum(expectedError).ClientErrorCode, e))
                {
                    return true;
                }
            }

            response.Refresh();
            response.Delete();

            return false;
        }
 /// <summary>
 /// Build error response.
 /// </summary>
 /// <param name="errorCode">
 /// The error code.
 /// </param>
 /// <returns>
 /// The <see cref="Error"/>.
 /// </returns>
 public Error BuildErrorResponse(SdmxErrorCodeEnumType errorCode)
 {
     return this.BuildErrorResponse(SdmxErrorCode.GetFromEnum(errorCode));
 }
 /// <summary>
 /// Create FlyExceptionObject Instace
 /// </summary>
 /// <param name="_flyExceptionType">Internal Exception type</param>
 /// <param name="_sdmxErrorCodeType">SDMX Standard Error Type</param>
 /// <param name="_flyExceptionText">Additional exception description</param>
 public FlyExceptionObject(FlyExceptionTypeEnum _flyExceptionType, SdmxErrorCodeEnumType _sdmxErrorCodeType, string _flyExceptionText)
 {
     this.FlyExceptionType = _flyExceptionType;
     this.SDMXException    = SDMXExceptionObject.Get(_sdmxErrorCodeType);
     this.FlyExceptionText = _flyExceptionText;
 }