예제 #1
0
        /// <summary>
        /// Instantiate a Box specific exception from a given HTTP response
        /// </summary>
        /// <param name="message">The message from the SDK about what happened</param>
        /// <param name="response">The HTTP response that generated the exception</param>
        public static BoxException GetResponseException <T>(string message, IBoxResponse <T> response) where T : class
        {
            BoxError error = null;

            if (!string.IsNullOrWhiteSpace(response.ContentString))
            {
                var converter = new BoxJsonConverter();

                try
                {
                    error = converter.Parse <BoxError>(response.ContentString);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(string.Format("Unable to parse error message: {0} ({1})", response.ContentString, e.Message));
                }
            }
            var ex = new BoxException(GetErrorMessage(message, response, error))
            {
                StatusCode      = response.StatusCode,
                ResponseHeaders = response.Headers,
                Error           = error
            };

            return(ex);
        }
예제 #2
0
 public Page3()
 {
     this.InitializeComponent();
     BoxHidden.AddHandler(TappedEvent, new TappedEventHandler(AnyBox_Tapped), true);
     BoxAlpha.AddHandler(TappedEvent, new TappedEventHandler(AnyBox_Tapped), true);
     BoxEps.AddHandler(TappedEvent, new TappedEventHandler(AnyBox_Tapped), true);
     BoxError.AddHandler(TappedEvent, new TappedEventHandler(AnyBox_Tapped), true);
 }
예제 #3
0
        //-------------------------------------------------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Verification qu'un mail est valide
        /// </summary>
        /// <param name="mail"></param>
        /// <returns></returns>
        private Boolean IsMailValid(String mail)
        {
            Regex regex = new Regex(@"^([\w]{2,})@([\w]{2,})\.([\w]{2,})$");

            if (!regex.IsMatch(txtMail.Text))
            {
                BoxError.Show("Erreur adresse mail", "L'adresse mail n'est pas valide : " + txtMail.Text);
                return(false);
            }

            return(true);
        }
예제 #4
0
        protected internal static BoxError GetResponseError <T>(IBoxResponse <T> response) where T : class
        {
            BoxError error = null;

            if (!string.IsNullOrWhiteSpace(response.ContentString))
            {
                var converter = new BoxJsonConverter();

                try
                {
                    error = converter.Parse <BoxError>(response.ContentString);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(string.Format("Unable to parse error message: {0} ({1})", response.ContentString, e.Message));
                }
            }

            return(error);
        }
        /// <summary>
        /// Parses the BoxResponse with the provided converter
        /// </summary>
        /// <typeparam name="T">The return type of the Box response</typeparam>
        /// <param name="response">The response to parse</param>
        /// <param name="converter">The converter to use for the conversion</param>
        /// <returns></returns>
        public static IBoxResponse <T> ParseResults <T>(this IBoxResponse <T> response, IBoxConverter converter)
            where T : class
        {
            BoxException exToThrow = null;

            switch (response.Status)
            {
            case ResponseStatus.Success:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    response.ResponseObject = converter.Parse <T>(response.ContentString);
                }
                break;

            case ResponseStatus.Forbidden:
                var errorMsg = response.Headers.WwwAuthenticate.FirstOrDefault();
                if (errorMsg != null)
                {
                    var err = new BoxError()
                    {
                        Code = response.StatusCode.ToString(), Description = "Forbidden", Message = errorMsg.ToString()
                    };
                    throw new BoxException(err.Message, err);
                }
                else if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    response.Error = converter.Parse <BoxError>(response.ContentString);
                    throw new BoxException(response.ContentString, response.Error)
                          {
                              StatusCode = response.StatusCode
                          };
                }
                else
                {
                    throw new BoxException("Forbidden");
                }

            default:
                if (!string.IsNullOrWhiteSpace(response.ContentString))
                {
                    try
                    {
                        switch (response.StatusCode)
                        {
                        case System.Net.HttpStatusCode.Conflict:
                            if (response is IBoxResponse <BoxPreflightCheck> )
                            {
                                BoxPreflightCheckConflictError <BoxFile> err = converter.Parse <BoxPreflightCheckConflictError <BoxFile> >(response.ContentString);
                                exToThrow = new BoxPreflightCheckConflictException <BoxFile>(response.ContentString, err);
                            }
                            else
                            {
                                BoxConflictError <T> error = converter.Parse <BoxConflictError <T> >(response.ContentString);
                                exToThrow = new BoxConflictException <T>(response.ContentString, error);
                            }

                            break;

                        default:
                            response.Error = converter.Parse <BoxError>(response.ContentString);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(string.Format("Unable to parse error message: {0}", response.ContentString));
                    }

                    throw exToThrow == null ?
                          new BoxException(response.ContentString, response.Error)
                          {
                              StatusCode = response.StatusCode
                          } :
                          exToThrow;
                }
                throw new BoxException(response.ContentString)
                      {
                          StatusCode = response.StatusCode
                      };
            }
            return(response);
        }
