Beispiel #1
0
        public override bool ProcessRecordAsync()
        {
            if (Name.IsNullOrEmpty())
            {
                var providers = ListAvailable.IsPresent ? PackageManagementService.GetAvailableProviders(this, Name).ReEnumerable() : SelectProviders(Name).ReEnumerable();

                var providerOrdered = providers.OrderBy(each => each.ProviderName);
                // Get all available providers
                foreach (var p in providerOrdered)
                {
                    WriteObject(p);
                }
            }
            else
            {
                ProcessProvidersFilteredByName();
            }

            return(true);
        }
Beispiel #2
0
        private void ProcessProvidersFilteredByName()
        {
            //Do not log error when a provider is not found in the list returned by SelectProviders(). This allows the searching continues
            //in the list of providers that are not loaded.
            ShouldLogError = false;
            var notfound = new List <string>();

            foreach (var name in Name)
            {
                var providers = ListAvailable.IsPresent ? PackageManagementService.GetAvailableProviders(this, new[] { name }).ReEnumerable() : SelectProviders(name).ReEnumerable();
                if (providers.Any())
                {
                    var providerOrdered = providers.OrderByDescending(each => each.ProviderName);

                    foreach (var provider in providerOrdered)
                    {
                        WriteObject(provider);
                    }
                }
                else
                {
                    notfound.Add(name);
                }
            }

            //Error out if the specific provider is not found
            if (notfound.Any())
            {
                if (notfound.Count == 1)
                {
                    Error(ListAvailable.IsPresent ? Constants.Errors.UnknownProvider : Constants.Errors.UnknownProviderFromActivatedList, notfound.FirstOrDefault());
                }
                else
                {
                    Error(ListAvailable.IsPresent ? Constants.Errors.UnknownProviders : Constants.Errors.UnknownProviderFromActivatedList, notfound.JoinWithComma());
                }
            }
            notfound.Clear();
        }