Ejemplo n.º 1
0
        /// <summary>
        /// Translate <see cref="FaultException"/> into general <see cref="Exception"/>
        /// </summary>
        /// <param name="faultException"></param>
        /// <returns></returns>
        public static Exception TranslateFaultException(FaultException <DataFault> faultException)
        {
            int errorCode = faultException.Detail.Code;

            switch (errorCode)
            {
            case DataErrorCode.DataNoPermission:
            {
                string errorMsg = SR.ResourceManager.GetString(DataErrorCode.Name(errorCode), CultureInfo.CurrentCulture);
                return(new UnauthorizedAccessException(errorMsg, faultException));
            }

            case DataErrorCode.InvalidAllowedUser:
            {
                string errorMsg = SR.ResourceManager.GetString(DataErrorCode.Name(errorCode), CultureInfo.CurrentCulture);
                return(new IdentityNotMappedException(string.Format(CultureInfo.CurrentCulture, errorMsg, faultException.Detail.Context[0] as string), faultException));
            }

            default:
                DataException e = new DataException(errorCode, faultException);
                e.DataClientId = faultException.Detail.Context[0] as string;
                e.DataServer   = faultException.Detail.Context[1] as string;
                return(e);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Map data error code to error message
        /// </summary>
        internal static string DataErrorCodeToMessage(int errorCode, string dataClientId, string dataServerAddress)
        {
            switch (errorCode)
            {
            case DataErrorCode.DataServerNoSpace:
            case DataErrorCode.DataFeatureNotSupported:
            case DataErrorCode.NoDataServerConfigured:
            case DataErrorCode.DataServerForAzureBurstMisconfigured:
            case DataErrorCode.DataClientIdInvalid:
            case DataErrorCode.DataClientDisposed:
            case DataErrorCode.ConnectDataServiceFailure:
            case DataErrorCode.ConnectDataServiceTimeout:
            case DataErrorCode.DataRetry:
                return(SR.ResourceManager.GetString(DataErrorCode.Name(errorCode), System.Globalization.CultureInfo.CurrentCulture));

            case DataErrorCode.DataClientAlreadyExists:
            case DataErrorCode.DataClientNotFound:
            case DataErrorCode.DataClientBusy:
            case DataErrorCode.DataClientBeingCreated:
            case DataErrorCode.DataClientNotWritable:
            case DataErrorCode.DataClientReadOnly:
            case DataErrorCode.DataClientLifeCycleSet:
            case DataErrorCode.DataClientDeleted:
            case DataErrorCode.DataInconsistent:
            case DataErrorCode.NoDataAvailable:
                string strMessage = SR.ResourceManager.GetString(DataErrorCode.Name(errorCode), System.Globalization.CultureInfo.CurrentCulture);
                return(string.Format(CultureInfo.CurrentCulture, strMessage, dataClientId));

            case DataErrorCode.DataServerMisconfigured:
            case DataErrorCode.DataServerUnreachable:
            case DataErrorCode.DataServerBadAddress:
                string strMessage2 = SR.ResourceManager.GetString(DataErrorCode.Name(errorCode), System.Globalization.CultureInfo.CurrentCulture);
                return(string.Format(CultureInfo.CurrentCulture, strMessage2, dataServerAddress));

            case DataErrorCode.DataServerUnsupported:
            case DataErrorCode.DataMaxSizeExceeded:
            case DataErrorCode.DataVersionUnsupported:
            case DataErrorCode.DataClientIdTooLong:
            case DataErrorCode.DataTypeMismatch:
            {
                // these error codes requires more information to build error message.
                System.Diagnostics.Debug.Assert(false, string.Format("cannot build error message for error code {0}", errorCode));
                return(SR.DataUnknownError);
            }

            default:
                return(SR.DataUnknownError);
            }
        }