public async Task Initialize() { var nuGetDownloader = new NuGetDownloader(_options.LoggerFactory()); var nugetDownloadResult = await nuGetDownloader.DownloadAsync(PackagesFolder, _packageName, _packageVersion, _includePrerelease, _packageFeed, includeSecondaryRepositories : _options.IncludeSystemFeedsAsSecondary, targetFramework : _options.TargetFramework).ConfigureAwait(false); foreach (var f in nugetDownloadResult.PackageAssemblyFiles) { _pluginAssemblyFilePaths.Add(Path.Combine(PackagesFolder, f)); } foreach (var pluginAssemblyFilePath in _pluginAssemblyFilePaths) { var options = new AssemblyPluginCatalogOptions { TypeFinderOptions = _options.TypeFinderOptions, PluginNameOptions = _options.PluginNameOptions }; var downloadedRuntimeDlls = nugetDownloadResult.RunTimeDlls.Where(x => x.IsRecommended).ToList(); var runtimeAssemblyHints = new List <RuntimeAssemblyHint>(); foreach (var runTimeDll in downloadedRuntimeDlls) { var runtimeAssembly = new RuntimeAssemblyHint(runTimeDll.FileName, runTimeDll.FullFilePath, runTimeDll.IsNative); runtimeAssemblyHints.Add(runtimeAssembly); } options.PluginLoadContextOptions.RuntimeAssemblyHints = runtimeAssemblyHints; var assemblyCatalog = new AssemblyPluginCatalog(pluginAssemblyFilePath, options); await assemblyCatalog.Initialize(); _pluginCatalogs.Add(assemblyCatalog); } IsInitialized = true; }
public async Task Initialize() { var nuGetDownloader = new NuGetDownloader(_options.LoggerFactory()); var pluginAssemblyFileNames = await nuGetDownloader.DownloadAsync(PackagesFolder, _packageName, _packageVersion, _includePrerelease, _packageFeed); foreach (var f in pluginAssemblyFileNames) { _pluginAssemblyFilePaths.Add(Path.Combine(PackagesFolder, f)); } foreach (var pluginAssemblyFilePath in _pluginAssemblyFilePaths) { var options = new AssemblyPluginCatalogOptions { TypeFinderOptions = _options.TypeFinderOptions, PluginNameOptions = _options.PluginNameOptions }; var assemblyCatalog = new AssemblyPluginCatalog(pluginAssemblyFilePath, options); await assemblyCatalog.Initialize(); _pluginCatalogs.Add(assemblyCatalog); } IsInitialized = true; }
public async Task DownloadVersion(string version) { _logger.Info("Downloading the package using package name {PackageName} and version {Version}", _packageName, version); try { var package = await FindPackage(); var appVersionsFolder = _storageService.GetApplicationVersionsFolder(); var downloadedFiles = await _nuGetDownloader.DownloadAsync(package.Package, package.Repository, appVersionsFolder); _logger.Info("Files downloaded to {AppVersionsFolder}", appVersionsFolder); _logger.Debug("Downloaded the following files:"); foreach (var downloadedFile in downloadedFiles) { _logger.Debug("{FileName}", downloadedFile); } if (downloadedFiles.Any() != true) { _logger.Error("The package didn't contain any files. Unknown state."); } string launchCommand; var newVersionPackage = downloadedFiles.Single(x => x.EndsWith(".nupkg")); var newVersionRoot = Path.GetDirectoryName(newVersionPackage); if (string.IsNullOrWhiteSpace(Configuration.LaunchCommand)) { try { launchCommand = downloadedFiles.SingleOrDefault(x => x.EndsWith(".exe")); } catch (Exception e) { _logger.Error(e, "Failed to find executable from downloaded package. Does it contain many exe-files?"); throw; } } else { try { launchCommand = newVersionRoot + "/" + Configuration.LaunchCommand; } catch (Exception e) { _logger.Error(e, "Failed to set launch command based on parameter {LaunchCommand}", Configuration.LaunchCommand); throw; } } if (launchCommand == null) { _logger.Error("The package didn't contain an executable."); throw new Exception("The package didn't contain an executable."); } _logger.Info("Executable to the downloaded version is {ExeFile}", launchCommand); await _storageService.UpdatePendingVersionRoot(newVersionRoot); await _storageService.UpdatePendingVersion(version); await _storageService.UpdatePendingExe(launchCommand); } catch (Exception e) { _logger.Error(e, "Failed to download package using package name {PackageName} and version {Version}", _packageName, version); throw; } }