2010-07-04 14:14:15 -07:00
|
|
|
|
using System;
|
2010-07-06 18:56:55 -07:00
|
|
|
|
using System.Linq;
|
2010-07-04 14:14:15 -07:00
|
|
|
|
using System.Web.Mvc;
|
2010-07-11 15:41:16 -07:00
|
|
|
|
using Futures.Modules.Packaging.Services;
|
|
|
|
|
using Futures.Modules.Packaging.ViewModels;
|
2010-07-04 14:14:15 -07:00
|
|
|
|
using Orchard.Environment.Extensions;
|
2010-07-06 18:56:55 -07:00
|
|
|
|
using Orchard.Localization;
|
2010-07-04 14:14:15 -07:00
|
|
|
|
using Orchard.Themes;
|
|
|
|
|
using Orchard.UI.Admin;
|
2010-07-06 18:56:55 -07:00
|
|
|
|
using Orchard.UI.Notify;
|
2010-07-04 14:14:15 -07:00
|
|
|
|
|
2010-07-11 15:41:16 -07:00
|
|
|
|
namespace Futures.Modules.Packaging.Controllers {
|
|
|
|
|
[Themed, Admin]
|
2010-07-04 14:14:15 -07:00
|
|
|
|
public class PackagingController : Controller {
|
2010-07-06 18:56:55 -07:00
|
|
|
|
private readonly IPackageManager _packageManager;
|
|
|
|
|
private readonly IPackageSourceManager _packageSourceManager;
|
|
|
|
|
private readonly IExtensionManager _extensionManager;
|
|
|
|
|
private readonly INotifier _notifier;
|
2010-07-04 14:14:15 -07:00
|
|
|
|
|
2010-07-06 18:56:55 -07:00
|
|
|
|
public PackagingController(
|
|
|
|
|
IPackageManager packageManager,
|
|
|
|
|
IPackageSourceManager packageSourceManager,
|
|
|
|
|
IExtensionManager extensionManager,
|
|
|
|
|
INotifier notifier) {
|
|
|
|
|
_packageManager = packageManager;
|
|
|
|
|
_packageSourceManager = packageSourceManager;
|
|
|
|
|
_extensionManager = extensionManager;
|
|
|
|
|
_notifier = notifier;
|
|
|
|
|
T = NullLocalizer.Instance;
|
2010-07-04 14:14:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 18:56:55 -07:00
|
|
|
|
Localizer T { get; set; }
|
|
|
|
|
|
2010-07-04 14:14:15 -07:00
|
|
|
|
public ActionResult Index() {
|
|
|
|
|
return Modules();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Sources() {
|
2010-07-06 18:56:55 -07:00
|
|
|
|
return View("Sources", new PackagingSourcesViewModel {
|
|
|
|
|
Sources = _packageSourceManager.GetSources(),
|
2010-07-04 14:14:15 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult AddSource(string url) {
|
2010-07-06 18:56:55 -07:00
|
|
|
|
_packageSourceManager.AddSource(new PackageSource { Id = Guid.NewGuid(), FeedUrl = url });
|
|
|
|
|
Update();
|
|
|
|
|
return RedirectToAction("Sources");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ActionResult Modules() {
|
|
|
|
|
return View("Modules", new PackagingModulesViewModel {
|
|
|
|
|
Modules = _packageSourceManager.GetModuleList()
|
|
|
|
|
});
|
2010-07-04 14:14:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Update() {
|
2010-07-06 18:56:55 -07:00
|
|
|
|
_packageSourceManager.UpdateLists();
|
|
|
|
|
_notifier.Information(T("List of available modules and themes is updated."));
|
2010-07-04 14:14:15 -07:00
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 18:56:55 -07:00
|
|
|
|
public ActionResult Harvest(string extensionName, string feedUrl) {
|
|
|
|
|
return View("Harvest", new PackagingHarvestViewModel {
|
|
|
|
|
ExtensionName = extensionName,
|
|
|
|
|
FeedUrl = feedUrl,
|
|
|
|
|
Sources = _packageSourceManager.GetSources(),
|
|
|
|
|
Extensions = _extensionManager.AvailableExtensions()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult Harvest(PackagingHarvestViewModel model) {
|
|
|
|
|
model.Sources = _packageSourceManager.GetSources();
|
|
|
|
|
model.Extensions = _extensionManager.AvailableExtensions();
|
|
|
|
|
|
|
|
|
|
var packageData = _packageManager.Harvest(model.ExtensionName);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.FeedUrl)) {
|
|
|
|
|
return new DownloadStreamResult(
|
|
|
|
|
packageData.ExtensionName + "-" + packageData.ExtensionVersion + ".zip",
|
|
|
|
|
"application/x-package",
|
|
|
|
|
packageData.PackageStream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!model.Sources.Any(src => src.FeedUrl == model.FeedUrl)) {
|
|
|
|
|
ModelState.AddModelError("FeedUrl", T("May only push directly to one of the configured sources.").ToString());
|
|
|
|
|
return View("Harvest", model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_packageManager.Push(packageData, model.FeedUrl);
|
|
|
|
|
_notifier.Information(T("Harvested {0} and published onto {1}", model.ExtensionName, model.FeedUrl));
|
|
|
|
|
|
|
|
|
|
Update();
|
|
|
|
|
|
|
|
|
|
return RedirectToAction("Harvest", new { model.ExtensionName, model.FeedUrl });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Install(string syndicationId) {
|
|
|
|
|
var packageData = _packageManager.Download(syndicationId);
|
|
|
|
|
_packageManager.Install(packageData);
|
|
|
|
|
_notifier.Information(T("Installed module"));
|
|
|
|
|
return RedirectToAction("Modules");
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-04 14:14:15 -07:00
|
|
|
|
}
|