コード例 #1
0
 public PackageSourceWrapper(PackageSource source)
 {
     this.source = source;
     Name        = source.Name;
     ToolTip     = source.Description;
     if (string.IsNullOrEmpty(ToolTip))
     {
         ToolTip = Name;
     }
 }
コード例 #2
0
        private SourceRepository GetSourceRepository(string SourceUrl)
        {
            try
            {
                IEnumerable <Lazy <INuGetResourceProvider, INuGetResourceProviderMetadata> > providers = container.GetExports <INuGetResourceProvider, INuGetResourceProviderMetadata>();

                StringBuilder sb = new StringBuilder();

                foreach (var provider in providers)
                {
                    sb.AppendLine(provider.Metadata.ResourceType.ToString());
                }

                Assert.True(providers.Count() > 0);
                NuGet.Configuration.PackageSource source = new NuGet.Configuration.PackageSource(SourceUrl, "mysource", true);
                SourceRepository repo = new SourceRepository(source, providers);
                return(repo);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
コード例 #3
0
ファイル: NuGetViewModel.cs プロジェクト: phillijw/RoslynPad
 public SourceRepository CreateRepository(PackageSource source, FeedType type)
 {
     return(_cachedSources.GetOrAdd(source, new SourceRepository(source, _resourceProviders, type)));
 }
コード例 #4
0
 public bool IsPackageSourceEnabled(NuGet.Configuration.PackageSource source)
 {
     return(true);
 }
コード例 #5
0
 public void DisablePackageSource(NuGet.Configuration.PackageSource source)
 {
     throw new NotImplementedException();
 }
コード例 #6
0
ファイル: Settings.cs プロジェクト: zyonet/NuGet.Client
        private static void LoadUserSpecificSettings(
            List <Settings> validSettingFiles,
            string root,
            string configFileName,
            IMachineWideSettings machineWideSettings,
            bool useTestingGlobalPath
            )
        {
            if (root == null)
            {
                // Path.Combine is performed with root so it should not be null
                // However, it is legal for it be empty in this method
                root = String.Empty;
            }
            // for the default location, allow case where file does not exist, in which case it'll end
            // up being created if needed
            Settings appDataSettings = null;

            if (configFileName == null)
            {
                var defaultSettingsFilePath = String.Empty;
                if (useTestingGlobalPath)
                {
                    defaultSettingsFilePath = Path.Combine(root, "TestingGlobalPath", DefaultSettingsFileName);
                }
                else
                {
                    var userSettingsDir = NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);

                    // If there is no user settings directory, return no appdata settings
                    if (userSettingsDir == null)
                    {
                        return;
                    }
                    defaultSettingsFilePath = Path.Combine(userSettingsDir, DefaultSettingsFileName);
                }

                if (!File.Exists(defaultSettingsFilePath) && machineWideSettings != null)
                {
                    // Since defaultSettingsFilePath is a full path, so it doesn't matter what value is
                    // used as root for the PhysicalFileSystem.
                    appDataSettings = ReadSettings(
                        root,
                        defaultSettingsFilePath);

                    // Disable machinewide sources to improve perf
                    var disabledSources = new List <SettingValue>();
                    foreach (var setting in machineWideSettings.Settings)
                    {
                        var values = setting.GetSettingValues(ConfigurationConstants.PackageSources, isPath: true);
                        foreach (var value in values)
                        {
                            var packageSource = new PackageSource(value.Value);

                            // if the machine wide package source is http source, disable it by default
                            if (packageSource.IsHttp)
                            {
                                disabledSources.Add(new SettingValue(value.Key, "true", origin: setting, isMachineWide: true, priority: 0));
                            }
                        }
                    }
                    appDataSettings.UpdateSections(ConfigurationConstants.DisabledPackageSources, disabledSources);
                }
                else
                {
                    appDataSettings = ReadSettings(root, defaultSettingsFilePath);
                    bool IsEmptyConfig = !appDataSettings.GetSettingValues(ConfigurationConstants.PackageSources).Any();

                    if (IsEmptyConfig)
                    {
                        var trackFilePath = Path.Combine(Path.GetDirectoryName(defaultSettingsFilePath), NuGetConstants.AddV3TrackFile);

                        if (!File.Exists(trackFilePath))
                        {
                            File.Create(trackFilePath).Dispose();
                            var defaultPackageSource = new SettingValue(NuGetConstants.FeedName, NuGetConstants.V3FeedUrl, isMachineWide: false);
                            defaultPackageSource.AdditionalData.Add(ConfigurationConstants.ProtocolVersionAttribute, "3");
                            appDataSettings.UpdateSections(ConfigurationConstants.PackageSources, new List <SettingValue> {
                                defaultPackageSource
                            });
                        }
                    }
                }
            }
            else
            {
                if (!FileSystemUtility.DoesFileExistIn(root, configFileName))
                {
                    var message = String.Format(CultureInfo.CurrentCulture,
                                                Resources.FileDoesNotExist,
                                                Path.Combine(root, configFileName));
                    throw new InvalidOperationException(message);
                }

                appDataSettings = ReadSettings(root, configFileName);
            }

            if (appDataSettings != null)
            {
                validSettingFiles.Add(appDataSettings);
            }
        }
コード例 #7
0
 public SourceRepository CreateRepository(PackageSource source)
 {
     return _cachedSources.GetOrAdd(source, new SourceRepository(source, _resourceProviders));
 }
コード例 #8
0
        private void UpdatePackageSource(
            PackageSource newSource,
            PackageSource existingSource,
            AddItem existingDisabledSourceItem,
            CredentialsItem existingCredentialsItem,
            bool updateEnabled,
            bool updateCredentials,
            bool shouldSkipSave,
            ref bool isDirty)
        {
            if (string.Equals(newSource.Name, existingSource.Name, StringComparison.OrdinalIgnoreCase))
            {
                if ((!string.Equals(newSource.Source, existingSource.Source, StringComparison.OrdinalIgnoreCase) ||
                     newSource.ProtocolVersion != existingSource.ProtocolVersion) && newSource.IsPersistable)
                {
                    Settings.AddOrUpdate(ConfigurationConstants.PackageSources, newSource.AsSourceItem());
                    isDirty = true;
                }

                if (updateEnabled)
                {
                    if (newSource.IsEnabled && existingDisabledSourceItem != null)
                    {
                        Settings.Remove(ConfigurationConstants.DisabledPackageSources, existingDisabledSourceItem);
                        isDirty = true;
                    }

                    if (!newSource.IsEnabled && existingDisabledSourceItem == null)
                    {
                        AddDisabledSource(newSource.Name, shouldSkipSave: true, isDirty: ref isDirty);
                    }
                }

                if (updateCredentials && newSource.Credentials != existingSource.Credentials)
                {
                    if (existingCredentialsItem != null)
                    {
                        if (newSource.Credentials == null)
                        {
                            Settings.Remove(ConfigurationConstants.CredentialsSectionName, existingCredentialsItem);
                            isDirty = true;
                        }
                        else
                        {
                            Settings.AddOrUpdate(ConfigurationConstants.CredentialsSectionName, newSource.Credentials.AsCredentialsItem());
                            isDirty = true;
                        }
                    }
                    else if (newSource.Credentials != null && newSource.Credentials.IsValid())
                    {
                        Settings.AddOrUpdate(ConfigurationConstants.CredentialsSectionName, newSource.Credentials.AsCredentialsItem());
                        isDirty = true;
                    }
                }

                if (!shouldSkipSave && isDirty)
                {
                    Settings.SaveToDisk();
                    OnPackageSourcesChanged();
                    isDirty = false;
                }
            }
        }