예제 #1
0
        private void RemoveSource()
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }
            // Check to see if we already have a registered source with the same name or source
            var sourceList      = SourceProvider.LoadPackageSources().ToList();
            var matchingSources = sourceList.Where(ps => string.Equals(Name, ps.Name, StringComparison.OrdinalIgnoreCase)).ToList();

            if (!matchingSources.Any())
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name);
            }

            if (Trust)
            {
                matchingSources.ForEach(p => SourceProvider.DeleteTrustedSource(p.Name));
            }
            else
            {
                var trustedSourceList = matchingSources.Where(p => p.TrustedSource != null).Select(p => UpdateServiceIndexTrustedSource(p));
                SourceProvider.SaveTrustedSources(trustedSourceList);
            }

            sourceList.RemoveAll(matchingSources.Contains);
            SourceProvider.SavePackageSources(sourceList);
            Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandSourceRemovedSuccessfully"), Name);
        }