public override List <Process> ListProcesses() { string username; TryGetUsername(out username); List <Process> processes; string psErrorMessage; // Try using 'ps' first if (!PSListProcess(username, out psErrorMessage, out processes)) { string procErrorMessage; // try using the /proc file system if (!ProcFSListProcess(username, out procErrorMessage, out processes)) { StringBuilder sb = new StringBuilder(); sb.Append(psErrorMessage); sb.AppendLine(string.Empty); sb.AppendLine(procErrorMessage); VSMessageBoxHelper.PostErrorMessage(StringResources.Error_ProcessListFailedTitle, sb.ToString()); return(new List <Process>(0)); } } return(processes); }
public static DockerConnection GetDockerConnection(string name, bool supportSSHConnections) { if (string.IsNullOrWhiteSpace(name)) { return(null); } DockerContainerTransportSettings settings; Connection remoteConnection; ThreadHelper.ThrowIfNotOnUIThread(); if (!DockerConnection.TryConvertConnectionStringToSettings(name, out settings, out remoteConnection) || settings == null) { string connectionString; bool success = ShowContainerPickerWindow(IntPtr.Zero, supportSSHConnections, out connectionString); if (success) { success = DockerConnection.TryConvertConnectionStringToSettings(connectionString, out settings, out remoteConnection); } if (!success || settings == null) { VSMessageBoxHelper.PostErrorMessage(StringResources.Error_ContainerConnectionStringInvalidTitle, StringResources.Error_ContainerConnectionStringInvalidMessage); return(null); } } string displayName = DockerConnection.CreateConnectionString(settings.ContainerName, remoteConnection?.Name, settings.HostName); if (DockerHelper.IsContainerRunning(settings.HostName, settings.ContainerName, remoteConnection)) { return(new DockerConnection(settings, remoteConnection, displayName)); } else { VSMessageBoxHelper.PostErrorMessage( StringResources.Error_ContainerUnavailableTitle, StringResources.Error_ContainerUnavailableMessage.FormatCurrentCultureWithArgs(settings.ContainerName)); return(null); } }
public static DockerConnection GetDockerConnection(string name) { if (string.IsNullOrWhiteSpace(name)) { return(null); } Connection remoteConnection = null; DockerContainerTransportSettings settings = null; string containerName; string dockerString; string hostName = string.Empty; // Assume format is <server>/<hostname>::<container> where if <server> is specified, it is for SSH string[] connectionStrings = name.Split('/'); // Format is wrong, ask the user to select from the dialog if (connectionStrings.Length > 2 || connectionStrings.Length < 1) { string connectionString; // If the user cancels the window, we want to fall back to the error message below if (ShowContainerPickerWindow(IntPtr.Zero, out connectionString)) { return(GetDockerConnection(connectionString)); } } if (connectionStrings.Length == 2) { // SSH connection string remoteConnectionString = connectionStrings[0]; dockerString = connectionStrings[1]; remoteConnection = GetSSHConnection(remoteConnectionString); } else if (connectionStrings.Length == 1) { // local connection dockerString = connectionStrings[0]; } else { VSMessageBoxHelper.PostErrorMessage(StringResources.Error_ContainerConnectionStringInvalidTitle, StringResources.Error_ContainerConnectionStringInvalidMessage); return(null); } if (!string.IsNullOrWhiteSpace(dockerString)) { if (dockerString.Contains("::")) { int pos = dockerString.IndexOf("::", StringComparison.Ordinal); hostName = dockerString.Substring(0, pos); containerName = dockerString.Substring(pos + 2); } else { containerName = dockerString; } settings = new DockerContainerTransportSettings(hostName, containerName, remoteConnection != null); string displayName = remoteConnection != null ? remoteConnection.Name + '/' + dockerString : dockerString; string output; string error; // Test container is available/reachable. 5 seconds should be enough to verify DockerExecutionManager manager = new DockerExecutionManager(settings, remoteConnection); if (manager.ExecuteCommand("/bin/sh", 5000, out output, out error, runInShell: false, makeInteractive: false) != 0) { // Error message might be in output. VSMessageBoxHelper.PostErrorMessage( StringResources.Error_ContainerUnavailableTitle, StringResources.Error_ContainerUnavailableMessage.FormatCurrentCultureWithArgs(containerName, string.IsNullOrWhiteSpace(error) ? output : error) ); return(null); } return(new DockerConnection(settings, remoteConnection, displayName, containerName)); } return(null); }