예제 #6
0
        private static string GetErrorMessage <T>(string message, IBoxResponse <T> response, BoxError error = null) where T : class
        {
            var requestID = error?.RequestId != null?string.Format(" | {0}", error.RequestId) : "";

            IEnumerable <string> traceIDHeaders;

            if (response.Headers != null && response.Headers.TryGetValues("BOX-REQUEST-ID", out traceIDHeaders))
            {
                foreach (var id in traceIDHeaders)
                {
                    // Take the first trace ID header value (there should only be one)
                    requestID += "." + id;
                    break;
                }
            }

            var errorInfo = error?.Code != null && error?.Message != null?string.Format(" {0} - {1}", error.Code, error.Message) : "";

            return(string.Format("{0} [{1}{2}]{3}", message, response.StatusCode, requestID, errorInfo));
        }
예제 #7
0
 /// <summary>
 /// Instantiates a new BoxException with the provided message and error object
 /// </summary>
 /// <param name="message"></param>
 /// <param name="error"></param>
 public BoxException(string message, BoxError error) : base(message)
 {
     Error = error;
 }
예제 #8
0
        protected internal static string GetErrorMessage <T>(string message, IBoxResponse <T> response, BoxError error = null) where T : class
        {
            var    requestID = error?.RequestId;
            string traceID   = null;

            if (response.Headers != null && response.Headers.TryGetValues("BOX-REQUEST-ID", out IEnumerable <string> traceIDHeaders))
            {
                traceID = traceIDHeaders.FirstOrDefault();
            }

            var errorCode        = error?.Code ?? error?.Name;
            var errorDescription = error?.Message ?? error?.Description;

            var exceptionMessage = message;

            exceptionMessage += " [" + response.StatusCode;
            if (requestID != null || traceID != null)
            {
                exceptionMessage += string.Format(" | {0}.{1}", requestID, traceID);
            }
            exceptionMessage += "]";
            if (errorCode != null)
            {
                exceptionMessage += " " + errorCode;
            }
            if (errorDescription != null)
            {
                exceptionMessage += " - " + errorDescription;
            }
            return(exceptionMessage);
        }
예제 #9
0
 /// <summary>
 /// Instantiates a new BoxAPIException with the provided message and error object, status code and response headers
 /// </summary>
 /// <param name="message"></param>
 /// <param name="error"></param>
 /// <param name="statusCode"></param>
 /// <param name="responseHeaders"></param>
 protected internal BoxAPIException(string message, BoxError error, HttpStatusCode statusCode, HttpResponseHeaders responseHeaders) : base(message)
 {
     Error           = error;
     StatusCode      = statusCode;
     ResponseHeaders = responseHeaders;
 }
예제 #10
0
        private static string GetErrorMessage <T>(string message, IBoxResponse <T> response, BoxError error = null) where T : class
        {
            var requestID = error?.RequestId != null?string.Format(" | {0}", error.RequestId) : "";

            var errorInfo = error?.Code != null && error?.Message != null?string.Format(" {0} - {1}", error.Code, error.Message) : "";

            return(string.Format("{0} [{1}{2}]{3}", message, response.StatusCode, requestID, errorInfo));
        }
 /// <summary>
 /// Instantiates a new BoxSessionInvalidatedException with the provided message and error object, status code and response headers
 /// </summary>
 /// <param name="message"></param>
 /// <param name="error"></param>
 /// <param name="statusCode"></param>
 /// <param name="responseHeaders"></param>
 protected internal BoxSessionInvalidatedException(string message, BoxError error, HttpStatusCode statusCode, HttpResponseHeaders responseHeaders)
     : base(message, error, statusCode, responseHeaders)
 {
 }