/// <summary> /// Initializes a new instance of the DebugService class and uses /// the given execution service for all future operations. /// </summary> public DebugService( IInternalPowerShellExecutionService executionService, IPowerShellDebugContext debugContext, RemoteFileManagerService remoteFileManager, BreakpointService breakpointService, PsesInternalHost psesHost, ILoggerFactory factory) { Validate.IsNotNull(nameof(executionService), executionService); _logger = factory.CreateLogger <DebugService>(); _executionService = executionService; _breakpointService = breakpointService; _psesHost = psesHost; _debugContext = debugContext; _debugContext.DebuggerStopped += OnDebuggerStopAsync; _debugContext.DebuggerResuming += OnDebuggerResuming; _debugContext.BreakpointUpdated += OnBreakpointUpdated; _remoteFileManager = remoteFileManager; invocationTypeScriptPositionProperty = typeof(InvocationInfo) .GetProperty( "ScriptPosition", BindingFlags.NonPublic | BindingFlags.Instance); }
public RemotePathMappings( RunspaceDetails runspaceDetails, RemoteFileManagerService remoteFileManager) { this.runspaceDetails = runspaceDetails; this.remoteFileManager = remoteFileManager; }
/// <summary> /// Opens a remote file, fetching its contents if necessary. /// </summary> /// <param name="remoteFilePath"> /// The remote file path to be opened. /// </param> /// <param name="runspaceDetails"> /// The runspace from which where the remote file will be fetched. /// </param> /// <returns> /// The local file path where the remote file's contents have been stored. /// </returns> public async Task <string> FetchRemoteFileAsync( string remoteFilePath, RunspaceDetails runspaceDetails) { string localFilePath = null; if (!string.IsNullOrEmpty(remoteFilePath)) { try { RemotePathMappings pathMappings = this.GetPathMappings(runspaceDetails); localFilePath = this.GetMappedPath(remoteFilePath, runspaceDetails); if (!pathMappings.IsRemotePathOpened(remoteFilePath)) { // Does the local file already exist? if (!File.Exists(localFilePath)) { // Load the file contents from the remote machine and create the buffer PSCommand command = new PSCommand(); command.AddCommand("Microsoft.PowerShell.Management\\Get-Content"); command.AddParameter("Path", remoteFilePath); command.AddParameter("Raw"); command.AddParameter("Encoding", "Byte"); byte[] fileContent = (await this.powerShellContext.ExecuteCommandAsync <byte[]>(command, false, false).ConfigureAwait(false)) .FirstOrDefault(); if (fileContent != null) { RemoteFileManagerService.StoreRemoteFile(localFilePath, fileContent, pathMappings); } else { this.logger.LogWarning( $"Could not load contents of remote file '{remoteFilePath}'"); } } } } catch (IOException e) { this.logger.LogError( $"Caught {e.GetType().Name} while attempting to get remote file at path '{remoteFilePath}'\r\n\r\n{e.ToString()}"); } } return(localFilePath); }
private string StoreRemoteFile( string remoteFilePath, byte[] fileContent, RunspaceDetails runspaceDetails) { RemotePathMappings pathMappings = this.GetPathMappings(runspaceDetails); string localFilePath = pathMappings.GetMappedPath(remoteFilePath); RemoteFileManagerService.StoreRemoteFile( localFilePath, fileContent, pathMappings); return(localFilePath); }
/// <summary> /// Initializes a new instance of the DebugService class and uses /// the given PowerShellContext for all future operations. /// </summary> /// <param name="powerShellContext"> /// The PowerShellContext to use for all debugging operations. /// </param> /// <param name="logger">An ILogger implementation used for writing log messages.</param> //public DebugService(PowerShellContextService powerShellContext, ILogger logger) // : this(powerShellContext, null, logger) //{ //} /// <summary> /// Initializes a new instance of the DebugService class and uses /// the given PowerShellContext for all future operations. /// </summary> /// <param name="powerShellContext"> /// The PowerShellContext to use for all debugging operations. /// </param> //// <param name = "remoteFileManager" > //// A RemoteFileManagerService instance to use for accessing files in remote sessions. //// </param> /// <param name="logger">An ILogger implementation used for writing log messages.</param> public DebugService( PowerShellContextService powerShellContext, RemoteFileManagerService remoteFileManager, BreakpointService breakpointService, ILoggerFactory factory) { Validate.IsNotNull(nameof(powerShellContext), powerShellContext); this.logger = factory.CreateLogger <DebugService>(); this.powerShellContext = powerShellContext; _breakpointService = breakpointService; this.powerShellContext.DebuggerStop += this.OnDebuggerStopAsync; this.powerShellContext.DebuggerResumed += this.OnDebuggerResumed; this.powerShellContext.BreakpointUpdated += this.OnBreakpointUpdated; this.remoteFileManager = remoteFileManager; this.invocationTypeScriptPositionProperty = typeof(InvocationInfo) .GetProperty( "ScriptPosition", BindingFlags.NonPublic | BindingFlags.Instance); }