private static PackagingEntry CreatePackageEntry(PublishedPackage package, PackagingSource source, Uri downloadUri) { var baseUri = new Uri(string.Format("{0}://{1}:{2}/", downloadUri.Scheme, downloadUri.Host, downloadUri.Port)); PublishedScreenshot screenshot = package.Screenshots != null?package.Screenshots.FirstOrDefault() : null; string iconUrl = GetAbsoluteUri(package.IconUrl, baseUri); string firstScreenshot = screenshot != null?GetAbsoluteUri(screenshot.ScreenshotUri, baseUri) : string.Empty; return(new PackagingEntry { Title = string.IsNullOrWhiteSpace(package.Title) ? package.Id : package.Title, PackageId = package.Id, PackageStreamUri = downloadUri.ToString(), ProjectUrl = package.ProjectUrl, GalleryDetailsUrl = package.GalleryDetailsUrl, Source = source, Version = package.Version ?? string.Empty, Description = package.Description, Authors = package.Authors, LastUpdated = package.LastUpdated, IconUrl = iconUrl, FirstScreenshot = firstScreenshot, Rating = package.Rating, RatingsCount = package.RatingsCount, DownloadCount = package.DownloadCount }); }
private IEnumerable <UpdatePackageEntry> GetPackagesWorker(PackagingSource packagingSource) { var list = new Dictionary <string, UpdatePackageEntry>(StringComparer.OrdinalIgnoreCase); var extensions = _extensionManager.AvailableExtensions(); foreach (var extension in extensions) { var packageId = PackageBuilder.BuildPackageId(extension.Id, extension.ExtensionType); GetOrAddEntry(list, packageId).ExtensionsDescriptor = extension; } var packages = _packagingSourceManager.GetExtensionList(false, packagingSource) .ToList() .GroupBy(p => p.PackageId, StringComparer.OrdinalIgnoreCase); foreach (var package in packages) { var entry = GetOrAddEntry(list, package.Key); entry.PackageVersions = entry.PackageVersions.Concat(package).ToList(); } return(list.Values.Where(e => e.ExtensionsDescriptor != null && e.PackageVersions.Any())); }
/// <summary> /// Adds a new feed sources. /// </summary> /// <param name="feedTitle">The feed title.</param> /// <param name="feedUrl">The feed url.</param> /// <returns>The feed identifier.</returns> public int AddSource(string feedTitle, string feedUrl) { var packagingSource = new PackagingSource { FeedTitle = feedTitle, FeedUrl = feedUrl }; _packagingSourceRecordRepository.Create(packagingSource); return(packagingSource.Id); }
/// <summary> /// Retrieves the number of extensions from a feed source. /// </summary> /// <param name="packagingSource">The packaging source from where to get the extensions.</param> /// <param name="query">The optional query to retrieve the extensions.</param> /// <returns>The number of extensions from a feed source.</returns> public int GetExtensionCount(PackagingSource packagingSource = null, Func <IQueryable <PublishedPackage>, IQueryable <PublishedPackage> > query = null) { return((packagingSource == null ? GetSources() : new[] { packagingSource }) .Sum(source => { var galleryFeedContext = new GalleryFeedContext(new Uri(source.FeedUrl)); IQueryable <PublishedPackage> packages = galleryFeedContext.Packages; if (query != null) { packages = query(packages); } return packages.Count(); } )); }
private PackagesStatusResult GetPackages(PackagingSource packagingSource) { return(_cacheManager.Get(packagingSource.FeedUrl, ctx => { // Refresh every minute or when signal was triggered ctx.Monitor(_clock.When(TimeSpan.FromMinutes(5))); ctx.Monitor(_signals.When("PackageUpdateService")); // We cache exception because we are calling on a network feed, and failure may // take quite some time. var result = new PackagesStatusResult { Entries = new List <UpdatePackageEntry>(), Errors = new List <Exception>() }; try { result.Entries = GetPackagesWorker(packagingSource); } catch (Exception e) { result.Errors = new[] { e }; } return result; })); }
public int GetExtensionCount(PackagingSource packagingSource = null, Func <IQueryable <PublishedPackage>, IQueryable <PublishedPackage> > query = null) { throw new NotImplementedException(); }
public IEnumerable <PackagingEntry> GetExtensionList(bool includeScreenshots, PackagingSource packagingSource = null, Func <IQueryable <PublishedPackage>, IQueryable <PublishedPackage> > query = null) { return(query(_publishedPackages.AsQueryable()).Select(package => CreatePackagingEntry(package))); }
// <Module packageId="module1" [repository="somerepo"] version="1.1" /> // install modules from feed. public void ExecuteRecipeStep(RecipeContext recipeContext) { if (!String.Equals(recipeContext.RecipeStep.Name, "Module", StringComparison.OrdinalIgnoreCase)) { return; } string packageId = null, version = null, repository = null; foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) { if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) { packageId = attribute.Value; } else if (String.Equals(attribute.Name.LocalName, "version", StringComparison.OrdinalIgnoreCase)) { version = attribute.Value; } else if (String.Equals(attribute.Name.LocalName, "repository", StringComparison.OrdinalIgnoreCase)) { repository = attribute.Value; } else { throw new InvalidOperationException(string.Format("Unrecognized attribute {0} encountered in step Module.", attribute.Name.LocalName)); } } if (packageId == null) { throw new InvalidOperationException("PackageId is required in a Module declaration in a recipe file."); } // download and install module from the orchard feed or a custom feed if repository is specified. bool enforceVersion = version != null; bool installed = false; PackagingEntry packagingEntry = null; var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault(); if (repository != null) { packagingSource = new PackagingSource { FeedTitle = repository, FeedUrl = repository }; } if (enforceVersion) { packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource, packages => packages.Where(package => package.PackageType.Equals(DefaultExtensionTypes.Module) && package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) && package.Version.Equals(version, StringComparison.OrdinalIgnoreCase))).FirstOrDefault(); } else { packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource, packages => packages.Where(package => package.PackageType.Equals(DefaultExtensionTypes.Module) && package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) && package.IsLatestVersion)).FirstOrDefault(); } if (packagingEntry != null) { if (!ModuleAlreadyInstalled(packagingEntry.PackageId)) { _packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/")); } installed = true; } if (!installed) { throw new InvalidOperationException(string.Format("Module {0} was not found in the specified location.", packageId)); } recipeContext.Executed = true; }
public IEnumerable<PackagingEntry> GetExtensionList(bool includeScreenshots, PackagingSource packagingSource = null, Func<IQueryable<PublishedPackage>, IQueryable<PublishedPackage>> query = null) { return new[] { new PackagingEntry { PackageId = "Orchard.Module.SuperWiki", Title = "SuperWiki", Version = "1.0.3" } }; }
private static IEnumerable <PackagingEntry> GetExtensionListFromSource(bool includeScreenshots, PackagingSource packagingSource, Func <IQueryable <PublishedPackage>, IQueryable <PublishedPackage> > query, PackagingSource source) { var galleryFeedContext = new GalleryFeedContext(new Uri(source.FeedUrl)) { IgnoreMissingProperties = true }; // Setup compression galleryFeedContext.SendingRequest += (o, e) => { if (e.Request is HttpWebRequest) { (e.Request as HttpWebRequest).AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } }; // Include screenshots if needed IQueryable <PublishedPackage> packages = includeScreenshots ? galleryFeedContext.Packages.Expand("Screenshots") : galleryFeedContext.Packages; if (query != null) { packages = query(packages); } return(packages.ToList().Select(p => CreatePackageEntry(p, packagingSource, galleryFeedContext.GetReadStreamUri(p)))); }
/// <summary> /// Retrieves the list of extensions from a feed source. /// </summary> /// <param name="includeScreenshots">Specifies if screenshots should be included in the result.</param> /// <param name="packagingSource">The packaging source from where to get the extensions.</param> /// <param name="query">The optional query to retrieve the extensions.</param> /// <returns>The list of extensions.</returns> public IEnumerable <PackagingEntry> GetExtensionList(bool includeScreenshots, PackagingSource packagingSource = null, Func <IQueryable <PublishedPackage>, IQueryable <PublishedPackage> > query = null) { return((packagingSource == null ? GetSources() : new[] { packagingSource }) .SelectMany(source => GetExtensionListFromSource(includeScreenshots, packagingSource, query, source))); }
/// <summary> /// Retrieves the list of extensions from a feed source. /// </summary> /// <param name="includeScreenshots">Specifies if screenshots should be included in the result.</param> /// <param name="packagingSource">The packaging source from where to get the extensions.</param> /// <param name="query">The optional query to retrieve the extensions.</param> /// <returns>The list of extensions.</returns> public IEnumerable <PackagingEntry> GetExtensionList(bool includeScreenshots, PackagingSource packagingSource = null, Func <IQueryable <PublishedPackage>, IQueryable <PublishedPackage> > query = null) { return((packagingSource == null ? GetSources() : new[] { packagingSource }) .SelectMany( source => { var galleryFeedContext = new GalleryFeedContext(new Uri(source.FeedUrl)); IQueryable <PublishedPackage> packages = includeScreenshots ? galleryFeedContext.Packages.Expand("Screenshots") : galleryFeedContext.Packages; if (query != null) { packages = query(packages); } return packages.ToList().Select(p => CreatePackageEntry(p, packagingSource, galleryFeedContext.GetReadStreamUri(p))); } )); }
// <Theme packageId="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" /> // Install themes from feed. public override void Execute(RecipeExecutionContext context) { bool enable = false, current = false; string packageId = null, version = null, repository = null; foreach (var attribute in context.RecipeStep.Step.Attributes()) { if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) { enable = Boolean.Parse(attribute.Value); } else if (String.Equals(attribute.Name.LocalName, "current", StringComparison.OrdinalIgnoreCase)) { current = Boolean.Parse(attribute.Value); } else if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) { packageId = attribute.Value; } else if (String.Equals(attribute.Name.LocalName, "version", StringComparison.OrdinalIgnoreCase)) { version = attribute.Value; } else if (String.Equals(attribute.Name.LocalName, "repository", StringComparison.OrdinalIgnoreCase)) { repository = attribute.Value; } else { Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName); } } if (packageId == null) { throw new InvalidOperationException("The PackageId attribute is required on a Theme declaration in a recipe file."); } // Download and install theme from the orchard feed or a custom feed if repository is specified. var enforceVersion = version != null; var installed = false; PackagingEntry packagingEntry = null; var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault(); if (repository != null) { packagingSource = new PackagingSource { FeedTitle = repository, FeedUrl = repository }; } if (enforceVersion) { packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource, packages => packages.Where(package => package.PackageType.Equals(DefaultExtensionTypes.Theme) && package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) && package.Version.Equals(version, StringComparison.OrdinalIgnoreCase))).FirstOrDefault(); } else { packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource, packages => packages.Where(package => package.PackageType.Equals(DefaultExtensionTypes.Theme) && package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) && package.IsLatestVersion)).FirstOrDefault(); } if (packagingEntry != null) { if (!ThemeAlreadyInstalled(packagingEntry.PackageId)) { Logger.Information("Installing theme package '{0}'.", packagingEntry.PackageId); _packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/")); } if (current) { Logger.Information("Enabling theme '{0}'.", packagingEntry.Title); _themeService.EnableThemeFeatures(packagingEntry.Title); Logger.Information("Setting theme '{0}' as the site theme.", packagingEntry.Title); _siteThemeService.SetSiteTheme(packagingEntry.Title); } else if (enable) { Logger.Information("Enabling theme '{0}'.", packagingEntry.Title); _themeService.EnableThemeFeatures(packagingEntry.Title); } installed = true; } if (!installed) { throw new InvalidOperationException(String.Format("Theme '{0}' was not found in the specified location.", packageId)); } }