public async Task <string?> RestoreAsync(ExtensionSource source, CancellationToken token) { if (source is null) { throw new ArgumentNullException(nameof(source)); } if (string.IsNullOrEmpty(source.Version)) { _logger.LogWarning("Cannot restore a source {Name} with no version", source.Name); return(null); } var path = _extensionLocator.GetInstallPath(source); if (Directory.Exists(path)) { _logger.LogDebug("{Name} is already restored at {Path}", source.Name, path); return(path); } _logger.LogDebug("Creating directory {Path} for extension {Name}", path, source.Name); Directory.CreateDirectory(path); var package = new NuGetReference(source.Name, source.Version); if (await _packageDownloader.Value.DownloadPackageToDirectoryAsync(path, package, source.Source ?? _options.Value.DefaultSource, token).ConfigureAwait(false)) { return(path); } Directory.Delete(path, true); return(null); }
public async Task <string?> GetLatestVersionAsync(ExtensionSource n, CancellationToken token) { if (n is null) { throw new ArgumentNullException(nameof(n)); } var result = await _packageDownloader.Value.GetNuGetReference(n.Name, n.Version, n.Source ?? _options.Value.DefaultSource, token).ConfigureAwait(false); return(result?.Version); }
public string GetInstallPath(ExtensionSource extensionSource) { if (extensionSource is null) { throw new ArgumentNullException(nameof(extensionSource)); } if (string.IsNullOrEmpty(extensionSource.Version)) { throw new UpgradeException("Cannot get path of source without version"); } var sourcePath = GetSourceForPath(extensionSource.Source); return(Path.Combine(_options.Value.ExtensionCachePath, sourcePath, extensionSource.Name, extensionSource.Version)); }
private void SetupMusicProvider(MusicProvider provider) { // Setup the content groups if (provider.Content != null) { foreach (var group in provider.Content) { // Extract any passed in buttons var buttons = new List <ContentButton>(); if (group.Buttons != null) { foreach (var buttonString in group.Buttons) { switch (buttonString) { case "PlayAllButton": buttons.Add(new PlayContentButton()); break; case "ShufflePlayButton": buttons.Add(new ShufflePlayContentButton()); break; } } } // Create the source and group var source = new ExtensionSource(this, group.OnGet); var contentGroup = new ContentGroup(source, group.Title, buttons, (parent) => { if (group.OnViewMore != null) { CallFunction(group.OnViewMore, parent); } }); // Parse the area var location = Enum.Parse <ContentArea>(group.Area); // Add the content group SimpleIoc.Default.GetInstance <IContentService>().AddContent(Identifier, location, contentGroup); } } }
public async Task <ExtensionSource?> AddAsync(ExtensionSource n, CancellationToken token) { if (n is null) { throw new ArgumentNullException(nameof(n)); } if (string.IsNullOrEmpty(n.Version)) { var version = await _extensionDownloader.Value.GetLatestVersionAsync(n, token).ConfigureAwait(false); if (version is null) { _logger.LogError("Could not find a version for extension {Name}", n.Name); return(null); } n = n with { Version = version }; _logger.LogInformation("Found version for extension {Name}: {Version}", n.Name, n.Version); } var path = await _extensionDownloader.Value.RestoreAsync(n, token).ConfigureAwait(false); if (path is null) { _logger.LogError("Could not install extension {Name} [{Version}] from {Source}", n.Name, n.Version, n.Source); return(null); } var config = _configurationLoader.Load(); var updated = config with { Extensions = config.Extensions.Add(n) }; _configurationLoader.Save(updated); return(n); }
public void TestGetPathExtensions(string pathExtensionsEnvironmentVariable, IEnumerable<string> expectedExtensions) { IEnumerable<string> result = new ExtensionSource().GetExtensions(pathExtensionsEnvironmentVariable, DirectorySource.PathSeparator); Assert.That(result, Is.EquivalentTo(expectedExtensions)); }