private Swidtag DownloadSwidtag(IEnumerable <Uri> locations) { foreach (var location in locations.WhereNotNull()) { try { var filename = "swidtag.xml".GenerateTemporaryFilename(); DownloadSwidtagToFile(filename, location); if (_timedOut) { // try one more time... DownloadSwidtagToFile(filename, location); } if (filename.FileExists()) { var document = XDocument.Load(filename); if (Swidtag.IsSwidtag(document.Root)) { Location = location; return(new Swidtag(document)); } } } catch (Exception e) { e.Dump(); } } return(null); }
public override string YieldSoftwareIdentityXml(string xmlSwidTag, bool commitImmediately = false) { Activity(); CommitCurrentItem(); if (string.IsNullOrWhiteSpace(xmlSwidTag)) { return(null); } try { XDocument xdoc = XDocument.Parse(xmlSwidTag); if (xdoc != null && xdoc.Root != null && Swidtag.IsSwidtag(xdoc.Root)) { _currentItem = new SoftwareIdentity(xdoc); if (Provider != null) { _currentItem.Provider = (PackageProvider)Provider; } } else { Verbose(string.Format(CultureInfo.CurrentCulture, Resources.Messages.SwidTagXmlInvalidNameSpace, xmlSwidTag, Iso19770_2.Namespace.Iso19770_2)); } } catch (Exception e) { Verbose(e.Message); Verbose(e.StackTrace); } if (_currentItem == null) { Warning(string.Format(CultureInfo.CurrentCulture, Resources.Messages.SwidTagXmlNotValid)); return(null); } string result = _currentItem.FastPackageReference; // provider author wants us to commit at once if (commitImmediately) { CommitCurrentItem(); } return(result); }
private Swidtag DownloadSwidtag(IEnumerable <Uri> locations, BootstrapRequest request) { foreach (var location in locations.WhereNotNull()) { try { var filename = FilesystemExtensions.GenerateTemporaryFileOrDirectoryNameInTempDirectory(); DownloadSwidtagToFile(filename, location); if (_timedOut) { // try one more time... DownloadSwidtagToFile(filename, location); } if (filename.FileExists()) { try { var document = XDocument.Load(filename); if (Swidtag.IsSwidtag(document.Root)) { Location = location; return(new Swidtag(document)); } } finally { System.IO.File.Delete(filename); } } } catch (Exception e) { e.Dump(request); } } return(null); }
/// <summary> /// Get a package provider from a given path. /// </summary> /// <param name="filePath"></param> /// <param name="suppressErrorsAndWarnings"></param> /// <param name="copyFileToTemp"></param> /// <returns></returns> internal Package GetProviderFromFile(string filePath, bool copyFileToTemp = false, bool suppressErrorsAndWarnings = false) { #if PORTABLE // not supported on core powershell return(null); #else if (string.IsNullOrWhiteSpace(filePath) && !System.IO.File.Exists(filePath)) { Warning(Constants.Messages.FileNotFound, filePath); return(null); } // support providers with .dll file extension only if (!Path.GetExtension(filePath).EqualsIgnoreCase(".dll")) { if (!suppressErrorsAndWarnings) { Warning(Resources.Messages.InvalidFileType, ".dll", filePath); } return(null); } string tempFile = filePath; IEnumerable <XElement> manifests = Enumerable.Empty <XElement>(); if (copyFileToTemp) { try { // Manifest.LoadFrom() does not work with network share, so we need to copy the dll to temp location tempFile = CopyToTempLocation(filePath); if (string.IsNullOrWhiteSpace(tempFile) && !System.IO.File.Exists(tempFile)) { Warning(Constants.Messages.FileNotFound, tempFile); return(null); } manifests = Manifest.LoadFrom(tempFile).ToArray(); } finally { if (!string.IsNullOrWhiteSpace(tempFile)) { tempFile.TryHardToDelete(); } } } else { // providers have the provider manifest embeded? manifests = Manifest.LoadFrom(filePath).ToArray(); } if (!manifests.Any()) { if (!suppressErrorsAndWarnings) { Warning(Resources.Messages.MissingProviderManifest, tempFile); } return(null); } var source = new Uri(filePath); foreach (var manifest in manifests) { var swidTagObject = new Swidtag(manifest); if (Swidtag.IsSwidtag(manifest) && swidTagObject.IsApplicable(new Hashtable())) { return(new Package(this, swidTagObject) { Location = source, Source = source.LocalPath }); } } return(null); #endif }
/// <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 }
/// <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)); } }); }