Enabling installation of packages from Orchard web app

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-11-12 13:23:39 -08:00
parent 686a9e6f4d
commit 3aa26ade9c
10 changed files with 40 additions and 104 deletions

View File

@@ -1,4 +1,6 @@
using System.IO;
using System;
using System.IO;
using System.Web;
using System.Web.Hosting;
using Orchard.Commands;
using Orchard.Environment.Extensions;
@@ -53,21 +55,34 @@ namespace Orchard.Packaging.Commands {
[CommandName("package install")]
[OrchardSwitches("Version")]
public void InstallPackage(string packageId, string location) {
_packageManager.Install(packageId, Version, Path.GetFullPath(location), ApplicationPath);
foreach(var message in _notifier.List()) {
Context.Output.WriteLine(message.Message);
try {
_packageManager.Install(packageId, Version, Path.GetFullPath(location), ApplicationPath);
foreach (var message in _notifier.List()) {
Context.Output.WriteLine(message.Message);
}
}
catch(Exception e) {
// Exceptions area thrown by NuGet as error messages
Context.Output.WriteLine(HttpUtility.HtmlDecode(T("Could not install the package: {0}", e.Message).Text));
}
}
[CommandHelp("package uninstall <packageId> \r\n\t" + "Uninstall a module or a theme.")]
[CommandName("package uninstall")]
public void UninstallPackage(string packageId) {
_packageManager.Uninstall(packageId, ApplicationPath);
try {
_packageManager.Uninstall(packageId, ApplicationPath);
foreach ( var message in _notifier.List() ) {
Context.Output.WriteLine(message.Message);
foreach ( var message in _notifier.List() ) {
Context.Output.WriteLine(message.Message);
}
}
catch(Exception e) {
// Exceptions area thrown by NuGet as error messages
Context.Output.WriteLine(HttpUtility.HtmlDecode(T("Could not unintall the package: {0}", e.Message).Text));
}
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Web.Hosting;
using System.Web.Mvc;
using System.Xml.Linq;
using Orchard.Environment.Extensions;
@@ -126,54 +127,16 @@ namespace Orchard.Packaging.Controllers {
});
}
public ActionResult Harvest(string extensionName, string feedUrl) {
return View(new PackagingHarvestViewModel {
ExtensionName = extensionName,
FeedUrl = feedUrl,
Sources = _packagingSourceManager.GetSources(),
Extensions = _extensionManager.AvailableExtensions()
});
}
public ActionResult Install(string packageId, string version, int sourceId, string redirectTo) {
var source = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
[HttpPost]
public ActionResult Harvest(PackagingHarvestViewModel model) {
#if REFACTORING
model.Sources = _packagingSourceManager.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(source == null) {
return HttpNotFound();
}
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(model);
}
_packageManager.Install(packageId, version, source.FeedUrl, HostingEnvironment.MapPath("~/"));
_packageManager.Push(packageData, model.FeedUrl, model.User, model.Password);
_notifier.Information(T("Harvested {0} and published onto {1}", model.ExtensionName, model.FeedUrl));
Update(null);
return RedirectToAction("Harvest", new { model.ExtensionName, model.FeedUrl });
#else
return View();
#endif
}
public ActionResult Install(string syndicationId, string cameFrom) {
#if REFACTORING
var packageData = _packageManager.Download(syndicationId);
_packageManager.Install(packageData.PackageStream);
_notifier.Information(T("Installed module"));
#endif
return RedirectToAction(cameFrom == "Themes" ? "ThemesIndex" : "ModulesIndex");
return RedirectToAction(redirectTo == "Themes" ? "Themes" : "Modules");
}
}
}

View File

@@ -108,10 +108,8 @@
<Content Include="Module.txt" />
<Content Include="Styles\admin.css" />
<Content Include="Views\Gallery\AddSource.cshtml" />
<Content Include="Views\Gallery\Harvest.cshtml" />
<Content Include="Views\Gallery\Modules.cshtml" />
<Content Include="Views\Gallery\Sources.cshtml" />
<Content Include="Views\Gallery\_Subnav.cshtml" />
<Content Include="Views\Web.config" />
</ItemGroup>
<ItemGroup />

View File

@@ -1,7 +1,7 @@
namespace Orchard.Packaging.Services {
public interface IPackageManager : IDependency {
PackageData Harvest(string extensionName);
PackageInfo Install(string packageId, string version, string location, string solutionFolder);
void Uninstall(string packageId, string solutionFolder);
PackageInfo Install(string packageId, string version, string location, string applicationPath);
void Uninstall(string packageId, string applicationPath);
}
}

View File

