private bool InstallProviderFromInstaller(Package provider, Link link, string fastPath, BootstrapRequest request) { switch (link.MediaType) { case Iso19770_2.MediaType.MsiPackage: case Iso19770_2.MediaType.MsuPackage: return(InstallPackageFile(provider, fastPath, request)); case Iso19770_2.MediaType.PackageReference: // let the core figure out how to install this package var packages = PackageManagementService.FindPackageByCanonicalId(link.HRef.AbsoluteUri, request).ToArray(); switch (packages.Length) { case 0: request.Warning("Unable to resolve package reference '{0}'", link.HRef); return(false); case 1: return(InstallPackageReference(provider, fastPath, request, packages)); default: request.Warning("Package Reference '{0}' resolves to {1} packages.", link.HRef, packages.Length); return(false); } case Iso19770_2.MediaType.NuGetPackage: return(InstallNugetPackage(provider, link, fastPath, request)); default: request.Warning("Provider '{0}' with link '{1}' has unknown media type '{2}'.", provider.Name, link.HRef, link.MediaType); return(false); } }
private bool InstallPackageFile(Package provider, string fastPath, BootstrapRequest request) { // we can download and verify this package and get the core to install it. var file = request.DownloadAndValidateFile(provider._swidtag); if (file != null) { // we have a valid file. // run the installer if (request.ProviderServices.Install(file, "", request)) { // it installed ok! request.YieldFromSwidtag(provider, fastPath); PackageManagementService.LoadProviders(request.As <IRequest>()); return(true); } request.Warning(Constants.Messages.FailedProviderBootstrap, fastPath); } return(false); }
internal void InstallPackage(string fastPath, BootstrapRequest request, bool errorContinue) { if (fastPath == null) { throw new ArgumentNullException("fastPath"); } if (request == null) { throw new ArgumentNullException("request"); } // ensure that mandatory parameters are present. request.Debug("Calling 'Bootstrap::InstallPackage'"); var triedAndFailed = false; //source can be from install - packageprovider or can be from the pipeline if ((request.LocalSource.Any() || fastPath.IsFile())) { InstallPackageFromFile(fastPath, request); return; } // verify the package integrity (ie, check if it's digitally signed before installing) var provider = request.GetProvider(new Uri(fastPath)); if (provider == null || !provider.IsValid) { var result = errorContinue ? request.Warning(Constants.Messages.UnableToResolvePackage, fastPath) : request.Error(ErrorCategory.InvalidData, fastPath, Constants.Messages.UnableToResolvePackage, fastPath); return; } // first install the dependencies if any var dependencyLinks = provider._swidtag.Links.Where(link => link.Relationship == Iso19770_2.Relationship.Requires).GroupBy(link => link.Artifact); foreach (var depLinks in dependencyLinks) { foreach (var item in depLinks) { Package packages = null; if (string.IsNullOrWhiteSpace(item.Attributes[Iso19770_2.Discovery.Name])) { //select the packages that marked as "latest" packages = (new Feed(request, new[] { item.HRef })).Query().FirstOrDefault(); } else { if (string.IsNullOrWhiteSpace(item.Attributes[Iso19770_2.Discovery.Version])) { //select the packages that marked as "latest" and matches the name specified packages = (new Feed(request, new[] { item.HRef })).Query().FirstOrDefault(p => p.Name.EqualsIgnoreCase(item.Attributes[Iso19770_2.Discovery.Name])); } else { //select the packages that matches version and name packages = (new Feed(request, new[] { item.HRef })).Query(item.Attributes[Iso19770_2.Discovery.Name], item.Attributes[Iso19770_2.Discovery.Version]).FirstOrDefault(); } } if (packages == null) { // no package found request.Warning(Resources.Messages.NoDependencyPackageFound, item.HRef); continue; } // try to install dependent providers. If fails, continue InstallPackage(packages.Location.AbsoluteUri, request, errorContinue: true); } } // group the links along 'artifact' lines var artifacts = provider._swidtag.Links.Where(link => link.Relationship == Iso19770_2.Relationship.InstallationMedia).GroupBy(link => link.Artifact); // try one artifact set at a time. foreach (var artifact in artifacts) { // first time we succeed, we're good to go. foreach (var link in artifact) { switch (link.Attributes[Iso19770_2.Discovery.Type]) { case "assembly": if (InstallAssemblyProvider(provider, link, fastPath, request)) { return; } triedAndFailed = true; continue; default: if (InstallProviderFromInstaller(provider, link, fastPath, request)) { return; } triedAndFailed = true; continue; } } } if (triedAndFailed) { // we tried installing something and it didn't go well. var result = errorContinue ? request.Warning(Constants.Messages.FailedProviderBootstrap, fastPath) : request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.FailedProviderBootstrap, fastPath); } else { // we didn't even find a link to bootstrap. var result = errorContinue ? request.Warning(Resources.Messages.MissingInstallationmedia, fastPath) : request.Error(ErrorCategory.InvalidOperation, fastPath, Resources.Messages.MissingInstallationmedia, fastPath); } }
private bool InstallNugetPackage(Package provider, Link link, string fastPath, BootstrapRequest request) { // download the nuget package string downloadedNupkg = request.DownloadAndValidateFile(provider._swidtag); if (downloadedNupkg != null) { // extracted folder string extractedFolder = String.Concat(FilesystemExtensions.GenerateTemporaryFileOrDirectoryNameInTempDirectory()); try { //unzip the file ZipFile.ExtractToDirectory(downloadedNupkg, extractedFolder); if (Directory.Exists(extractedFolder)) { string versionFolder = Path.Combine(request.DestinationPath(request), provider.Name, provider.Version); // tool folder is where we find things like nuget.exe string toolFolder = Path.Combine(extractedFolder, "tools"); string libFolder = Path.Combine(extractedFolder, "lib"); // create the directory version folder if not exist if (!Directory.Exists(versionFolder)) { Directory.CreateDirectory(versionFolder); } // copy the tools directory if (Directory.Exists(toolFolder)) { string destinationToolFolder = Path.Combine(versionFolder, "tools"); if (!Directory.Exists(destinationToolFolder)) { Directory.CreateDirectory(destinationToolFolder); } foreach (string child in Directory.EnumerateFiles(toolFolder)) { try { // try copy and overwrite File.Copy(child, Path.Combine(destinationToolFolder, Path.GetFileName(child)), true); } catch (Exception e) { request.Debug(e.StackTrace); if (!(e is UnauthorizedAccessException || e is IOException)) { // something wrong, delete the version folder versionFolder.TryHardToDelete(); return(false); } // otherwise this means the file is just being used. so just moves on to copy other files } } } // copy files from lib if (Directory.Exists(libFolder)) { // check that the lib folder has at most 1 dll if (Directory.EnumerateFiles(libFolder).Count(file => String.Equals(Path.GetExtension(file), ".dll", StringComparison.OrdinalIgnoreCase)) > 1) { request.Warning(String.Format(CultureInfo.CurrentCulture, Resources.Messages.MoreThanOneDllExists, provider.Name)); return(false); } foreach (string child in Directory.EnumerateFiles(libFolder)) { try { File.Copy(child, Path.Combine(versionFolder, Path.GetFileName(child)), true); } catch (Exception e) { request.Debug(e.StackTrace); if (!(e is UnauthorizedAccessException || e is IOException)) { // something wrong, delete the version folder versionFolder.TryHardToDelete(); return(false); } // otherwise this means the file is just being used. so just moves on to copy other files } } } // target file name is the assembly provider string targetFile = Path.Combine(versionFolder, Path.GetFileName(link.Attributes[Iso19770_2.Discovery.TargetFilename])); if (File.Exists(targetFile)) { request.Verbose(Resources.Messages.InstalledPackage, provider.Name, targetFile); request.YieldFromSwidtag(provider, fastPath); return(true); } } } finally { downloadedNupkg.TryHardToDelete(); extractedFolder.TryHardToDelete(); } } return(false); }
private bool InstallProviderFromInstaller(Package provider, Link link, string fastPath, BootstrapRequest request) { switch (link.MediaType) { case Iso19770_2.MediaType.MsiPackage: case Iso19770_2.MediaType.MsuPackage: return InstallPackageFile(provider, fastPath, request); case Iso19770_2.MediaType.PackageReference: // let the core figure out how to install this package var packages = PackageManagementService.FindPackageByCanonicalId(link.HRef.AbsoluteUri, request).ToArray(); switch (packages.Length) { case 0: request.Warning("Unable to resolve package reference '{0}'", link.HRef); return false; case 1: return InstallPackageReference(provider, fastPath, request, packages); default: request.Warning("Package Reference '{0}' resolves to {1} packages.", packages.Length); return false; } case Iso19770_2.MediaType.NuGetPackage: return InstallNugetPackage(provider, link, fastPath, request); default: request.Warning("Provider '{0}' with link '{1}' has unknown media type '{2}'.", provider.Name, link.HRef, link.MediaType); return false; } }
private bool InstallPackageFile(Package provider, string fastPath, BootstrapRequest request) { // we can download and verify this package and get the core to install it. var file = request.DownloadAndValidateFile(provider.Name, provider._swidtag); if (file != null) { // we have a valid file. // run the installer if (request.ProviderServices.Install(file, "", request)) { // it installed ok! request.YieldFromSwidtag(provider, fastPath); PackageManagementService.LoadProviders(request.As<IRequest>()); return true; } request.Warning(Constants.Messages.FailedProviderBootstrap, fastPath); } return false; }
private bool InstallNugetPackage(Package provider, Link link, string fastPath, BootstrapRequest request) { // download the nuget package string downloadedNupkg = request.DownloadAndValidateFile(provider.Name, provider._swidtag); if (downloadedNupkg != null) { // extracted folder string extractedFolder = String.Concat(downloadedNupkg.GenerateTemporaryFilename()); try { //unzip the file ZipFile.ExtractToDirectory(downloadedNupkg, extractedFolder); if (Directory.Exists(extractedFolder)) { string versionFolder = Path.Combine(request.DestinationPath(request), provider.Name, provider.Version); // tool folder is where we find things like nuget.exe string toolFolder = Path.Combine(extractedFolder, "tools"); string libFolder = Path.Combine(extractedFolder, "lib"); // create the directory version folder if not exist if (!Directory.Exists(versionFolder)) { Directory.CreateDirectory(versionFolder); } // copy the tools directory if (Directory.Exists(toolFolder)) { string destinationToolFolder = Path.Combine(versionFolder, "tools"); if (!Directory.Exists(destinationToolFolder)) { Directory.CreateDirectory(destinationToolFolder); } foreach (string child in Directory.EnumerateFiles(toolFolder)) { try { // try copy and overwrite File.Copy(child, Path.Combine(destinationToolFolder, Path.GetFileName(child)), true); } catch (Exception e) { request.Debug(e.StackTrace); if (!(e is UnauthorizedAccessException || e is IOException)) { // something wrong, delete the version folder versionFolder.TryHardToDelete(); return false; } // otherwise this means the file is just being used. so just moves on to copy other files } } } // copy files from lib if (Directory.Exists(libFolder)) { // check that the lib folder has at most 1 dll if (Directory.EnumerateFiles(libFolder).Count(file => String.Equals(Path.GetExtension(file), ".dll", StringComparison.OrdinalIgnoreCase)) > 1) { request.Warning(String.Format(CultureInfo.CurrentCulture, Resources.Messages.MoreThanOneDllExists, provider.Name)); return false; } foreach (string child in Directory.EnumerateFiles(libFolder)) { try { File.Copy(child, Path.Combine(versionFolder, Path.GetFileName(child)), true); } catch (Exception e) { request.Debug(e.StackTrace); if (!(e is UnauthorizedAccessException || e is IOException)) { // something wrong, delete the version folder versionFolder.TryHardToDelete(); return false; } // otherwise this means the file is just being used. so just moves on to copy other files } } } // target file name is the assembly provider string targetFile = Path.Combine(versionFolder, Path.GetFileName(link.Attributes[Iso19770_2.Discovery.TargetFilename])); if (File.Exists(targetFile)) { request.Verbose(Resources.Messages.InstalledPackage, provider.Name, targetFile); request.YieldFromSwidtag(provider, fastPath); return true; } } } finally { downloadedNupkg.TryHardToDelete(); extractedFolder.TryHardToDelete(); } } return false; }
internal void InstallPackage(string fastPath, BootstrapRequest request, bool errorContinue) { if (fastPath == null) { throw new ArgumentNullException("fastPath"); } if (request == null) { throw new ArgumentNullException("request"); } // ensure that mandatory parameters are present. request.Debug("Calling 'Bootstrap::InstallPackage'"); var triedAndFailed = false; //source can be from install - packageprovider or can be from the pipeline if ((request.LocalSource.Any() || fastPath.IsFile())) { InstallPackageFromFile(fastPath, request); return; } // verify the package integrity (ie, check if it's digitally signed before installing) var provider = request.GetProvider(new Uri(fastPath)); if (provider == null || !provider.IsValid) { var result = errorContinue ? request.Warning(Constants.Messages.UnableToResolvePackage, fastPath) : request.Error(ErrorCategory.InvalidData, fastPath, Constants.Messages.UnableToResolvePackage, fastPath); return; } // first install the dependencies if any var dependencyLinks = provider._swidtag.Links.Where(link => link.Relationship == Iso19770_2.Relationship.Requires).GroupBy(link => link.Artifact); foreach (var depLinks in dependencyLinks) { foreach (var item in depLinks) { Package packages = null; if (string.IsNullOrWhiteSpace(item.Attributes[Iso19770_2.Discovery.Name])) { //select the packages that marked as "latest" packages = (new Feed(request, new[] {item.HRef})).Query().FirstOrDefault(); } else { if (string.IsNullOrWhiteSpace(item.Attributes[Iso19770_2.Discovery.Version])) { //select the packages that marked as "latest" and matches the name specified packages = (new Feed(request, new[] { item.HRef })).Query().FirstOrDefault(p => p.Name.EqualsIgnoreCase(item.Attributes[Iso19770_2.Discovery.Name])); } else { //select the packages that matches version and name packages = (new Feed(request, new[] { item.HRef })).Query(item.Attributes[Iso19770_2.Discovery.Name], item.Attributes[Iso19770_2.Discovery.Version]).FirstOrDefault(); } } if (packages == null) { // no package found request.Warning(Resources.Messages.NoDependencyPackageFound, item.HRef); continue; } // try to install dependent providers. If fails, continue InstallPackage(packages.Location.AbsoluteUri, request, errorContinue: true); } } // group the links along 'artifact' lines var artifacts = provider._swidtag.Links.Where(link => link.Relationship == Iso19770_2.Relationship.InstallationMedia).GroupBy(link => link.Artifact); // try one artifact set at a time. foreach (var artifact in artifacts) { // first time we succeed, we're good to go. foreach (var link in artifact) { switch (link.Attributes[Iso19770_2.Discovery.Type]) { case "assembly": if (InstallAssemblyProvider(provider, link, fastPath, request)) { return; } triedAndFailed = true; continue; default: if (InstallProviderFromInstaller(provider, link, fastPath, request)) { return; } triedAndFailed = true; continue; } } } if (triedAndFailed) { // we tried installing something and it didn't go well. var result = errorContinue ? request.Warning(Constants.Messages.FailedProviderBootstrap, fastPath) : request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.FailedProviderBootstrap, fastPath); } else { // we didn't even find a link to bootstrap. var result = errorContinue ? request.Warning(Resources.Messages.MissingInstallationmedia, fastPath) : request.Error(ErrorCategory.InvalidOperation, fastPath, Resources.Messages.MissingInstallationmedia, fastPath); } }