Example #1
0
        // VATRP-1271: Liz E. - condense this down and use the JSON handler that we already have
        public static ACEConfig createConfigFromURL(string url, string userName, string password)
        {
            //ACEConfig defaultval = defaultConfig();
            IFeedbackThread feedbackThread = HockeyClient.Current.CreateFeedbackThread();
            string          stacktrace     = null;

            try
            {
                ACEConfig aceConfig = JsonWebRequest.MakeJsonWebRequestAuthenticated <ACEConfig>(url, userName, password);
                // aceConfig should never be null at this point - throwing JsonException in a failure event. If it is null, there is a problem -
                //    but let's log it and handle it
                if (aceConfig == null)
                {
                    aceConfig = JsonWebRequest.MakeHttpJsonWebRequest <ACEConfig>(url); // cjm-sep17
                    if (aceConfig == null)
                    {
                        aceConfig = JsonFactoryConfig.defaultConfig(ACEConfigStatusType.UNKNOWN);
                    }
                }
                else
                {
                    aceConfig.configStatus = ACEConfigStatusType.LOGIN_SUCCEESSFUL;
                }
                aceConfig.NormalizeValues();
                return(aceConfig);
            }
            catch (JsonException ex)
            {
                // Once the codes that are sent back from the server are managed we can manage them here. For now, look
                //   for unauthorized in the message string as we know that this is returned currently.
                if ((ex.InnerException != null) && !string.IsNullOrEmpty(ex.InnerException.Message) &&
                    ex.InnerException.Message.ToLower().Contains("unauthorized"))
                {
                    ACEConfig config = JsonFactoryConfig.defaultConfig(ACEConfigStatusType.LOGIN_UNAUTHORIZED);
                    config.NormalizeValues();
                    return(config);
                }
                else
                {
                    ACEConfig config;
                    switch (ex.jsonExceptionType)
                    {
                    case JsonExceptionType.DESERIALIZATION_FAILED: config = JsonFactoryConfig.defaultConfig(ACEConfigStatusType.UNABLE_TO_PARSE);
                        break;

                    case JsonExceptionType.CONNECTION_FAILED: config = JsonFactoryConfig.defaultConfig(ACEConfigStatusType.CONNECTION_FAILED);
                        break;

                    default:
                        config = JsonFactoryConfig.defaultConfig(ACEConfigStatusType.UNKNOWN);
                        break;
                    }
                    config.NormalizeValues();
                    return(config);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                stacktrace = ex.StackTrace;
                ACEConfig config = JsonFactoryConfig.defaultConfig(ACEConfigStatusType.UNKNOWN);
                config.NormalizeValues();
                return(config);
            }

            if ((feedbackThread != null) && !string.IsNullOrEmpty(stacktrace))
            {
                feedbackThread.PostFeedbackMessageAsync(url + "\n\n" + stacktrace, "*****@*****.**", "json failed to deseralized", "Ace Logcat");
            }
            // note - this may be an invalid login - need to look for the correct unauthorized response assuming that there is one.
            //  Otherwise the app will use null response for now to assume unauthorized
            ACEConfig defaultConfig = JsonFactoryConfig.defaultConfig(ACEConfigStatusType.SRV_RECORD_NOT_FOUND);

            defaultConfig.NormalizeValues();
            return(defaultConfig);
        }