示例#1
0
        /// <summary>
        ///     This initializes the provider registry with the list of package providers.
        ///     (currently a hardcoded list, soon, registry driven)
        /// </summary>
        /// <param name="request"></param>
        private void LoadProviders(IRequest request)
        {
            var providerAssemblies = (_initialized ? Enumerable.Empty <string>() : _defaultProviders)
                                     .Concat(GetProvidersFromRegistry(Registry.LocalMachine, "SOFTWARE\\MICROSOFT\\ONEGET"))
                                     .Concat(GetProvidersFromRegistry(Registry.CurrentUser, "SOFTWARE\\MICROSOFT\\ONEGET"))
                                     .Concat(AutoloadedAssemblyLocations.SelectMany(location => {
                if (Directory.Exists(location))
                {
                    return(Directory.EnumerateFiles(location).Where(each => !IsExcluded(each) && (each.EndsWith(".exe", StringComparison.CurrentCultureIgnoreCase) || each.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))));
                }
                return(Enumerable.Empty <string>());
            }));

            providerAssemblies = providerAssemblies.Distinct(new PathEqualityComparer(PathCompareOption.FileWithoutExtension));

            // there is no trouble with loading providers concurrently.
            Parallel.ForEach(providerAssemblies, providerAssemblyName => {
                try {
                    request.Debug(request.FormatMessageString("Trying provider assembly: {0}", providerAssemblyName));
                    if (TryToLoadProviderAssembly(providerAssemblyName, request))
                    {
                        request.Debug(request.FormatMessageString("SUCCESS provider assembly: {0}", providerAssemblyName));
                    }
                } catch {
                    request.Error(Constants.Messages.ProviderPluginLoadFailure, ErrorCategory.InvalidOperation.ToString(), providerAssemblyName, request.FormatMessageString(Constants.Messages.ProviderPluginLoadFailure, providerAssemblyName));
                }
            });
        }
        /// <summary>
        ///     This initializes the provider registry with the list of package providers.
        ///     (currently a hardcoded list, soon, registry driven)
        /// </summary>
        /// <param name="request"></param>
        internal void LoadProviders(IRequest request)
        {
            var providerAssemblies = (_initialized ? Enumerable.Empty <string>() : _defaultProviders)
                                     .Concat(GetProvidersFromRegistry(Registry.LocalMachine, "SOFTWARE\\MICROSOFT\\ONEGET"))
                                     .Concat(GetProvidersFromRegistry(Registry.CurrentUser, "SOFTWARE\\MICROSOFT\\ONEGET"))
                                     .Concat(AutoloadedAssemblyLocations.SelectMany(location => {
                if (Directory.Exists(location))
                {
                    return(Directory.EnumerateFiles(location).Where(each => !IsExcluded(each) && (each.EndsWith(".exe", StringComparison.CurrentCultureIgnoreCase) || each.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))));
                }
                return(Enumerable.Empty <string>());
            }));

            providerAssemblies = providerAssemblies.OrderByDescending(each => {
                try {
                    // try to get a version from the file first
                    return((ulong)(FourPartVersion)FileVersionInfo.GetVersionInfo(each));
                } catch {
                    // otherwise we can't make a distinction.
                    return((ulong)0);
                }
            });
            providerAssemblies = providerAssemblies.Distinct(new PathEqualityComparer(PathCompareOption.FileWithoutExtension));

            // hack to make sure we don't load the old version of the nuget provider
            // when we have the ability to examine a plugin without dragging it into the
            // primary appdomain, this won't be needed.
            FourPartVersion minimumnugetversion = "2.8.3.6";

            providerAssemblies = providerAssemblies.Where(assemblyFile => {
                try {
                    if ("nuget-anycpu".EqualsIgnoreCase(Path.GetFileNameWithoutExtension(assemblyFile)) && ((FourPartVersion)FileVersionInfo.GetVersionInfo(assemblyFile)) < minimumnugetversion)
                    {
                        return(false);
                    }
                }
                catch {
                }
                return(true);
            });

            // there is no trouble with loading providers concurrently.
            providerAssemblies.ParallelForEach(providerAssemblyName => {
                try {
                    request.Debug(request.FormatMessageString("Trying provider assembly: {0}", providerAssemblyName));
                    if (TryToLoadProviderAssembly(providerAssemblyName, request))
                    {
                        request.Debug(request.FormatMessageString("SUCCESS provider assembly: {0}", providerAssemblyName));
                    }
                } catch {
                    request.Error(Constants.Messages.ProviderPluginLoadFailure, ErrorCategory.InvalidOperation.ToString(), providerAssemblyName, request.FormatMessageString(Constants.Messages.ProviderPluginLoadFailure, providerAssemblyName));
                }
            });
        }
