private async Task <IBitbucketClient> CreateBitbucketClient(GitCredentials gitCredentials)
        {
            var credentials = new Credentials(gitCredentials.Login, gitCredentials.Password);

            if (!gitCredentials.IsEnterprise)
            {
                return(await _bitbucketClientFactory.CreateStandardBitBucketClient(credentials));
            }
            else
            {
                return(await _bitbucketClientFactory.CreateEnterpriseBitBucketClient(gitCredentials.Host, credentials));
            }
        }
 private async Task GitClientLogin(Result <ConnectionData> result)
 {
     if (result.IsSuccess && result.Data.IsLoggedIn)
     {
         try
         {
             var cred = new GitCredentials()
             {
                 Login        = result.Data.UserName,
                 Password     = result.Data.Password,
                 Host         = result.Data.Host,
                 IsEnterprise = result.Data.IsEnterprise
             };
             await _gitClient.LoginAsync(cred);
         }
         catch (Exception ex)
         {
             Logger.Warn("Couldn't login user using stored credentials. Credentials must have been changed or there is no internet connection", ex);
         }
     }
 }
        public async Task LoginAsync(GitCredentials gitCredentials)
        {
            if (IsConnected)
            {
                return;
            }

            OnConnectionChanged(new ConnectionData()
            {
                IsLoggingIn = true
            });

            if (string.IsNullOrEmpty(gitCredentials.Login) ||
                string.IsNullOrEmpty(gitCredentials.Password))
            {
                throw new Exception("Credentials fields cannot be empty");
            }

            ConnectionData connectionData = ConnectionData.NotLogged;

            try
            {
                connectionData = new ConnectionData()
                {
                    Password     = gitCredentials.Password,
                    Host         = gitCredentials.Host,
                    IsEnterprise = gitCredentials.IsEnterprise,
                    IsLoggingIn  = false
                };
                Client = await CreateBitbucketClient(gitCredentials);

                connectionData.UserName   = Client.ApiConnection.Credentials.Login;
                connectionData.Id         = Client.ApiConnection.Credentials.AccountId;
                connectionData.IsLoggedIn = true;
            }
            finally
            {
                OnConnectionChanged(connectionData);
            }
        }
Beispiel #4
0
 internal void Copy(GitCredentials gitCredentials)
 {
     entries.AddRange(gitCredentials.Select(e => new GitCredential(e)));
 }
 public async Task ChangeUserAsync(GitCredentials credentials)
 {
     Client = null;
     await LoginAsync(credentials);
 }