public override Task <IAttachDebuggerStep> OnStartAsync() { ProgressMessage = Resources.AttachDebuggerConnectingProgressMessage; IsCancelButtonEnabled = false; if (!WindowsCredentialManager.Write( Context.PublicIp, Context.Credential.User, Context.Credential.Password, WindowsCredentialManager.CredentialType.DomainPassword, WindowsCredentialManager.CredentialPersistence.Session)) { Debug.WriteLine($"Failed to save credential for {Context.PublicIp}, last error is {Marshal.GetLastWin32Error()}"); // It's OKay to continue, the Debugger2 will prompt UI to ask for credential. } if (!GetAllProcessesList()) { return(Task.FromResult <IAttachDebuggerStep>(HelpStepViewModel.CreateStep(Context))); } else if (Processes.Count() == 1) { return(Task.FromResult(Attach())); } else { EnableSelection(); // Returns null so that the user stays on the step to pick a process. return(Task.FromResult <IAttachDebuggerStep>(null)); } }
/// <summary> /// Store credential using git-credential-manager /// </summary> /// <param name="url">The repository url.</param> /// <param name="refreshToken">Google cloud credential refresh token.</param> /// <param name="pathOption"><seealso cref="StoreCredentialPathOption"/> </param> /// <returns> /// True: if credential is stored successfully. /// Otherwise false. /// </returns> public static bool StoreCredential( string url, string refreshToken, StoreCredentialPathOption pathOption) { url.ThrowIfNullOrEmpty(nameof(url)); refreshToken.ThrowIfNullOrEmpty(nameof(refreshToken)); Uri uri = new Uri(url); UriPartial uriPartial; switch (pathOption) { case StoreCredentialPathOption.UrlPath: uriPartial = UriPartial.Path; break; case StoreCredentialPathOption.UrlHost: uriPartial = UriPartial.Authority; break; default: throw new ArgumentException(nameof(pathOption)); } return(WindowsCredentialManager.Write( $"git:{uri.GetLeftPart(uriPartial)}", username: CsrRefreshTokenAccessUserName, password: refreshToken, credentialType: WindowsCredentialManager.CredentialType.Generic, persistenceType: WindowsCredentialManager.CredentialPersistence.LocalMachine)); }