public NuGet.IPackageRepository GetRepositoryFromSource(NuGet.PackageSource packageSource)
 {
     if (GetRepositoryFromSourceCallback != null)
     {
         return(GetRepositoryFromSourceCallback(packageSource));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Returns PackageSources if specified in the config file. Else returns the default sources specified in the constructor.
        /// If no default values were specified, returns an empty sequence.
        /// </summary>
        public IEnumerable <PackageSource> LoadPackageSources()
        {
            var sources                 = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var settingsValue           = new List <SettingValue>();
            IList <SettingValue> values = _settingsManager.GetValues(PackageSourcesSectionName, isPath: true);
            var machineWideSourcesCount = 0;

            if (!values.IsEmpty())
            {
                var machineWideSources = new List <SettingValue>();

                // remove duplicate sources. Pick the one with the highest priority.
                // note that Reverse() is needed because items in 'values' is in
                // ascending priority order.
                foreach (var settingValue in values.Reverse())
                {
                    if (!sources.Contains(settingValue.Key))
                    {
                        if (settingValue.IsMachineWide)
                        {
                            machineWideSources.Add(settingValue);
                        }
                        else
                        {
                            settingsValue.Add(settingValue);
                        }

                        sources.Add(settingValue.Key);
                    }
                }

                // Reverse the the list to be backward compatible
                settingsValue.Reverse();
                machineWideSourcesCount = machineWideSources.Count;

                // Add machine wide sources at the end
                settingsValue.AddRange(machineWideSources);
            }

            var loadedPackageSources = new List <PackageSource>();

            if (!settingsValue.IsEmpty())
            {
                // Create disabledSources list
                var disabledSourcesValues = _settingsManager.GetValues(DisabledPackageSourcesSectionName, isPath: false) ??
                                            Enumerable.Empty <SettingValue>();

                // the value of this dictionary is the priority value
                var disabledSources = new Dictionary <string, int>(StringComparer.CurrentCultureIgnoreCase);
                foreach (var v in disabledSourcesValues)
                {
                    if (!disabledSources.ContainsKey(v.Key) ||
                        disabledSources[v.Key] < v.Priority)
                    {
                        disabledSources[v.Key] = v.Priority;
                    }
                }

                // Create loadedPackageSources list
                loadedPackageSources = new List <PackageSource>();
                foreach (var p in settingsValue)
                {
                    string name = p.Key;
                    string src  = p.Value;
                    PackageSourceCredential creds = ReadCredential(name);

                    var isEnabled = !disabledSources.ContainsKey(name) ||
                                    disabledSources[name] < p.Priority;
                    var packageSource = new PackageSource(src, name, isEnabled)
                    {
                        UserName            = creds != null ? creds.Username : null,
                        Password            = creds != null ? creds.Password : null,
                        IsPasswordClearText = creds != null && creds.IsPasswordClearText,
                        IsMachineWide       = p.IsMachineWide
                    };

                    loadedPackageSources.Add(packageSource);
                }

                if (_migratePackageSources != null)
                {
                    MigrateSources(loadedPackageSources);
                }
            }

            SetDefaultPackageSources(loadedPackageSources, machineWideSourcesCount);

            return(loadedPackageSources);
        }
Esempio n. 3
0
 private static KeyValuePair <string, string> ReadPasswordValues(PackageSource source) =>
 new KeyValuePair <string, string>(source.IsPasswordClearText ? "ClearTextPassword" : "Password", source.IsPasswordClearText ? source.Password : EncryptionUtility.EncryptString(source.Password));
Esempio n. 4
0
        public IEnumerable <PackageSource> LoadPackageSources()
        {
            HashSet <string>     set           = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            List <SettingValue>  sequence      = new List <SettingValue>();
            IList <SettingValue> settingValues = this._settingsManager.GetSettingValues("packageSources", true);
            int machineWideSourcesCount        = 0;

            if (!settingValues.IsEmpty <SettingValue>())
            {
                List <SettingValue> collection = new List <SettingValue>();
                foreach (SettingValue value2 in settingValues.Reverse <SettingValue>())
                {
                    if (!set.Contains(value2.Key))
                    {
                        if (value2.IsMachineWide)
                        {
                            collection.Add(value2);
                        }
                        else
                        {
                            sequence.Add(value2);
                        }
                        set.Add(value2.Key);
                    }
                }
                sequence.Reverse();
                machineWideSourcesCount = collection.Count;
                sequence.AddRange(collection);
            }
            List <PackageSource> loadedPackageSources = new List <PackageSource>();

            if (!sequence.IsEmpty <SettingValue>())
            {
                Dictionary <string, SettingValue> disabledSources = Enumerable.ToDictionary <SettingValue, string>(this._settingsManager.GetSettingValues("disabledPackageSources", false) ?? Enumerable.Empty <SettingValue>(), s => s.Key, StringComparer.CurrentCultureIgnoreCase);
                loadedPackageSources = Enumerable.Select <SettingValue, PackageSource>(sequence, delegate(SettingValue p) {
                    SettingValue value2;
                    string key = p.Key;
                    PackageSourceCredential credential = this.ReadCredential(key);
                    bool isEnabled = true;
                    if (disabledSources.TryGetValue(key, out value2) && (value2.Priority >= p.Priority))
                    {
                        isEnabled = false;
                    }
                    PackageSource source1      = new PackageSource(p.Value, key, isEnabled);
                    PackageSource source2      = new PackageSource(p.Value, key, isEnabled);
                    source2.UserName           = credential?.Username;
                    PackageSource local4       = source2;
                    PackageSource local5       = source2;
                    local5.Password            = credential?.Password;
                    PackageSource local2       = local5;
                    PackageSource local3       = local5;
                    local3.IsPasswordClearText = (credential != null) && credential.IsPasswordClearText;
                    PackageSource local1       = local3;
                    local1.IsMachineWide       = p.IsMachineWide;
                    return(local1);
                }).ToList <PackageSource>();
                if (this._migratePackageSources != null)
                {
                    this.MigrateSources(loadedPackageSources);
                }
            }
            this.SetDefaultPackageSources(loadedPackageSources, machineWideSourcesCount);
            return(loadedPackageSources);
        }