/// <summary> /// Execute remote PowerShell command to copy/setup debugger remote tools. /// </summary> public async Task <bool> Install(CancellationToken cancelToken) { try { var target = new RemoteTarget(_computerName, _credential); return(await target.ExecuteAsync(AddInstallCommands, cancelToken)); } catch (Exception ex) when( ex is ParameterBindingException && ex.Message.Contains(PowerShellFailedToConnectException.SessionEmptyErrorMessage)) { throw new PowerShellFailedToConnectException(ex); } }
/// <summary> /// Start the session and start the remote tool. /// This starts a backgroud task and leave it running till it is cancelled or stopped. /// </summary> /// <param name="computerName">The ipaddress of debugging target machine.</param> /// <param name="username">The username for authentication.</param> /// <param name="password">The password for authentication.</param> /// <param name="subscribeClosingEvent">The method to subscribe to solution closing event.</param> /// <param name="unsubscribeClosingEvent">The method to unsubscribe solution closing event.</param> public RemoteToolSession( string computerName, string username, string password, Action <EventHandler> subscribeClosingEvent, Action <EventHandler> unsubscribeClosingEvent) { var target = new RemoteTarget(computerName, RemotePowerShellUtils.CreatePSCredential(username, password)); string script = RemotePowerShellUtils.GetEmbeddedFile(StartPsFilePath); _closingEventHandler = (se, e) => Stop(); subscribeClosingEvent(_closingEventHandler); _powerShellTask = ExecuteScript(target, script, unsubscribeClosingEvent); }
/// <summary> /// Start the session and start the remote tool. /// This starts a backgroud task and leave it running till it is cancelled or stopped. /// </summary> /// <param name="computerName">The ipaddress of debugging target machine.</param> /// <param name="username">The username for authentication.</param> /// <param name="password">The password for authentication.</param> /// <param name="subscribeClosingEvent">The method to subscribe to solution closing event.</param> /// <param name="unsubscribeClosingEvent">The method to unsubscribe solution closing event.</param> public RemoteToolSession( string computerName, string username, string password, Action <EventHandler> subscribeClosingEvent, Action <EventHandler> unsubscribeClosingEvent) { var target = new RemoteTarget(computerName, RemotePowerShellUtils.CreatePSCredential(username, password)); string script = RemotePowerShellUtils.GetEmbeddedFile(StartPsFilePath); _closingEventHandler = (se, e) => Stop(); subscribeClosingEvent(_closingEventHandler); _powerShellTask = Task.Run(() => { try { target.EnterSessionExecute(script, _cancelTokenSource.Token); } finally { unsubscribeClosingEvent(_closingEventHandler); } }); }