示例#3
0
        /// <summary>
        ///     This initializes the provider registry with the list of package providers.
        ///     (currently a hardcoded list, soon, registry driven)
        /// </summary>
        /// <param name="request"></param>
        private void LoadProviders(IRequest request)
        {
            var providerAssemblies = (_initialized ? Enumerable.Empty <string>() : _builtInProviders)
                                     .Concat(GetProvidersFromRegistry(Registry.LocalMachine, "SOFTWARE\\MICROSOFT\\ONEGET"))
                                     .Concat(GetProvidersFromRegistry(Registry.CurrentUser, "SOFTWARE\\MICROSOFT\\ONEGET"))
                                     .Concat(AutoloadedAssemblyLocations.SelectMany(location => {
                if (Directory.Exists(location))
                {
                    return(Directory.EnumerateFiles(location).Where(each => each.EndsWith(".exe", StringComparison.CurrentCultureIgnoreCase) || each.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase)));
                }
                return(Enumerable.Empty <string>());
            }));

            // there is no trouble with loading providers concurrently.
            Parallel.ForEach(providerAssemblies, providerAssemblyName => {
                try {
                    request.Verbose(request.FormatMessageString("Trying provider assembly: {0}", providerAssemblyName));
                    TryToLoadProviderAssembly(providerAssemblyName, request);
                } catch {
                    request.Error(Constants.ProviderPluginLoadFailure, Constants.Invalidoperation, providerAssemblyName, request.FormatMessageString(Constants.ProviderPluginLoadFailure, providerAssemblyName));
                }
            });
        }
        /// <summary>
        ///     This initializes the provider registry with the list of package providers.
        ///     (currently a hardcoded list, soon, registry driven)
        /// </summary>
        /// <param name="request"></param>
        internal void LoadProviders(IHostApi request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var providerAssemblies = (_initialized ? Enumerable.Empty <string>() : _defaultProviders)
                                     .Concat(GetProvidersFromRegistry(Registry.LocalMachine, "SOFTWARE\\MICROSOFT\\PACKAGEMANAGEMENT"))
                                     .Concat(GetProvidersFromRegistry(Registry.CurrentUser, "SOFTWARE\\MICROSOFT\\PACKAGEMANAGEMENT"))
                                     .Concat(AutoloadedAssemblyLocations.SelectMany(location => {
                if (Directory.Exists(location))
                {
                    return(Directory.EnumerateFiles(location).Where(each => (each.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) || each.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))));
                }
                return(Enumerable.Empty <string>());
            }));

#if DEEP_DEBUG
            providerAssemblies = providerAssemblies.ToArray();

            foreach (var each in providerAssemblies)
            {
                request.Debug("possible assembly: {0}".format(each));
            }
#endif

            // find modules that have manifests
            // todo: expand this out to validate the assembly is ok for this instance of PackageManagement.
            providerAssemblies = providerAssemblies.Where(each => Manifest.LoadFrom(each).Any(manifest => Swidtag.IsSwidtag(manifest) && new Swidtag(manifest).IsApplicable(new Hashtable())));

            // add inbox assemblies (don't require manifests, because they are versioned with the core)

#if !COMMUNITY_BUILD
            // todo: these should just be strong-named references. for now, just load them from the same directory.
            providerAssemblies = providerAssemblies.Concat(new[] {
                Path.Combine(BaseDir, "Microsoft.PackageManagement.MetaProvider.PowerShell.dll"),
                Path.Combine(BaseDir, "Microsoft.PackageManagement.ArchiverProviders.dll"),
                Path.Combine(BaseDir, "Microsoft.PackageManagement.CoreProviders.dll"),
                Path.Combine(BaseDir, "Microsoft.PackageManagement.MsuProvider.dll"),
#if !CORE_CLR
                // can't load these providers here.
                Path.Combine(BaseDir, "Microsoft.PackageManagement.MsiProvider.dll"),
#endif
            });
#endif

#if DEEP_DEBUG
            providerAssemblies = providerAssemblies.ToArray();

            foreach (var each in providerAssemblies)
            {
                request.Debug("possible assembly with manifest: {0}".format(each));
            }
#endif

            providerAssemblies = providerAssemblies.OrderByDescending(each => {
                try {
                    // try to get a version from the file first
                    return((ulong)(FourPartVersion)FileVersionInfo.GetVersionInfo(each));
                } catch {
                    // otherwise we can't make a distinction.
                    return((ulong)0);
                }
            });
            providerAssemblies = providerAssemblies.Distinct(new PathEqualityComparer(PathCompareOption.FileWithoutExtension));

            // there is no trouble with loading providers concurrently.
