Beispiel #1
0
        private void Login_Click(object sender, RoutedEventArgs e)
        {
            VSActivityLog.Info("Login button clicked");
            try
            {
                // Disable textbox passwordBox and login button
                userIdBox.IsReadOnly     = true;
                accessTokenBox.IsEnabled = false;
                logInButton.IsEnabled    = false;

                var userId      = userIdBox.Text;
                var accessToken = accessTokenBox.Password;
                var credentials = new Credentials(userId, accessToken);
                if (_authorizationManager.Login(credentials))
                {
                    VSActivityLog.Info("Logged in successfully");
                    VsUtils.DisplayInStatusBar(_serviceProvider, "Logged into QuantConnect");
                    _credentials = new Credentials(userId, accessToken);
                    Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                VsUtils.ShowMessageBox(_serviceProvider, "QuantConnect Login Exception", ex.ToString());
                VSActivityLog.Error(ex.ToString());
            }
            VsUtils.DisplayInStatusBar(_serviceProvider, "Failed to login");
            userIdBox.BorderBrush      = Brushes.Red;
            accessTokenBox.BorderBrush = Brushes.Red;
            // Re enable button and textbox
            userIdBox.IsReadOnly     = false;
            accessTokenBox.IsEnabled = true;
            logInButton.IsEnabled    = true;
        }
        /// <summary>
        /// Perform QuantConnect authentication
        /// </summary>
        /// <param name="serviceProvider">Visual Studio services provider</param>
        /// <param name="explicitLogin">User explicitly clicked Log In button</param>
        /// <param name="showLoginDialog">If true LoginDialog will be shown, careful it blocks UI</param>
        /// <returns>true if user logged into QuantConnect, false otherwise</returns>
        public async Task <bool> Login(IServiceProvider serviceProvider, bool explicitLogin, bool showLoginDialog = true)
        {
            VSActivityLog.Info("Logging in");

            var authorizationManager = AuthorizationManager.GetInstance();

            if (authorizationManager.IsLoggedIn())
            {
                VSActivityLog.Info("Already logged in");
                return(true);
            }

            var previousCredentials = CredentialsManager.GetLastCredential();

            if (!explicitLogin && await LoggedInWithLastStorredPassword(previousCredentials))
            {
                VSActivityLog.Info("Logged in with previously storred credentials");
                return(true);
            }

            if (showLoginDialog)
            {
                return(LoginWithDialog(serviceProvider, previousCredentials));
            }
            VsUtils.DisplayInStatusBar(serviceProvider, "Please login to QuantConnect");
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Create LoginDialog
        /// </summary>
        /// <param name="authorizationManager">Authorization manager</param>
        /// <param name="previousCredentials">User previous credentials</param>
        public LoginDialog(AuthorizationManager authorizationManager, Credentials?previousCredentials)
        {
            VSActivityLog.Info("Created login dialog");
            InitializeComponent();
            _authorizationManager = authorizationManager;

            DisplayPreviousCredentials(previousCredentials);
            _userIdNormalBrush      = userIdBox.BorderBrush;
            _accessTokenNormalBrush = userIdBox.BorderBrush;
        }
Beispiel #4
0
 /// <summary>
 /// Authenticate API
 /// </summary>
 /// <param name="credentials">User id and access token to authenticate the API</param>
 /// <returns>true if successfully authenticated API, false otherwise</returns>
 public bool Login(Credentials credentials)
 {
     VSActivityLog.Info("Authenticating QuantConnect API");
     try
     {
         var api = new Api.Api();
         api.Initialize(int.Parse(credentials.UserId), credentials.AccessToken, Globals.DataFolder);
         if (api.Connected)
         {
             _api = api;
             return(true);
         }
     }
     catch (FormatException)
     {
         VSActivityLog.Error("User id is not a valid number");
     }
     return(false);
 }
Beispiel #5
0
        private bool LoginWithDialog(IServiceProvider serviceProvider, Credentials?previousCredentials)
        {
            var logInDialog = new LoginDialog(AuthorizationManager.GetInstance(), previousCredentials, serviceProvider);

            VsUtils.DisplayDialogWindow(logInDialog);

            var credentials = logInDialog.GetCredentials();

            if (credentials.HasValue)
            {
                VSActivityLog.Info("Storing credentials");
                CredentialsManager.StoreCredentials(credentials.Value);
                return(true);
            }
            else
            {
                VSActivityLog.Info("Login cancelled");
                return(false);
            }
        }
Beispiel #6
0
        private void Login_Click(object sender, RoutedEventArgs e)
        {
            VSActivityLog.Info("Log in button clicked");
            logInButton.IsEnabled = false;
            var userId      = userIdBox.Text;
            var accessToken = accessTokenBox.Password;
            var credentials = new Credentials(userId, accessToken);

            if (_authorizationManager.Login(credentials))
            {
                VSActivityLog.Info("Logged in successfully");
                _credentials = new Credentials(userId, accessToken);
                Close();
            }
            else
            {
                VSActivityLog.Error("Failed to login");
                userIdBox.BorderBrush      = Brushes.Red;
                accessTokenBox.BorderBrush = Brushes.Red;
            }
            logInButton.IsEnabled = true;
        }
Beispiel #7
0
        /// <summary>
        /// Perform QuantConnect authentication
        /// </summary>
        /// <param name="serviceProvider">Visual Studio services provider</param>
        /// <param name="explicitLogin">User explicitly clicked Log In button</param>
        /// <returns>true if user logged into QuantConnect, false otherwise</returns>
        public bool Login(IServiceProvider serviceProvider, bool explicitLogin)
        {
            VSActivityLog.Info("Logging in");

            var authorizationManager = AuthorizationManager.GetInstance();

            if (authorizationManager.IsLoggedIn())
            {
                VSActivityLog.Info("Already logged in");
                return(true);
            }

            var previousCredentials = CredentialsManager.GetLastCredential();

            if (!explicitLogin && LoggedInWithLastStorredPassword(previousCredentials))
            {
                VSActivityLog.Info("Logged in with previously storred credentials");
                return(true);
            }

            return(LoginWithDialog(serviceProvider, previousCredentials));
        }
        /// <summary>
        /// Authenticate API
        /// </summary>
        /// <param name="credentials">User id and access token to authenticate the API</param>
        /// <returns>true if successfully authenticated API, false otherwise</returns>
        public async System.Threading.Tasks.Task <bool> Login(Credentials credentials)
        {
            VSActivityLog.Info("Authenticating QuantConnect API");
            try
            {
                var api = new Api.Api();
                api.Initialize(int.Parse(credentials.UserId), credentials.AccessToken, Globals.DataFolder);
                var apiConnected = await System.Threading.Tasks.Task.Run(() => api.Connected);

                if (apiConnected)
                {
                    _api = api;
                    return(true);
                }
            }
            catch (Exception exception)
            {
                VsUtils.ShowErrorMessageBox(ServiceProvider.GlobalProvider,
                                            "QuantConnect Exception", exception.ToString());
            }
            return(false);
        }