Beispiel #1
0
        public override int Execute()
        {
            IEnumerable <WorkloadId> installedList = _workloadRecordRepo.GetInstalledWorkloads(_currentSdkFeatureBand);

            if (_machineReadableOption)
            {
                if (!string.IsNullOrWhiteSpace(_targetSdkVersion))
                {
                    if (new SdkFeatureBand(_targetSdkVersion).CompareTo(_currentSdkFeatureBand) < 0)
                    {
                        throw new ArgumentException(
                                  $"Version band of {_targetSdkVersion} --- {new SdkFeatureBand(_targetSdkVersion)} should not be smaller than current version band {_currentSdkFeatureBand}");
                    }
                }

                UpdateAvailableEntry[] updateAvailable = GetUpdateAvailable(installedList);
                ListOutput             listOutput      = new(installedList.Select(id => id.ToString()).ToArray(),
                                                             updateAvailable);

                _reporter.WriteLine("==workloadListJsonOutputStart==");
                _reporter.WriteLine(
                    JsonSerializer.Serialize(listOutput,
                                             new JsonSerializerOptions {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                }));
                _reporter.WriteLine("==workloadListJsonOutputEnd==");
            }
            else
            {
                InstalledWorkloadsCollection installedWorkloads = new(installedList, $"SDK {_currentSdkFeatureBand}");

                if (OperatingSystem.IsWindows())
                {
                    VisualStudioWorkloads.GetInstalledWorkloads(_workloadResolver, _currentSdkFeatureBand, installedWorkloads);
                }

                _reporter.WriteLine();

                PrintableTable <KeyValuePair <string, string> > table = new();
                table.AddColumn(LocalizableStrings.WorkloadIdColumn, workload => workload.Key);
                table.AddColumn(LocalizableStrings.WorkloadSourceColumn, workload => workload.Value);

                table.PrintRows(installedWorkloads.AsEnumerable(), l => _reporter.WriteLine(l));

                _reporter.WriteLine();
                _reporter.WriteLine(LocalizableStrings.WorkloadListFooter);
                _reporter.WriteLine();

                var updatableWorkloads = _workloadManifestUpdater.GetUpdatableWorkloadsToAdvertise(installedList).Select(workloadId => workloadId.ToString());
                if (updatableWorkloads.Any())
                {
                    _reporter.WriteLine(string.Format(LocalizableStrings.WorkloadUpdatesAvailable, string.Join(" ", updatableWorkloads)));
                    _reporter.WriteLine();
                }
            }

            return(0);
        }
Beispiel #2
0
        public override int Execute()
        {
            IEnumerable <WorkloadId> installedList = _workloadListHelper.InstalledSdkWorkloadIds;

            if (_machineReadableOption)
            {
                _workloadListHelper.CheckTargetSdkVersionIsValid();

                UpdateAvailableEntry[] updateAvailable = GetUpdateAvailable(installedList);
                ListOutput             listOutput      = new(installedList.Select(id => id.ToString()).ToArray(),
                                                             updateAvailable);

                Reporter.WriteLine("==workloadListJsonOutputStart==");
                Reporter.WriteLine(
                    JsonSerializer.Serialize(listOutput,
                                             new JsonSerializerOptions {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                }));
                Reporter.WriteLine("==workloadListJsonOutputEnd==");
            }
            else
            {
                InstalledWorkloadsCollection installedWorkloads = _workloadListHelper.AddInstalledVsWorkloads(installedList);
                Reporter.WriteLine();

                PrintableTable <KeyValuePair <string, string> > table = new();
                table.AddColumn(LocalizableStrings.WorkloadIdColumn, workload => workload.Key);
                table.AddColumn(LocalizableStrings.WorkloadSourceColumn, workload => workload.Value);

                table.PrintRows(installedWorkloads.AsEnumerable(), l => Reporter.WriteLine(l));

                Reporter.WriteLine();
                Reporter.WriteLine(LocalizableStrings.WorkloadListFooter);
                Reporter.WriteLine();

                var updatableWorkloads = _workloadManifestUpdater.GetUpdatableWorkloadsToAdvertise(installedList).Select(workloadId => workloadId.ToString());
                if (updatableWorkloads.Any())
                {
                    Reporter.WriteLine(string.Format(LocalizableStrings.WorkloadUpdatesAvailable, string.Join(" ", updatableWorkloads)));
                    Reporter.WriteLine();
                }
            }

            return(0);
        }