#if DEEP_DEBUG
            providerAssemblies.SerialForEach(providerAssemblyName => {
#else
            providerAssemblies.ParallelForEach(providerAssemblyName => {
#endif
                TryToLoadProviderAssembly(providerAssemblyName, request);
            });
#if DEEP_DEBUG
            WaitForDebugger();
#endif
        }
示例#5
0
        /// <summary>
        ///     This initializes the provider registry with the list of package providers.
        ///     (currently a hardcoded list, soon, registry driven)
        /// </summary>
        /// <param name="request"></param>
        internal void LoadProviders(IHostApi request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var providerAssemblies = (_initialized ? Enumerable.Empty <string>() : _defaultProviders)
                                     .Concat(GetProvidersFromRegistry(Registry.LocalMachine, "SOFTWARE\\MICROSOFT\\ONEGET"))
                                     .Concat(GetProvidersFromRegistry(Registry.CurrentUser, "SOFTWARE\\MICROSOFT\\ONEGET"))
                                     .Concat(AutoloadedAssemblyLocations.SelectMany(location => {
                if (Directory.Exists(location))
                {
                    return(Directory.EnumerateFiles(location).Where(each => !IsExcluded(each) && (each.EndsWith(".exe", StringComparison.CurrentCultureIgnoreCase) || each.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))));
                }
                return(Enumerable.Empty <string>());
            }));

#if DEEP_DEBUG
            providerAssemblies = providerAssemblies.ToArray();

            foreach (var each in providerAssemblies)
            {
                request.Debug("possible assembly: {0}".format(each));
            }
#endif

            // find modules that have manifests
            // todo: expand this out to validate the assembly is ok for this instance of OneGet.
            providerAssemblies = providerAssemblies.Where(each => Manifest.LoadFrom(each).Any(manifest => Swidtag.IsSwidtag(manifest) && new Swidtag(manifest).IsApplicable(new Hashtable())));

            // add inbox assemblies (don't require manifests, because they are versioned with the core)

#if !COMMUNITY_BUILD
            // todo: these should just be strong-named references. for now, just load them from the same directory.
            providerAssemblies = providerAssemblies.Concat(new[] {
                Path.Combine(baseDir, "Microsoft.OneGet.MetaProvider.PowerShell.dll"),
                Path.Combine(baseDir, "Microsoft.OneGet.ArchiverProviders.dll"),
                Path.Combine(baseDir, "Microsoft.OneGet.CoreProviders.dll"),
                Path.Combine(baseDir, "Microsoft.OneGet.MsuProvider.dll"),
#if !CORE_CLR
                // can't load these providers here.
                Path.Combine(baseDir, "Microsoft.OneGet.MsiProvider.dll"),
#endif
            });
#endif

#if DEEP_DEBUG
            providerAssemblies = providerAssemblies.ToArray();

            foreach (var each in providerAssemblies)
            {
                request.Debug("possible assembly with manifest: {0}".format(each));
            }
#endif

            providerAssemblies = providerAssemblies.OrderByDescending(each => {
                try {
                    // try to get a version from the file first
                    return((ulong)(FourPartVersion)FileVersionInfo.GetVersionInfo(each));
                } catch {
                    // otherwise we can't make a distinction.
                    return((ulong)0);
                }
            });
            providerAssemblies = providerAssemblies.Distinct(new PathEqualityComparer(PathCompareOption.FileWithoutExtension));

#if BEFORE_WE_HAD_MANIFESTS
            // hack to make sure we don't load the old version of the nuget provider
            // when we have the ability to examine a plugin without dragging it into the
            // primary appdomain, this won't be needed.
            FourPartVersion minimumnugetversion = "2.8.3.6";

            providerAssemblies = providerAssemblies.Where(assemblyFile => {
                try {
                    if ("nuget-anycpu".EqualsIgnoreCase(Path.GetFileNameWithoutExtension(assemblyFile)) && ((FourPartVersion)FileVersionInfo.GetVersionInfo(assemblyFile)) < minimumnugetversion)
                    {
                        return(false);
                    }
                } catch {
                }
                return(true);
            });
#endif

            // there is no trouble with loading providers concurrently.
#if DEBUG
            providerAssemblies.SerialForEach(providerAssemblyName => {
#else
            providerAssemblies.ParallelForEach(providerAssemblyName => {
#endif
                try {
                    request.Debug(request.FormatMessageString("Trying provider assembly: {0}", providerAssemblyName));
                    if (TryToLoadProviderAssembly(providerAssemblyName, request))
                    {
                        request.Debug(request.FormatMessageString("SUCCESS provider assembly: {0}", providerAssemblyName));
                    }
                    else
                    {
                        request.Debug(request.FormatMessageString("FAILED provider assembly: {0}", providerAssemblyName));
                    }
                } catch {
                    request.Error(Constants.Messages.ProviderPluginLoadFailure, ErrorCategory.InvalidOperation.ToString(), providerAssemblyName, request.FormatMessageString(Constants.Messages.ProviderPluginLoadFailure, providerAssemblyName));
                }
            });
        }