mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Handle exceptions in web command line
--HG-- branch : dev
This commit is contained in:
@@ -1,22 +1,30 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Commands;
|
using Orchard.Commands;
|
||||||
using Orchard.Experimental.ViewModels;
|
using Orchard.Experimental.ViewModels;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Localization;
|
||||||
using Orchard.Themes;
|
using Orchard.Themes;
|
||||||
using Orchard.UI.Admin;
|
using Orchard.UI.Admin;
|
||||||
|
using Orchard.UI.Notify;
|
||||||
|
|
||||||
namespace Orchard.Experimental.Controllers {
|
namespace Orchard.Experimental.Controllers {
|
||||||
[Themed, Admin, OrchardFeature("Orchard.Experimental.WebCommandLine")]
|
[Themed, Admin, OrchardFeature("Orchard.Experimental.WebCommandLine")]
|
||||||
public class CommandsController : Controller {
|
public class CommandsController : Controller {
|
||||||
private readonly ICommandManager _commandManager;
|
private readonly ICommandManager _commandManager;
|
||||||
|
|
||||||
public CommandsController(ICommandManager commandManager) {
|
public CommandsController(ICommandManager commandManager, IOrchardServices services) {
|
||||||
_commandManager = commandManager;
|
_commandManager = commandManager;
|
||||||
|
Services = services;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IOrchardServices Services { get; set; }
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public ActionResult Index() {
|
public ActionResult Index() {
|
||||||
return Execute();
|
return Execute();
|
||||||
}
|
}
|
||||||
@@ -27,6 +35,7 @@ namespace Orchard.Experimental.Controllers {
|
|||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Execute(CommandsExecuteViewModel model) {
|
public ActionResult Execute(CommandsExecuteViewModel model) {
|
||||||
|
try {
|
||||||
using (var writer = new StringWriter()) {
|
using (var writer = new StringWriter()) {
|
||||||
var commandLine = model.CommandLine.Trim();
|
var commandLine = model.CommandLine.Trim();
|
||||||
CommandParameters parameters = GetCommandParameters(commandLine, writer);
|
CommandParameters parameters = GetCommandParameters(commandLine, writer);
|
||||||
@@ -38,6 +47,11 @@ namespace Orchard.Experimental.Controllers {
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
model.Results = writer.ToString();
|
model.Results = writer.ToString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(Exception exception) {
|
||||||
|
Services.Notifier.Error(T("Error executing command: {0}", exception.Message));
|
||||||
|
Services.TransactionManager.Cancel();
|
||||||
|
}
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user