Пример #1
0
        public override void ChangeActiveSource(PackageSource newSource)
        {
            if (newSource.Equals(NuGetV3PreviewSource))
            {
                return; // Can't set it as default
            }

            var source = _sourceProvider.GetEnabledPackageSources()
                         .FirstOrDefault(s => String.Equals(s.Name, newSource.Name, StringComparison.OrdinalIgnoreCase));

            if (source == null)
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Strings.VsPackageManagerSession_UnknownSource,
                              newSource.Name),
                          "newSource");
            }

            // The Urls should be equal but if they aren't, there's nothing the user can do about it :(
            Debug.Assert(String.Equals(source.Source, newSource.Url, StringComparison.Ordinal));

            // Update the active package source
            _sourceProvider.ActivePackageSource = source;
        }
Пример #2
0
 public static bool IsAnySourceLocal(IVsPackageSourceProvider packageSourceProvider, out string localSource)
 {
     localSource = string.Empty;
     if (packageSourceProvider != null)
     {
         //If any of the active sources is local folder and is available, return true
         IEnumerable <PackageSource> sources = null;
         PackageSource activeSource          = packageSourceProvider.ActivePackageSource;
         if (activeSource.IsAggregate())
         {
             sources = packageSourceProvider.GetEnabledPackageSources();
             foreach (PackageSource s in sources)
             {
                 if (IsLocal(s.Source))
                 {
                     localSource = s.Source;
                     return(true);
                 }
             }
         }
         else
         {
             if (IsLocal(activeSource.Source))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #3
0
        public static bool IsHttpSource(IVsPackageSourceProvider packageSourceProvider)
        {
            var activeSource = packageSourceProvider.ActivePackageSource;
            if (activeSource == null)
            {
                return false;
            }

            if (activeSource.IsAggregate())
            {
                return packageSourceProvider.GetEnabledPackageSources().Any(s => UriHelper.IsHttpSource(s.Source));
            }
            else
            {
                return UriHelper.IsHttpSource(activeSource.Source);
            }
        }
Пример #4
0
        public static bool IsHttpSource(IVsPackageSourceProvider packageSourceProvider)
        {
            var activeSource = packageSourceProvider.ActivePackageSource;

            if (activeSource == null)
            {
                return(false);
            }

            if (activeSource.IsAggregate())
            {
                return(packageSourceProvider.GetEnabledPackageSources().Any(s => IsHttpSource(s.Source)));
            }
            else
            {
                return(IsHttpSource(activeSource.Source));
            }
        }
Пример #5
0
        public static bool IsAnySourceAvailable(IVsPackageSourceProvider packageSourceProvider, bool checkHttp)
        {
            //If any of the enabled sources is http, return true
            if (checkHttp)
            {
                bool isHttpSource;
                isHttpSource = UriHelper.IsHttpSource(packageSourceProvider);
                if (isHttpSource)
                {
                    return(true);
                }
            }

            if (packageSourceProvider != null)
            {
                //If any of the active sources is UNC share or local folder and is available, return true
                IEnumerable <PackageSource> sources = null;
                PackageSource activeSource          = packageSourceProvider.ActivePackageSource;
                if (activeSource.IsAggregate())
                {
                    sources = packageSourceProvider.GetEnabledPackageSources();
                    foreach (PackageSource s in sources)
                    {
                        if (IsLocal(s.Source) || IsUNC(s.Source))
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    if (IsLocal(activeSource.Source) || IsUNC(activeSource.Source))
                    {
                        return(true);
                    }
                }
            }

            //If none of the above matched, return false
            return(false);
        }
Пример #6
0
        public static bool IsHttpSource(IVsPackageSourceProvider packageSourceProvider)
        {
            var activeSource = packageSourceProvider.ActivePackageSource;
            if (activeSource == null)
            {
                return false;
            }

            if (activeSource.IsAggregate())
            {
                return packageSourceProvider.GetEnabledPackageSources().Any(s => IsHttpSource(s.Source));
            }
            // For API V3, the source could be a local .json file.
            else if (activeSource.Source.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }
            else
            {
                return IsHttpSource(activeSource.Source);
            }
        }
Пример #7
0
        public static bool IsHttpSource(IVsPackageSourceProvider packageSourceProvider)
        {
            var activeSource = packageSourceProvider.ActivePackageSource;

            if (activeSource == null)
            {
                return(false);
            }

            if (activeSource.IsAggregate())
            {
                return(packageSourceProvider.GetEnabledPackageSources().Any(s => IsHttpSource(s.Source)));
            }
            // For API V3, the source could be a local .json file.
            else if (activeSource.Source.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            else
            {
                return(IsHttpSource(activeSource.Source));
            }
        }
Пример #8
0
        public static bool IsAnySourceAvailable(IVsPackageSourceProvider packageSourceProvider, bool checkHttp)
        {
            //If any of the enabled sources is http, return true
            if (checkHttp)
            {
                bool isHttpSource;
                isHttpSource = UriHelper.IsHttpSource(packageSourceProvider);
                if (isHttpSource)
                {
                    return true;
                }
            }

            if (packageSourceProvider != null)
            {
                //If any of the active sources is UNC share or local folder and is available, return true
                IEnumerable<PackageSource> sources = null;
                PackageSource activeSource = packageSourceProvider.ActivePackageSource;
                if (activeSource.IsAggregate())
                {
                    sources = packageSourceProvider.GetEnabledPackageSources();
                    foreach (PackageSource s in sources)
                    {
                        if (IsLocal(s.Source) || IsUNC(s.Source)) return true;
                    }
                }
                else
                {
                    if (IsLocal(activeSource.Source) || IsUNC(activeSource.Source)) return true;
                }
            }

            //If none of the above matched, return false
            return false;
        }
Пример #9
0
 public static bool IsAnySourceLocal(IVsPackageSourceProvider packageSourceProvider, out string localSource)
 {
     localSource = string.Empty;
     if (packageSourceProvider != null)
     {
         //If any of the active sources is local folder and is available, return true
         IEnumerable<PackageSource> sources = null;
         PackageSource activeSource = packageSourceProvider.ActivePackageSource;
         if (activeSource.IsAggregate())
         {
             sources = packageSourceProvider.GetEnabledPackageSources();
             foreach (PackageSource s in sources)
             {
                 if (IsLocal(s.Source))
                 {
                     localSource = s.Source;
                     return true;
                 }
             }
         }
         else
         {
             if (IsLocal(activeSource.Source)) return true;
         }
     }
     return false;
 }
Пример #10
0
 public string[] GetPackageSources()
 {
     // Starting NuGet 3.0 RC, AggregateSource will not be displayed in the Package source dropdown box of PowerShell console.
     return(_packageSourceProvider.GetEnabledPackageSources().Select(ps => ps.Name).ToArray());
 }