From c0f552949feebfd345b1fab7b80c6280b6a16fd0 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 10 Nov 2010 14:46:56 -0800 Subject: [PATCH] Updating the gallery module --HG-- branch : nuget --- .../Modules/Orchard.Packaging/AdminMenu.cs | 4 +- .../Commands/GalleryCommands.cs | 105 -------------- .../Controllers/GalleryController.cs | 49 +++---- .../DefaultPackagingUpdater.cs | 7 +- .../Modules/Orchard.Packaging/Migrations.cs | 16 +++ .../Models/PackagingSourceRecord.cs | 12 ++ .../Orchard.Packaging.csproj | 20 +-- .../Services/IPackageManager.cs | 3 - .../Services/IPackagingSourceManager.cs | 11 +- .../Services/PackageManager.cs | 50 ------- .../Services/PackagingEntry.cs | 14 +- .../Services/PackagingSource.cs | 2 +- .../Services/PackagingSourceManager.cs | 135 ++++++------------ .../PackagingExtensionsViewModel.cs | 11 ++ .../ViewModels/PackagingHarvestViewModel.cs | 4 +- .../ViewModels/PackagingModulesViewModel.cs | 10 -- .../ViewModels/PackagingSourcesViewModel.cs | 4 +- .../Views/Gallery/Modules.cshtml | 19 ++- .../Views/Gallery/Themes.cshtml | 2 +- 19 files changed, 151 insertions(+), 327 deletions(-) delete mode 100644 src/Orchard.Web/Modules/Orchard.Packaging/Commands/GalleryCommands.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Packaging/Migrations.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Packaging/Models/PackagingSourceRecord.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Packaging/ViewModels/PackagingExtensionsViewModel.cs delete mode 100644 src/Orchard.Web/Modules/Orchard.Packaging/ViewModels/PackagingModulesViewModel.cs diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/AdminMenu.cs b/src/Orchard.Web/Modules/Orchard.Packaging/AdminMenu.cs index 7730c5087..f34d93011 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/AdminMenu.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/AdminMenu.cs @@ -12,9 +12,9 @@ namespace Orchard.Packaging { public void GetNavigation(NavigationBuilder builder) { builder.Add(T("Gallery"), "30", menu => menu .Add(T("Modules"), "1.0", item => item - .Action("ModulesIndex", "Gallery", new { area = "Orchard.Packaging" })) + .Action("Modules", "Gallery", new { area = "Orchard.Packaging" })) .Add(T("Themes"), "2.0", item => item - .Action("ThemesIndex", "Gallery", new { area = "Orchard.Packaging" })) + .Action("Themes", "Gallery", new { area = "Orchard.Packaging" })) .Add(T("Feeds"), "3.0", item => item .Action("Sources", "Gallery", new { area = "Orchard.Packaging" }))); } diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Commands/GalleryCommands.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Commands/GalleryCommands.cs deleted file mode 100644 index 845fae08f..000000000 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Commands/GalleryCommands.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.IO; -using System.Net; -using Orchard.Commands; -using Orchard.Environment.Extensions; -using Orchard.Packaging.Services; - -namespace Orchard.Packaging.Commands { - [OrchardFeature("Gallery")] - public class GalleryCommands : DefaultOrchardCommandHandler { - private readonly IPackageManager _packageManager; - - [OrchardSwitch] - public string User { get; set; } - - [OrchardSwitch] - public string Password { get; set; } - - public GalleryCommands(IPackageManager packageManager) { - _packageManager = packageManager; - } - -#if false - [CommandHelp("harvest \r\n\t" + "Package a module into a distributable")] - [CommandName("harvest")] - public void PackageCreate(string moduleName) { - var packageData = _packageManager.Harvest(moduleName); - if (packageData.PackageStream.CanSeek) - packageData.PackageStream.Seek(0, SeekOrigin.Begin); - - const int chunk = 512; - var dataBuffer = new byte[3 * chunk]; - var charBuffer = new char[4 * chunk + 2]; - for (; ; ) { - var dataCount = packageData.PackageStream.Read(dataBuffer, 0, dataBuffer.Length); - if (dataCount <= 0) - return; - - var charCount = Convert.ToBase64CharArray(dataBuffer, 0, dataCount, charBuffer, 0); - Context.Output.Write(charBuffer, 0, charCount); - } - } -#endif - - [CommandHelp("gallery submit module /User: /Password:\r\n\t" + "Package a module into a distributable and push it to a feed server.")] - [CommandName("gallery submit module")] - [OrchardSwitches("User,Password")] - public void SubmitModule(string moduleName, string feedUrl) { - var packageData = _packageManager.Harvest(moduleName); - - if ( String.IsNullOrWhiteSpace(User) ) { - Context.Output.WriteLine(T("Missing or incorrect User")); - return; - } - - if ( String.IsNullOrWhiteSpace(Password) ) { - Context.Output.WriteLine(T("Missing or incorrect Password")); - return; - } - - try { - _packageManager.Push(packageData, feedUrl, User, Password); - Context.Output.WriteLine(T("Success")); - } - catch (WebException webException) { - string text = ""; - if (webException.Response != null) { - text = new StreamReader(webException.Response.GetResponseStream()).ReadToEnd(); - } - throw new ApplicationException(text); - } - } - - [CommandHelp("gallery submit package /User: /Password:\r\n\t" + "Push a packaged module to a feed server.")] - [CommandName("gallery submit package")] - [OrchardSwitches("User,Password")] - public void SubmitPackage(string filePath, string feedUrl) { - using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read)) { - var packageData = new PackageData { - PackageStream = stream - }; - - if ( String.IsNullOrWhiteSpace(User) ) { - Context.Output.WriteLine(T("Missing or incorrect User")); - return; - } - - if ( String.IsNullOrWhiteSpace(Password) ) { - Context.Output.WriteLine(T("Missing or incorrect Password")); - return; - } - - try { - _packageManager.Push(packageData, feedUrl, User, Password); - Context.Output.WriteLine(T("Success")); - } - catch (WebException webException) { - var text = new StreamReader(webException.Response.GetResponseStream()).ReadToEnd(); - throw new ApplicationException(text); - } - } - } - } -} - diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs index ecc8b7941..2289eee42 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs @@ -15,6 +15,7 @@ namespace Orchard.Packaging.Controllers { [OrchardFeature("Gallery")] [Themed, Admin] public class GalleryController : Controller { + private readonly IPackageManager _packageManager; private readonly IPackagingSourceManager _packagingSourceManager; private readonly IExtensionManager _extensionManager; @@ -34,24 +35,15 @@ namespace Orchard.Packaging.Controllers { Localizer T { get; set; } - public ActionResult ModulesIndex() { - return Modules(Guid.Empty); - } - - public ActionResult ThemesIndex() { - return Themes(Guid.Empty); - } - public ActionResult Sources() { return View(new PackagingSourcesViewModel { Sources = _packagingSourceManager.GetSources(), }); } - public ActionResult Remove(Guid id) { + public ActionResult Remove(int id) { _packagingSourceManager.RemoveSource(id); _notifier.Information(T("The feed has been removed successfully.")); - Update(null); return RedirectToAction("Sources"); } @@ -92,9 +84,9 @@ namespace Orchard.Packaging.Controllers { if ( !ModelState.IsValid ) return View(new PackagingAddSourceViewModel { Url = url }); - _packagingSourceManager.AddSource(new PackagingSource { Id = Guid.NewGuid(), FeedUrl = url, FeedTitle = title }); + _packagingSourceManager.AddSource(title, url); _notifier.Information(T("The feed has been added successfully.")); - Update(null); + return RedirectToAction("Sources"); } catch ( Exception exception ) { @@ -104,32 +96,36 @@ namespace Orchard.Packaging.Controllers { } - public ActionResult Modules(Guid? sourceId) { + public ActionResult Modules(int? sourceId) { var selectedSource = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault(); - return View("Modules", new PackagingModulesViewModel { - Modules = _packagingSourceManager.GetModuleList(selectedSource).Where(p => p.SyndicationItem.Categories.All(c => c.Name == "Orchard Module" || c.Name != "Orchard Theme")), + var sources = selectedSource != null + ? new [] { selectedSource } + : _packagingSourceManager.GetSources() + ; + + return View("Modules", new PackagingExtensionsViewModel { + Extensions = sources.SelectMany(source => _packagingSourceManager.GetModuleList(source)), Sources = _packagingSourceManager.GetSources().OrderBy(s => s.FeedTitle), SelectedSource = selectedSource }); } - public ActionResult Themes(Guid? sourceId) { + public ActionResult Themes(int? sourceId) { var selectedSource = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault(); - return View("Themes", new PackagingModulesViewModel { - Modules = _packagingSourceManager.GetModuleList(selectedSource).Where(p => p.SyndicationItem.Categories.Any(c => c.Name == "Orchard Theme")), + var sources = selectedSource != null + ? new[] { selectedSource } + : _packagingSourceManager.GetSources() + ; + + return View("Themes", new PackagingExtensionsViewModel { + Extensions = sources.SelectMany(source => _packagingSourceManager.GetThemeList(source)), Sources = _packagingSourceManager.GetSources().OrderBy(s => s.FeedTitle), SelectedSource = selectedSource }); } - public ActionResult Update(string cameFrom) { - _packagingSourceManager.UpdateLists(); - _notifier.Information(T("List of available modules and themes is updated.")); - return RedirectToAction(cameFrom == "Themes" ? "ThemesIndex" : "ModulesIndex"); - } - public ActionResult Harvest(string extensionName, string feedUrl) { return View(new PackagingHarvestViewModel { ExtensionName = extensionName, @@ -141,6 +137,7 @@ namespace Orchard.Packaging.Controllers { [HttpPost] public ActionResult Harvest(PackagingHarvestViewModel model) { + #if REFACTORING model.Sources = _packagingSourceManager.GetSources(); model.Extensions = _extensionManager.AvailableExtensions(); @@ -164,6 +161,10 @@ namespace Orchard.Packaging.Controllers { Update(null); return RedirectToAction("Harvest", new { model.ExtensionName, model.FeedUrl }); +#else + return View(); +#endif + } public ActionResult Install(string syndicationId, string cameFrom) { diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/DefaultPackagingUpdater.cs b/src/Orchard.Web/Modules/Orchard.Packaging/DefaultPackagingUpdater.cs index 0af950039..279557015 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/DefaultPackagingUpdater.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/DefaultPackagingUpdater.cs @@ -4,23 +4,20 @@ using Orchard.Environment.Extensions; using Orchard.Environment.Extensions.Models; using Orchard.Localization; using Orchard.Packaging.Services; -using Orchard.UI.Notify; namespace Orchard.Packaging { [OrchardFeature("Gallery")] public class DefaultPackagingUpdater : IFeatureEventHandler { private readonly IPackagingSourceManager _packagingSourceManager; - private readonly INotifier _notifier; - public DefaultPackagingUpdater(IPackagingSourceManager packagingSourceManager, INotifier notifier) { + public DefaultPackagingUpdater(IPackagingSourceManager packagingSourceManager) { _packagingSourceManager = packagingSourceManager; - _notifier = notifier; } public Localizer T { get; set; } public void Install(Feature feature) { - _packagingSourceManager.AddSource(new PackagingSource { Id = Guid.NewGuid(), FeedTitle = "Orchard Module Gallery", FeedUrl = "http://orchardproject.net/gallery08/feed" }); + _packagingSourceManager.AddSource( "Orchard Extensions Gallery", "http://feed.nuget.org/ctp2/odata/v1" ); } public void Enable(Feature feature) { diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Migrations.cs new file mode 100644 index 000000000..9464ace80 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Migrations.cs @@ -0,0 +1,16 @@ +using Orchard.Data.Migration; + +namespace Orchard.Packaging { + public class Migrations: DataMigrationImpl { + public int Create() { + SchemaBuilder.CreateTable("PackagingSourceRecord", + table => table + .Column("Id", column => column.PrimaryKey().Identity()) + .Column("FeedTitle", c => c.WithLength(255)) + .Column("FeedUrl", c => c.WithLength(2048)) + ); + + return 1; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Models/PackagingSourceRecord.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Models/PackagingSourceRecord.cs new file mode 100644 index 000000000..f4e4c7a8a --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Models/PackagingSourceRecord.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Orchard.Packaging.Models { + public class PackagingSourceRecord { + public virtual int Id { get; set; } + public virtual string FeedTitle { get; set; } + public virtual string FeedUrl { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Orchard.Packaging.csproj b/src/Orchard.Web/Modules/Orchard.Packaging/Orchard.Packaging.csproj index 4cc9514a4..10e6564ba 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Orchard.Packaging.csproj +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Orchard.Packaging.csproj @@ -36,7 +36,9 @@ + + @@ -70,11 +72,12 @@ - + + @@ -91,7 +94,7 @@ - + @@ -105,9 +108,7 @@ - - - + {F879F274-EFA0-4157-8404-33A19B4E6AEC} @@ -118,9 +119,6 @@ Orchard.Framework - - - Designer @@ -136,6 +134,12 @@ Designer + + + + + +