Orc.NuGetExplorer.AuthenticationProvider.GetCredentialsAsync C# (CSharp) Method

GetCredentialsAsync() public method

public GetCredentialsAsync ( Uri uri, bool previousCredentialsFailed ) : Task
uri System.Uri
previousCredentialsFailed bool
return Task
        public async Task<AuthenticationCredentials> GetCredentialsAsync(Uri uri, bool previousCredentialsFailed)
        {
            Log.Debug("Requesting credentials for '{0}'", uri);

            bool? result = null;

            var credentials = new AuthenticationCredentials(uri);

            using (_pleaseWaitInterruptService.Value.InterruptTemporarily())
            {
                await DispatchHelper.DispatchIfNecessaryAsync(() =>
                {
                    var uriString = uri.ToString().ToLower();

                    using (var scopeManager = ScopeManager<AuthenticationScope>.GetScopeManager(uriString.GetSafeScopeName(), () => new AuthenticationScope()))
                    {
                        var authenticationScope = scopeManager.ScopeObject;

                        var credentialsPrompter = new CredentialsPrompter(_configurationService)
                        {
                            Target = uriString,
                            UserName = string.Empty,
                            Password = string.Empty,
                            AllowStoredCredentials = !previousCredentialsFailed,
                            ShowSaveCheckBox = true,
                            WindowTitle = "Credentials required",
                            MainInstruction = "Credentials are required to access this feed",
                            Content = string.Format("In order to continue, please enter the credentials for {0} below.", uri),
                            IsAuthenticationRequired = authenticationScope.CanPromptForAuthentication
                        };

                        authenticationScope.HasPromptedForAuthentication = true;

                        result = credentialsPrompter.ShowDialog();
                        if (result ?? false)
                        {
                            credentials.UserName = credentialsPrompter.UserName;
                            credentials.Password = credentialsPrompter.Password;
                        }
                        else
                        {
                            credentials.StoreCredentials = false;
                        }
                    }
                });
            }

            if (result ?? false)
            {
                Log.Debug("Successfully requested credentials for '{0}' using user '{1}'", uri, credentials.UserName);

                return credentials;
            }

            Log.Debug("Failed to request credentials for '{0}'", uri);

            return null;
        }
        #endregion