コード例 #1
0
        private async void LoginOrSearch()
        {
            try
            {
                var loggedIn = await QuandlConfig.ApiKeyValid();

                Dispatcher.Invoke(() =>
                {
                    if (loggedIn)
                    {
                        foreach (UIElement child in currentStepGrid.Children)
                        {
                            child.Visibility = Visibility.Visible;
                        }

                        ChangeToCurrentStep();
                    }
                    else
                    {
                        var loginXaml = new Uri("../Settings/Login.xaml", UriKind.Relative);
                        stepFrame.NavigationUIVisibility = NavigationUIVisibility.Hidden;
                        stepFrame.Source = loginXaml;
                        currentStepGrid.Children[0].Visibility = Visibility.Collapsed;
                        currentStepGrid.Children[2].Visibility = Visibility.Collapsed;
                    }
                    Focus();
                });
            }
            catch (Exception exp)
            {
                MainLogic.Instance.UpdateStatusBar(exp);
                Logger.log(exp);
            }
        }
コード例 #2
0
 private async void ValideKey()
 {
     try
     {
         await QuandlConfig.ApiKeyValid();
     }
     catch (Exception exp)
     {
         Globals.ThisAddIn.UpdateStatusBar(exp);
         Logger.log(exp);
     }
 }
コード例 #3
0
        private async void loginButton_click(object sender, RoutedEventArgs e)
        {
            loginForm.IsEnabled   = false;
            errorLabel.Visibility = Visibility.Hidden;

            try
            {
                // save this to config
                if (!string.IsNullOrWhiteSpace(apiKey.Text))
                {
                    var key = apiKey.Text.Trim();
                    if (await QuandlConfig.ApiKeyValid(key))
                    {
                        QuandlConfig.ApiKey = key;
                        MainLogic.Instance.TaskPaneUpdater.Hide <WizardGuideControlHost>();
                    }
                    else
                    {
                        DisplayErrorMessage(Properties.Resources.SettingsInValidApiKey);
                    }
                }
                else if (!string.IsNullOrWhiteSpace(email.Text) && !string.IsNullOrWhiteSpace(password.Password))
                {
                    QuandlConfig.AuthenticateWithCredentials(new Web(), email.Text.Trim(), password.Password.Trim());
                    MainLogic.Instance.TaskPaneUpdater.Hide <WizardGuideControlHost>();
                }
                else
                {
                    DisplayErrorMessage(Properties.Resources.SettingsIncorrectUsernameOrPassword);
                }
            }
            catch (QuandlErrorBase exp)
            {
                if (exp.StatusCode == HttpStatusCode.BadRequest)
                {
                    DisplayErrorMessage(Properties.Resources.SettingsIncorrectCredentials);
                }
                else
                {
                    DisplayErrorMessage(Properties.Resources.SettingsSomethingWrongTryLater);
                }
            }
            catch (Exception exp)
            {
                DisplayErrorMessage(Properties.Resources.SettingsIncorrectUsernameOrPassword);
                MainLogic.Instance.UpdateStatusBar(exp);
                // For debug purposes only. This should not make it to production.

                Logger.log(exp);
            }
        }
コード例 #4
0
        public void Cleanup()
        {
            try
            {
                QuandlConfig.Reset();
            }
            catch (ArgumentException)
            {
                // Exception message: Cannot delete a subkey tree because the subkey does not exist.
                // do nothing if key not exist
            }

            Assert.That(null, Is.Null);
        }
コード例 #5
0
 async Task ValidateApiKey(string apiKey)
 {
     if (await QuandlConfig.ApiKeyValid(apiKey))
     {
         Dispatcher.Invoke(() => {
             SaveSettings(apiKey);
             Close();
         });
     }
     else
     {
         DisplayErrorMessage(Properties.Resources.InvalidApiKeyEntered);
     }
 }
コード例 #6
0
        public void AuthenticateWithCredentialsTest()
        {
            Mock <Web> webMock  = new Mock <Web>();
            var        obj      = new { user = new { account = "account", password = "******" } };
            var        payload  = JsonConvert.SerializeObject(obj);
            JObject    userJson = JObject.Parse(@"{'user': {'api_key': 'api_key'}}");

            webMock.Setup(w => w.Authenticate(payload)).Returns(userJson);
            try
            {
                QuandlConfig.AuthenticateWithCredentials(webMock.Object, "account", "password");
            }
            catch (NullReferenceException e)
            {
                Assert.Fail("QuandlConfig.AuthenticateWithCredentials should not throw exception:" + e.Message);
            }
        }
コード例 #7
0
        public WizardGuide()
        {
            InitializeComponent();

            // Wait for the UI thread to become idle before rendering. Not this can have disastrous performance implications if used incorrectly.
            Dispatcher.Invoke(new System.Action(() => { }), DispatcherPriority.ContextIdle, null);

            // async check that the user is logged in our not
            Loaded += async delegate
            {
                PrepareFormEvents();
                try
                {
                    var validKey = await QuandlConfig.ApiKeyValid();

                    LoginOrSearch();
                }
                catch (Exception exp)
                {
                    MainLogic.Instance.UpdateStatusBar(exp);
                    Logger.log(exp);
                }
            };
        }
コード例 #8
0
 public void TestQuandlConfigResetSettings()
 {
     QuandlConfig.ApiKey = "foo";
     QuandlConfig.Reset();
     Assert.IsNull(QuandlConfig.ApiKey);
 }
コード例 #9
0
 public void Cleanup()
 {
     QuandlConfig.Reset();
 }