/// <summary>
 /// Initializes a new instance of class <seealso cref="RemoteToolInstaller"/>
 /// </summary>
 /// <param name="computerName">
 /// The remote computer name. It can be a public ip address too.
 /// </param>
 /// <param name="username">Credential user name.</param>
 /// <param name="password">Credential password.</param>
 /// <param name="debuggerToolLocalPath">
 /// The path to Visual Studio remote debugging tools.
 /// It is located under Visual Studio installation path.
 /// </param>
 public RemoteToolInstaller(
     string computerName,
     string username,
     string password,
     string debuggerToolLocalPath)
 {
     _debuggerToolLocalPath = debuggerToolLocalPath;
     _credential            = RemotePowerShellUtils.CreatePSCredential(username, password);
     _computerName          = computerName;
 }
 private void AddInstallCommands(PowerShell powerShell)
 {
     powerShell.AddVariable(CredentialVariablename, _credential);
     powerShell.AddVariable(RemoteToolSourcePath, _debuggerToolLocalPath);
     powerShell.AddScript("$ErrorActionPreference = \"Stop\"");
     powerShell.AddScript("$sessionOptions = New-PSSessionOption –SkipCACheck –SkipCNCheck –SkipRevocationCheck");
     powerShell.AddScript($"$session = New-PSSession {_computerName} -UseSSL -Credential $credential -SessionOption $sessionOptions");
     powerShell.AddScript(RemotePowerShellUtils.GetEmbeddedFile(InstallerPsFilePath));
     powerShell.AddScript("Remove-PSSession -Session $session");
 }
        /// <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);
        }
Beispiel #4
0
        /// <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);
                }
            });
        }