private void RefreshContainersListInternal() { try { IContainerViewModel selectedContainer = SelectedContainerInstance; SelectedContainerInstance = null; IEnumerable <DockerContainerInstance> containers; if (SelectedConnection is LocalConnectionViewModel) { containers = DockerHelper.GetLocalDockerContainers(Hostname); } else { ContainersFoundText = UIResources.SSHConnectingStatusText; var connection = SelectedConnection.Connection; if (connection == null) { UpdateStatusMessage(UIResources.SSHConnectionFailedStatusText, isError: true); return; } containers = DockerHelper.GetRemoteDockerContainers(connection, Hostname); } ContainerInstances = new ObservableCollection <IContainerViewModel>(containers.Select(item => new DockerContainerViewModel(item)).ToList()); OnPropertyChanged(nameof(ContainerInstances)); if (ContainerInstances.Count() > 0) { if (selectedContainer != null) { var found = ContainerInstances.FirstOrDefault(c => selectedContainer.Equals(c)); if (found != null) { SelectedContainerInstance = found; return; } } SelectedContainerInstance = ContainerInstances[0]; } } catch (Exception ex) { UpdateStatusMessage(UIResources.ErrorStatusTextFormat.FormatCurrentCultureWithArgs(ex.Message), isError: true); return; } finally { if (ContainerInstances.Count() > 0) { ContainersFoundText = UIResources.ContainersFoundStatusText.FormatCurrentCultureWithArgs(ContainerInstances.Count()); } else { ContainersFoundText = UIResources.NoContainersFound; } IsRefreshEnabled = true; } }
private void RefreshContainersListInternal() { int totalContainers = 0; try { IContainerViewModel selectedContainer = SelectedContainerInstance; SelectedContainerInstance = null; IEnumerable <DockerContainerInstance> containers; if (SelectedConnection is LocalConnectionViewModel) { containers = DockerHelper.GetLocalDockerContainers(Hostname, out totalContainers); } else { ContainersFoundText = UIResources.SSHConnectingStatusText; var connection = SelectedConnection.Connection; if (connection == null) { UpdateStatusMessage(UIResources.SSHConnectionFailedStatusText, isError: true); return; } containers = DockerHelper.GetRemoteDockerContainers(connection, Hostname, out totalContainers); } if (containers.Count() > 0) { string serverOS; if (DockerHelper.TryGetServerOS(Hostname, out serverOS)) { bool lcow; bool getLCOW = DockerHelper.TryGetLCOW(Hostname, out lcow); TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; serverOS = textInfo.ToTitleCase(serverOS); /* Note: LCOW is the abbreviation for Linux Containers on Windows * * In LCOW, both Linux and Windows containers can run simultaneously in a Docker (Windows) Engine. * Thus, the container platform must be queried directly. * Otherwise, the container platform must match that of the server engine. */ if (lcow && serverOS.Contains("Windows")) { foreach (DockerContainerInstance container in containers) { string containerPlatform = string.Empty; if (DockerHelper.TryGetContainerPlatform(Hostname, container.Name, out containerPlatform)) { container.Platform = textInfo.ToTitleCase(containerPlatform); } else { container.Platform = unknownOS; } } } else { foreach (DockerContainerInstance container in containers) { container.Platform = serverOS; } } } else { foreach (DockerContainerInstance container in containers) { container.Platform = unknownOS; } } } ContainerInstances = new ObservableCollection <IContainerViewModel>(containers.Select(item => new DockerContainerViewModel(item)).ToList()); OnPropertyChanged(nameof(ContainerInstances)); if (ContainerInstances.Count() > 0) { if (selectedContainer != null) { var found = ContainerInstances.FirstOrDefault(c => selectedContainer.Equals(c)); if (found != null) { SelectedContainerInstance = found; return; } } SelectedContainerInstance = ContainerInstances[0]; } } catch (Exception ex) { UpdateStatusMessage(UIResources.ErrorStatusTextFormat.FormatCurrentCultureWithArgs(ex.Message), isError: true); return; } finally { if (ContainerInstances.Count() > 0) { if (ContainerInstances.Count() < totalContainers) { UpdateStatusMessage(UIResources.ContainersNotAllParsedStatusText.FormatCurrentCultureWithArgs(totalContainers - ContainerInstances.Count()), isError: false); ContainersFoundText = UIResources.ContainersNotAllParsedText.FormatCurrentCultureWithArgs(ContainerInstances.Count(), totalContainers); } else { ContainersFoundText = UIResources.ContainersFoundStatusText.FormatCurrentCultureWithArgs(ContainerInstances.Count()); } } else { ContainersFoundText = UIResources.NoContainersFound; } IsRefreshEnabled = true; } }