@@ -72,7 +72,7 @@ namespace Orchard.Packaging.Services {
var project = new FileBasedProjectSystem(applicationPath) { Logger = logger };
var projectManager = new ProjectManager(
sourceRepository, // source repository for the package to install
new DefaultPackagePathResolver(location),
new DefaultPackagePathResolver(applicationPath),
project,
new ExtensionReferenceRepository(project, sourceRepository, _extensionManager)
) {Logger = logger};

View File

@@ -33,12 +33,12 @@ namespace Orchard.Packaging.Services {
};
}
public PackageInfo Install(string packageId, string version, string location, string solutionFolder) {
return _packageExpander.Install(packageId, version, location, solutionFolder);
public PackageInfo Install(string packageId, string version, string location, string applicationPath) {
return _packageExpander.Install(packageId, version, location, applicationPath);
}
public void Uninstall(string packageId, string solutionFolder) {
_packageExpander.Uninstall(packageId, solutionFolder);
public void Uninstall(string packageId, string applicationPath) {
_packageExpander.Uninstall(packageId, applicationPath);
}
#endregion
}

View File

@@ -1,32 +0,0 @@
@model Orchard.Packaging.ViewModels.PackagingHarvestViewModel
<h1>
@Html.TitleForPage(T("Packaging").ToString(), T("Harvest Packages").ToString())</h1>
@Html.Partial("_Subnav", Model)
@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary(T("Package creation was unsuccessful. Please correct the errors and try again.").ToString())
foreach (var group in Model.Extensions.Where(x => !x.Location.StartsWith("~/Core")).GroupBy(x => x.ExtensionType)) {
<fieldset>
<legend>@T("Harvest") @group.Key</legend>
<ul>
@foreach (var item in group) {
<li>
<label>
@Html.RadioButtonFor(m=>m.ExtensionName, item.Name, new Dictionary<string, object>{{"id",item.Name}})
@item.DisplayName
</label>
</li>
}
</ul>
@Html.ValidationMessageFor(m => m.ExtensionName)
</fieldset>
}
<fieldset>
@Html.LabelFor(m => m.FeedUrl, T("Feed Url"))
@Html.DropDownListFor(m => m.FeedUrl, new[]{new SelectListItem{Text=T("Download").ToString(),Value=""}}.Concat( Model.Sources.Select(x => new SelectListItem { Text = T("Push to {0}", x.FeedUrl).ToString(), Value = x.FeedUrl })))
@Html.ValidationMessageFor(m=>m.FeedUrl)
</fieldset>
<fieldset>
<button class="primaryAction" type="submit">@T("Harvest")</button>
</fieldset>
}

View File

@@ -28,14 +28,14 @@
</div>
<div class="related">
@Html.ActionLink(T("Install").ToString(), "Install", new RouteValueDictionary {{"SyndicationId", item.PackageId},{"cameFrom", "Modules"}})@T(" | ")
@Html.ActionLink(T("Install").ToString(), "Install", new RouteValueDictionary {{"packageId", item.PackageId}, {"version", item.Version}, {"sourceId", item.Source.Id}, {"cameFrom", "Modules"}})@T(" | ")
<a href="@item.PackageStreamUri">@T("Download")</a>
</div>
<div class="properties">
<p>@(item.Description == null ? T("(No description").Text : item.Description)</p>
<ul class="pageStatus">
@*todo: (sebros) find a way to get the update date*@<li style="color:red">@T("Last Updated: {0}", DateTime.Now.ToLocalTime())</li>
<li>@T("Last Updated: {0}", DateTime.Now.ToLocalTime())</li>
<li>&nbsp;&#124;&nbsp;@T("Author: {0}", item.Authors)</li>
</ul>
</div>

View File

@@ -35,7 +35,7 @@
<div class="properties">
<p>@(item.Description == null ? T("(No description").Text : item.Description)</p>
<ul class="pageStatus">
@*todo: (sebros) find a way to get the update date*@<li style="color:red">@T("Last Updated: {0}", DateTime.Now.ToLocalTime())</li>
<li>@T("Last Updated: {0}", DateTime.Now.ToLocalTime())</li>
<li>&nbsp;&#124;&nbsp;@T("Author: {0}", item.Authors)</li>
</ul>
</div>

View File

@@ -1,8 +0,0 @@
@model Orchard.Packaging.ViewModels.PackagingHarvestViewModel
<p>
@Html.ActionLink(T("Browse Repository Packages").ToString(), "Index")
&bull;
@Html.ActionLink(T("Harvest Local Packages").ToString(), "Harvest")
&bull;
@Html.ActionLink(T("Edit Repository Sources").ToString(), "Sources")
</p>