public void SdkExceptionConstructorTest4()
        {
            string       errorMessage = "This is an error message.";
            SdkException target       = new SdkException(errorMessage);

            Assert.AreEqual(target.Message, errorMessage);
        }
Beispiel #2
0
        /// <summary>
        /// Processes the exception.
        /// </summary>
        /// <param name="ex">The caught exception.</param>
        /// <returns>The clear SDK exception object.</returns>
        public static SdkException ProcessException(Exception ex)
        {
            var exception = new SdkException(ex.Message);

            if (ex is WebException)
            {
                var webEx    = ex as WebException;
                var response = webEx.Response as HttpWebResponse;
                if (response != null)
                {
                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.Unauthorized:
                        exception = new SdkNotAuthorizedException();
                        break;

                    case HttpStatusCode.BadRequest:
                        exception = new SdkBadRequestException();
                        break;

                    case HttpStatusCode.NotFound:
                        exception = new SdkBadParameterException();
                        break;
                    }
                }
            }
            else if (ex is OutOfMemoryException)
            {
                exception = new SdkOutOfMemoryException();
            }

            return(exception);
        }
        public void SdkExceptionConstructorTest3()
        {
            string       message = "Sdk Exception was thrown.";
            SdkException target  = new SdkException();

            Assert.AreEqual(target.Message, message);
        }
        public void SdkExceptionConstructorTest5()
        {
            string errorMessage = "This is an error message.";

            System.Exception innerException = new ArgumentNullException();
            SdkException     target         = new SdkException(errorMessage, innerException);

            Assert.AreEqual(target.Message, errorMessage);
            Assert.ReferenceEquals(target.InnerException, innerException);
        }
        public void SdkExceptionConstructorTest()
        {
            string       errorMessage = "Unauthorized";
            string       errorCode    = "401";
            string       source       = "Intuit.Ipp.Test";
            SdkException target       = new SdkException(errorMessage, errorCode, source);

            Assert.AreEqual(target.Message, errorMessage);
            Assert.AreEqual(target.ErrorCode, errorCode);
            Assert.AreEqual(target.Source, source);
        }
        public void SdkExceptionConstructorTest1()
        {
            string errorMessage = "Unauthorized";
            string errorCode    = "401";
            string source       = "Intuit.Ipp.Test";

            System.Exception innerException = new ArgumentNullException();
            SdkException     target         = new SdkException(errorMessage, errorCode, source, innerException);

            Assert.AreEqual(target.Message, errorMessage);
            Assert.AreEqual(target.ErrorCode, errorCode);
            Assert.AreEqual(target.Source, source);
            Assert.ReferenceEquals(target.InnerException, innerException);
        }
        private void LogSdkError(SdkException e, [CallerMemberName] string memberName = "")
        {
            IEnumerable <FieldInfo> enumerable = Enumerable.Where <FieldInfo>((IEnumerable <FieldInfo>) typeof(FaceSdkErrors).GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy), (Func <FieldInfo, bool>)(fi => fi.IsLiteral && !fi.IsInitOnly));
            string str = e.ErrorCode.ToString();

            foreach (FieldInfo fieldInfo in enumerable)
            {
                if ((int)e.ErrorCode == (int)(uint)fieldInfo.GetValue((object)null))
                {
                    str = fieldInfo.Name;
                    break;
                }
            }
            this._log.ErrorFormat("Unable to {0} template Error={1}", (object)memberName, (object)str);
        }
Beispiel #8
0
        /// <summary>
        /// Prevents a default instance of the <see cref="IdentifyServiceManager" /> class from being created.
        /// </summary>
        private IdentifyServiceManager()
        {
            if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["BASE_URL"]))
            {
                String url = ConfigurationManager.AppSettings["BASE_URL"];

                if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
                {
                    SdkException sdkException = new SdkException(new common.model.SdkInternalError(Constants.INVALID_CUSTOM_BASE_URL));
                    throw sdkException;
                }


                UrlMaker.UrlStrategy.BASE_URL = ConfigurationManager.AppSettings["BASE_URL"];
            }
        }
        public void SdkExceptionConstructorTest2()
        {
            string errorMessage = "Unauthorized";
            string errorCode    = "401";
            string source       = "Intuit.Ipp.Test";

            System.Exception innerException = new ArgumentNullException();
            SdkException     target         = new SdkException(errorMessage, errorCode, source, innerException);
            SdkException     newTarget      = null;

            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, target);
                s.Position = 0; // Reset stream position
                newTarget  = (SdkException)formatter.Deserialize(s);
            }

            Assert.IsNotNull(newTarget);
            Assert.AreEqual(newTarget.Message, errorMessage);
            Assert.AreEqual(newTarget.ErrorCode, errorCode);
            Assert.AreEqual(newTarget.Source, source);
            Assert.ReferenceEquals(newTarget.InnerException, innerException);
        }
 private void ProcessError(SdkException ex)
 {
     Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("SDK error: " + ex.Message)));
 }
Beispiel #11
0
        /// <summary>
        /// Processes the API Request Object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">The URL.</param>
        /// <param name="inputaddress">inputaddress String</param>
        /// <returns>string</returns>
        public static string processAPIRequestInternal <T>(String url, String inputaddress)
        {
            String       endPoint          = String.Empty;
            String       contentTypeString = String.Empty;
            SdkException exception         = null;

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            try
            {
                String accessToken = OAuthFactory.getOAuthService().getAuthenticationToken();
                //Add xml API fragment string to complete the endpoint for xml input
                endPoint          = url + Constants.API_FRAGMENT_JSON;
                contentTypeString = "application/json;charset=utf-8";

                Uri uri = new Uri(endPoint);
                using (ExtendedWebClient client = new ExtendedWebClient())
                {
                    client.Headers.Add(HttpRequestHeader.ContentType, contentTypeString);
                    client.Headers.Add(Constants.AUTH_HEADER, accessToken);
                    client.Headers.Add(Constants.USER_AGENT, "CSharp-SDK");
                    String resp = (client.UploadString(uri, inputaddress));
                    return(resp);
                }
            }
            catch (WebException webException)
            {
                Debug.WriteLine("Got an error response from API" + webException);
                string responseText = string.Empty;
                int    statusCode   = 0;

                if (webException.Response != null)
                {
                    var responseStream = webException.Response.GetResponseStream();
                    statusCode = (int)((HttpWebResponse)webException.Response).StatusCode;

                    using (var reader = new StreamReader(responseStream))
                    {
                        responseText = reader.ReadToEnd();
                    }
                    try
                    {
                        ErrorInfo apiError;
                        apiError = serializer.Deserialize <ErrorInfo>(responseText);
                        if (apiError != null)
                        {
                            apiError.HttpStatusCode = statusCode;
                            apiError.Reason         = webException.Message;
                            apiError.Response       = responseText;
                        }
                        exception = new SdkException(apiError);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine("Unexpected Error: " + e);
                        exception = new SdkException(new SdkInternalError(Constants.ERROR_MSG_API_PROCESSING, e));
                    }
                }
                else
                {
                    Debug.WriteLine("Unexpected Error: " + webException);
                    exception = new SdkException(new SdkInternalError(Constants.ERROR_MSG_API_PROCESSING, webException));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Unexpected Error: " + e);
                exception = new SdkException(new SdkInternalError(Constants.ERROR_MSG_API_PROCESSING, e));
            }

            throw exception;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WebResponseEventArgs{T}"/> class.
 /// </summary>
 /// <param name="EventData">The event data.</param>
 /// <param name="sdkException">The SDK exception.</param>
 public WebResponseEventArgs(T EventData, SdkException sdkException)
 {
     this.ResponseObject = EventData;
     this.SDKException   = sdkException;
 }
 private void ProcessError(SdkException ex)
 {
     this.ShowMessage(ex.Message, "SDK error");
 }