mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 12:09:41 +08:00
IExceptionPolicy concept and default implementation.
Updating EventBus and UnhandledExceptionFilter to use the exception policy. Adding OrchardFatalException. Updating text on default error page. (Part II) Removing the unhandled "catch" from module controllers. If there are "expected" exceptions, move them closer to the APIs where they occur. Removing ControllerExtensions.Error and refactoring. --HG-- branch : 1.x extra : transplant_source : %5C9a%E2%9A%F4%ACI%A3F%3C%D2%5C%CC%5C%9A.%E1%EF%3C
This commit is contained in:
@@ -4,6 +4,7 @@ using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Events;
|
||||
using System;
|
||||
using Orchard.Exceptions;
|
||||
|
||||
namespace Orchard.Tests.Events {
|
||||
[TestFixture]
|
||||
@@ -18,6 +19,7 @@ namespace Orchard.Tests.Events {
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultOrchardEventBus>().As<IEventBus>();
|
||||
builder.RegisterType<StubExceptionPolicy>().As<IExceptionPolicy>();
|
||||
builder.RegisterType<StubEventHandler2>().As<IEventHandler>();
|
||||
builder.RegisterInstance(_eventHandler).As<IEventHandler>();
|
||||
|
||||
@@ -229,4 +231,10 @@ namespace Orchard.Tests.Events {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class StubExceptionPolicy : IExceptionPolicy {
|
||||
public bool HandleException(object sender, Exception exception) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -128,52 +128,47 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
[HttpPost, ActionName("List")]
|
||||
[FormValueRequired("submit.BulkEdit")]
|
||||
public ActionResult ListPOST(ContentOptions options, IEnumerable<int> itemIds, string returnUrl) {
|
||||
try {
|
||||
if (itemIds != null) {
|
||||
switch (options.BulkAction) {
|
||||
case ContentsBulkAction.None:
|
||||
break;
|
||||
case ContentsBulkAction.PublishNow:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishContent, item, T("Couldn't publish selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
|
||||
_contentManager.Publish(item);
|
||||
if (itemIds != null) {
|
||||
switch (options.BulkAction) {
|
||||
case ContentsBulkAction.None:
|
||||
break;
|
||||
case ContentsBulkAction.PublishNow:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishContent, item, T("Couldn't publish selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully published."));
|
||||
break;
|
||||
case ContentsBulkAction.Unpublish:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishContent, item, T("Couldn't unpublish selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
|
||||
_contentManager.Unpublish(item);
|
||||
_contentManager.Publish(item);
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully published."));
|
||||
break;
|
||||
case ContentsBulkAction.Unpublish:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishContent, item, T("Couldn't unpublish selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully unpublished."));
|
||||
break;
|
||||
case ContentsBulkAction.Remove:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.DeleteContent, item, T("Couldn't remove selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
|
||||
_contentManager.Remove(item);
|
||||
_contentManager.Unpublish(item);
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully unpublished."));
|
||||
break;
|
||||
case ContentsBulkAction.Remove:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.DeleteContent, item, T("Couldn't remove selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully removed."));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
_contentManager.Remove(item);
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully removed."));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
catch {
|
||||
_transactionManager.Cancel();
|
||||
}
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
|
||||
}
|
||||
|
@@ -21,38 +21,32 @@ namespace Orchard.Core.HomePage.Controllers {
|
||||
|
||||
[Themed]
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
var homepage = _orchardServices.WorkContext.CurrentSite.HomePage;
|
||||
if (String.IsNullOrEmpty(homepage))
|
||||
return View();
|
||||
var homepage = _orchardServices.WorkContext.CurrentSite.HomePage;
|
||||
if (String.IsNullOrEmpty(homepage))
|
||||
return View();
|
||||
|
||||
var homePageParameters = homepage.Split(';');
|
||||
if (homePageParameters.Length != 2)
|
||||
return View();
|
||||
var homePageParameters = homepage.Split(';');
|
||||
if (homePageParameters.Length != 2)
|
||||
return View();
|
||||
|
||||
var providerName = homePageParameters[0];
|
||||
var item = Int32.Parse(homePageParameters[1]);
|
||||
var providerName = homePageParameters[0];
|
||||
var item = Int32.Parse(homePageParameters[1]);
|
||||
|
||||
foreach (var provider in _homePageProviders) {
|
||||
if (!string.Equals(provider.GetProviderName(), providerName))
|
||||
continue;
|
||||
foreach (var provider in _homePageProviders) {
|
||||
if (!string.Equals(provider.GetProviderName(), providerName))
|
||||
continue;
|
||||
|
||||
var result = provider.GetHomePage(item);
|
||||
if (result is ViewResultBase) {
|
||||
var resultBase = result as ViewResultBase;
|
||||
ViewData.Model = resultBase.ViewData.Model;
|
||||
resultBase.ViewData = ViewData;
|
||||
}
|
||||
|
||||
return result;
|
||||
var result = provider.GetHomePage(item);
|
||||
if (result is ViewResultBase) {
|
||||
var resultBase = result as ViewResultBase;
|
||||
ViewData.Model = resultBase.ViewData.Model;
|
||||
resultBase.ViewData = ViewData;
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
catch {
|
||||
return View();
|
||||
return result;
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,8 +1,6 @@
|
||||
<div>
|
||||
<h1 id="page-title">@Html.TitleForPage(T("Oops. Something went wrong ... sorry"))</h1>
|
||||
<div>
|
||||
<p>@T("An unhandled exception has occurred. The exception message was : {0}", @Model.Message).Text</p>
|
||||
<br />
|
||||
<p>@T("Please refresh the page. If the error persists, go back.").Text</p>
|
||||
<p>@T("An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back").Text</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -9,7 +9,6 @@ using Orchard.Media.Models;
|
||||
using Orchard.Media.Services;
|
||||
using Orchard.Media.ViewModels;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Media.Controllers {
|
||||
[ValidateInput(false)]
|
||||
@@ -197,7 +196,7 @@ namespace Orchard.Media.Controllers {
|
||||
try {
|
||||
_mediaService.UploadMediaFile(viewModel.MediaPath, Request.Files[fileName], viewModel.ExtractZip);
|
||||
}
|
||||
catch (ArgumentException argumentException) {
|
||||
catch (ArgumentException) {
|
||||
Services.Notifier.Error(T("Uploading media file failed:"));
|
||||
return View(viewModel);
|
||||
}
|
||||
@@ -277,7 +276,7 @@ namespace Orchard.Media.Controllers {
|
||||
try {
|
||||
_mediaService.RenameFile(viewModel.MediaPath, viewModel.Name, input["NewName"]);
|
||||
}
|
||||
catch (ArgumentException argumentException) {
|
||||
catch (ArgumentException) {
|
||||
Services.Notifier.Error(T("Editing media file failed."));
|
||||
return EditMedia(viewModel);
|
||||
}
|
||||
|
@@ -154,7 +154,7 @@ namespace Orchard.Modules.Controllers {
|
||||
_dataMigrationManager.Update(id);
|
||||
Services.Notifier.Information(T("The feature {0} was updated successfully", id));
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("An error occured while updating the feature {0}: {1}", id, exception.Message), Logger, Services.Notifier);
|
||||
Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, exception.Message));
|
||||
}
|
||||
|
||||
return RedirectToAction("Features");
|
||||
|
@@ -8,6 +8,7 @@ using Orchard.Logging;
|
||||
using Orchard.MultiTenancy.Services;
|
||||
using Orchard.MultiTenancy.ViewModels;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.MultiTenancy.Controllers {
|
||||
@@ -74,8 +75,8 @@ namespace Orchard.MultiTenancy.Controllers {
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.Error(exception, T("Creating Tenant failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
catch (ArgumentException exception) {
|
||||
Services.Notifier.Error(T("Creating Tenant failed: {0}", exception.Message));
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
@@ -137,7 +138,7 @@ namespace Orchard.MultiTenancy.Controllers {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.Error(exception, T("Failed to edit tenant: {0} ", exception.Message), Logger, Services.Notifier);
|
||||
Services.Notifier.Error(T("Failed to edit tenant: {0} ", exception.Message));
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
|
@@ -84,45 +84,39 @@ namespace Orchard.Packaging.Controllers {
|
||||
if (_shellSettings.Name != ShellSettings.DefaultName || !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add sources")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
if (!String.IsNullOrEmpty(url)) {
|
||||
if (!url.StartsWith("http")) {
|
||||
ModelState.AddModelError("Url", T("The Url is not valid").Text);
|
||||
}
|
||||
if (!String.IsNullOrEmpty(url)) {
|
||||
if (!url.StartsWith("http")) {
|
||||
ModelState.AddModelError("Url", T("The Url is not valid").Text);
|
||||
}
|
||||
else if (String.IsNullOrWhiteSpace(url)) {
|
||||
ModelState.AddModelError("Url", T("Url is required").Text);
|
||||
}
|
||||
|
||||
string title = null;
|
||||
// try to load the feed
|
||||
try {
|
||||
|
||||
XNamespace atomns = "http://www.w3.org/2005/Atom";
|
||||
var feed = XDocument.Load(url, LoadOptions.PreserveWhitespace);
|
||||
var titleNode = feed.Descendants(atomns + "title").FirstOrDefault();
|
||||
if (titleNode != null)
|
||||
title = titleNode.Value;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(title)) {
|
||||
ModelState.AddModelError("Url", T("The feed has no title.").Text);
|
||||
}
|
||||
} catch {
|
||||
ModelState.AddModelError("Url", T("The url of the feed or its content is not valid.").Text);
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return View(new PackagingAddSourceViewModel { Url = url });
|
||||
|
||||
_packagingSourceManager.AddSource(title, url);
|
||||
Services.Notifier.Information(T("The feed has been added successfully."));
|
||||
|
||||
return RedirectToAction("Sources");
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Adding feed failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
|
||||
return View(new PackagingAddSourceViewModel { Url = url });
|
||||
}
|
||||
else if (String.IsNullOrWhiteSpace(url)) {
|
||||
ModelState.AddModelError("Url", T("Url is required").Text);
|
||||
}
|
||||
|
||||
string title = null;
|
||||
// try to load the feed
|
||||
try {
|
||||
XNamespace atomns = "http://www.w3.org/2005/Atom";
|
||||
var feed = XDocument.Load(url, LoadOptions.PreserveWhitespace);
|
||||
var titleNode = feed.Descendants(atomns + "title").FirstOrDefault();
|
||||
if (titleNode != null)
|
||||
title = titleNode.Value;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(title)) {
|
||||
ModelState.AddModelError("Url", T("The feed has no title.").Text);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
ModelState.AddModelError("Url", T("The url of the feed or its content is not valid.").Text);
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return View(new PackagingAddSourceViewModel { Url = url });
|
||||
|
||||
_packagingSourceManager.AddSource(title, url);
|
||||
Services.Notifier.Information(T("The feed has been added successfully."));
|
||||
|
||||
return RedirectToAction("Sources");
|
||||
}
|
||||
|
||||
public ActionResult Modules(PackagingExtensionsOptions options, PagerParameters pagerParameters) {
|
||||
@@ -209,8 +203,9 @@ namespace Orchard.Packaging.Controllers {
|
||||
extensions = extensions.Take(pager.PageSize);
|
||||
}
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Error loading extensions from gallery source '{0}'. {1}.", source.FeedTitle, exception.Message), Logger, Services.Notifier);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Error loading extensions from gallery source '{0}'. {1}.", source.FeedTitle, exception.Message));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -103,17 +103,18 @@ namespace Orchard.Packaging.Controllers {
|
||||
if (_shellSettings.Name != ShellSettings.DefaultName || !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add sources")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
var source = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
|
||||
if (source == null) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
var source = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
|
||||
if (source == null) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
PackageInfo packageInfo = _packageManager.Install(packageId, version, source.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||
|
||||
if (DefaultExtensionTypes.IsTheme(packageInfo.ExtensionType)) {
|
||||
Services.Notifier.Information(T("The theme has been successfully installed. It can be enabled in the \"Themes\" page accessible from the menu."));
|
||||
} else if (DefaultExtensionTypes.IsModule(packageInfo.ExtensionType)) {
|
||||
}
|
||||
else if (DefaultExtensionTypes.IsModule(packageInfo.ExtensionType)) {
|
||||
Services.Notifier.Information(T("The module has been successfully installed."));
|
||||
|
||||
IPackageRepository packageRepository = PackageRepositoryFactory.Default.CreateRepository(new PackageSource(source.FeedUrl, "Default"));
|
||||
@@ -123,8 +124,8 @@ namespace Orchard.Packaging.Controllers {
|
||||
return InstallPackageDetails(extensionDescriptor, redirectUrl);
|
||||
}
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.Error(exception, T("Package installation failed."), Logger, Services.Notifier);
|
||||
catch (Exception) {
|
||||
Services.Notifier.Error(T("Package installation failed."));
|
||||
}
|
||||
|
||||
return Redirect(redirectUrl);
|
||||
@@ -134,14 +135,13 @@ namespace Orchard.Packaging.Controllers {
|
||||
if (_shellSettings.Name != ShellSettings.DefaultName || !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to install packages")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (Request.Files == null ||
|
||||
Request.Files.Count == 0 ||
|
||||
string.IsNullOrWhiteSpace(Request.Files.Get(0).FileName)) {
|
||||
|
||||
throw new OrchardException(T("Select a file to upload."));
|
||||
}
|
||||
try {
|
||||
if (Request.Files == null ||
|
||||
Request.Files.Count == 0 ||
|
||||
string.IsNullOrWhiteSpace(Request.Files.Get(0).FileName)) {
|
||||
|
||||
throw new OrchardException(T("Select a file to upload."));
|
||||
}
|
||||
|
||||
HttpPostedFileBase file = Request.Files.Get(0);
|
||||
string fullFileName = Path.Combine(_appDataFolderRoot.RootFolder, Path.GetFileName(file.FileName)).Replace(Path.DirectorySeparatorChar, '/');
|
||||
file.SaveAs(fullFileName);
|
||||
@@ -158,8 +158,8 @@ namespace Orchard.Packaging.Controllers {
|
||||
return InstallPackageDetails(extensionDescriptor, redirectUrl);
|
||||
}
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.Error(exception, T("Package uploading and installation failed."), Logger, Services.Notifier);
|
||||
catch (Exception) {
|
||||
Services.Notifier.Error(T("Package uploading and installation failed."));
|
||||
}
|
||||
|
||||
return Redirect(redirectUrl);
|
||||
@@ -210,7 +210,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
_recipeManager.Execute(recipe);
|
||||
}
|
||||
catch {
|
||||
Services.Notifier.Error(T("Recipes contains {0} unsuported module installation steps.", recipe.Name));
|
||||
Services.Notifier.Error(T("Recipes contains {0} unsupported module installation steps.", recipe.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,15 +237,14 @@ namespace Orchard.Packaging.Controllers {
|
||||
|
||||
try {
|
||||
_packageManager.Uninstall(id, HostingEnvironment.MapPath("~/"));
|
||||
|
||||
_notifier.Information(T("Uninstalled package \"{0}\"", id));
|
||||
|
||||
return this.RedirectLocal(returnUrl, "~/");
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Uninstall failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Uninstall failed: {0}", exception.Message));
|
||||
return Redirect(retryUrl);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Uninstalled package \"{0}\"", id));
|
||||
return this.RedirectLocal(returnUrl, "~/");
|
||||
}
|
||||
}
|
||||
}
|
@@ -50,19 +50,13 @@ namespace Orchard.Roles.Controllers {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage roles")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
int roleId = Convert.ToInt32(key.Substring("Checkbox.".Length));
|
||||
_roleService.DeleteRole(roleId);
|
||||
}
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
int roleId = Convert.ToInt32(key.Substring("Checkbox.".Length));
|
||||
_roleService.DeleteRole(roleId);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Deleting Role failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
|
||||
return View();
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
@@ -79,29 +73,23 @@ namespace Orchard.Roles.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var viewModel = new RoleCreateViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel);
|
||||
|
||||
//check if the role name already exists
|
||||
if (!_roleService.VerifyRoleUnicity(viewModel.Name)) {
|
||||
Services.Notifier.Error(T("Creating Role {0} failed: Role with same name already exists", viewModel.Name));
|
||||
return RedirectToAction("Create");
|
||||
}
|
||||
|
||||
_roleService.CreateRole(viewModel.Name);
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
string permissionName = key.Substring("Checkbox.".Length);
|
||||
_roleService.CreatePermissionForRole(viewModel.Name,
|
||||
permissionName);
|
||||
}
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Creating Role failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
UpdateModel(viewModel);
|
||||
|
||||
//check if the role name already exists
|
||||
if (!_roleService.VerifyRoleUnicity(viewModel.Name)) {
|
||||
Services.Notifier.Error(T("Creating Role {0} failed: Role with same name already exists", viewModel.Name));
|
||||
return RedirectToAction("Create");
|
||||
}
|
||||
|
||||
_roleService.CreateRole(viewModel.Name);
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
string permissionName = key.Substring("Checkbox.".Length);
|
||||
_roleService.CreatePermissionForRole(viewModel.Name,
|
||||
permissionName);
|
||||
}
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult Edit(int id) {
|
||||
@@ -135,25 +123,19 @@ namespace Orchard.Roles.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var viewModel = new RoleEditViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel);
|
||||
// Save
|
||||
List<string> rolePermissions = new List<string>();
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
string permissionName = key.Substring("Checkbox.".Length);
|
||||
rolePermissions.Add(permissionName);
|
||||
}
|
||||
UpdateModel(viewModel);
|
||||
// Save
|
||||
List<string> rolePermissions = new List<string>();
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
string permissionName = key.Substring("Checkbox.".Length);
|
||||
rolePermissions.Add(permissionName);
|
||||
}
|
||||
_roleService.UpdateRole(viewModel.Id, viewModel.Name, rolePermissions);
|
||||
|
||||
Services.Notifier.Information(T("Your Role has been saved."));
|
||||
return RedirectToAction("Edit", new { id });
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Editing Role failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
|
||||
return RedirectToAction("Edit", id);
|
||||
}
|
||||
_roleService.UpdateRole(viewModel.Id, viewModel.Name, rolePermissions);
|
||||
|
||||
Services.Notifier.Information(T("Your Role has been saved."));
|
||||
return RedirectToAction("Edit", new { id });
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Edit")]
|
||||
@@ -167,17 +149,10 @@ namespace Orchard.Roles.Controllers {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage roles")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
_roleService.DeleteRole(id);
|
||||
_roleService.DeleteRole(id);
|
||||
Services.Notifier.Information(T("Role was successfully deleted."));
|
||||
|
||||
Services.Notifier.Information(T("Role was successfully deleted."));
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Editing Role failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
|
||||
return RedirectToAction("Edit", id);
|
||||
}
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -57,7 +57,8 @@ namespace Orchard.Search.Controllers {
|
||||
searchFields,
|
||||
searchHit => searchHit);
|
||||
} catch(Exception exception) {
|
||||
this.Error(exception, T("Invalid search query: {0}", exception.Message), Logger, Services.Notifier);
|
||||
Logger.Error(T("Invalid search query: {0}", exception.Message).Text);
|
||||
Services.Notifier.Error(T("Invalid search query: {0}", exception.Message));
|
||||
}
|
||||
|
||||
var list = Shape.List();
|
||||
|
@@ -124,8 +124,9 @@ namespace Orchard.Setup.Controllers {
|
||||
|
||||
// redirect to the welcome page.
|
||||
return Redirect("~/");
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Setup failed:"), Logger, _notifier);
|
||||
} catch (Exception) {
|
||||
Logger.Error(T("Setup failed:").Text);
|
||||
_notifier.Error(T("Setup failed:"));
|
||||
|
||||
model.Recipes = recipes;
|
||||
foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
|
@@ -221,7 +221,8 @@ namespace Orchard.Themes.Controllers {
|
||||
_dataMigrationManager.Update(themeId);
|
||||
Services.Notifier.Information(T("The theme {0} was updated succesfuly", themeId));
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("An error occured while updating the theme {0}: {1}", themeId, exception.Message), Logger, Services.Notifier);
|
||||
Logger.Error(T("An error occured while updating the theme {0}: {1}", themeId, exception.Message).Text);
|
||||
Services.Notifier.Error(T("An error occured while updating the theme {0}: {1}", themeId, exception.Message));
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
|
@@ -95,17 +95,12 @@ namespace Orchard.Widgets.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
if (!string.IsNullOrWhiteSpace(moveUp))
|
||||
_widgetsService.MoveWidgetUp(widgetId);
|
||||
else if (!string.IsNullOrWhiteSpace(moveDown))
|
||||
_widgetsService.MoveWidgetDown(widgetId);
|
||||
else if (!string.IsNullOrWhiteSpace(moveHere))
|
||||
_widgetsService.MoveWidgetToLayer(widgetId, layerId);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.Error(exception, T("Moving widget failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(moveUp))
|
||||
_widgetsService.MoveWidgetUp(widgetId);
|
||||
else if (!string.IsNullOrWhiteSpace(moveDown))
|
||||
_widgetsService.MoveWidgetDown(widgetId);
|
||||
else if (!string.IsNullOrWhiteSpace(moveHere))
|
||||
_widgetsService.MoveWidgetToLayer(widgetId, layerId);
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
}
|
||||
@@ -147,11 +142,10 @@ namespace Orchard.Widgets.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
WidgetPart widgetPart = Services.ContentManager.New<WidgetPart>(widgetType);
|
||||
if (widgetPart == null)
|
||||
return HttpNotFound();
|
||||
try {
|
||||
WidgetPart widgetPart = Services.ContentManager.New<WidgetPart>(widgetType);
|
||||
if (widgetPart == null)
|
||||
return HttpNotFound();
|
||||
|
||||
int widgetPosition = _widgetsService.GetWidgets().Where(widget => widget.Zone == widgetPart.Zone).Count() + 1;
|
||||
widgetPart.Position = widgetPosition.ToString();
|
||||
widgetPart.Zone = zone;
|
||||
@@ -161,7 +155,8 @@ namespace Orchard.Widgets.Controllers {
|
||||
return View((object)model);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.Error(exception, T("Creating widget failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
Logger.Error(T("Creating widget failed: {0}", exception.Message).Text);
|
||||
Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
}
|
||||
}
|
||||
@@ -171,24 +166,27 @@ namespace Orchard.Widgets.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
WidgetPart widgetPart = _widgetsService.CreateWidget(layerId, widgetType, "", "", "");
|
||||
if (widgetPart == null)
|
||||
return HttpNotFound();
|
||||
WidgetPart widgetPart = _widgetsService.CreateWidget(layerId, widgetType, "", "", "");
|
||||
if (widgetPart == null)
|
||||
return HttpNotFound();
|
||||
|
||||
var model = Services.ContentManager.UpdateEditor(widgetPart, this);
|
||||
var model = Services.ContentManager.UpdateEditor(widgetPart, this);
|
||||
try {
|
||||
// override the CommonPart's persisting of the current container
|
||||
widgetPart.LayerPart = _widgetsService.GetLayer(layerId);
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Your {0} has been added.", widgetPart.TypeDefinition.DisplayName));
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Creating widget failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Logger.Error(T("Creating widget failed: {0}", exception.Message).Text);
|
||||
Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
}
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Your {0} has been added.", widgetPart.TypeDefinition.DisplayName));
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
}
|
||||
@@ -197,27 +195,22 @@ namespace Orchard.Widgets.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
LayerPart layerPart = Services.ContentManager.New<LayerPart>("Layer");
|
||||
if (layerPart == null)
|
||||
return HttpNotFound();
|
||||
LayerPart layerPart = Services.ContentManager.New<LayerPart>("Layer");
|
||||
if (layerPart == null)
|
||||
return HttpNotFound();
|
||||
|
||||
dynamic model = Services.ContentManager.BuildEditor(layerPart);
|
||||
dynamic model = Services.ContentManager.BuildEditor(layerPart);
|
||||
|
||||
// only messing with the hints if they're given
|
||||
if (!string.IsNullOrWhiteSpace(name))
|
||||
model.Name = name;
|
||||
if (!string.IsNullOrWhiteSpace(description))
|
||||
model.Description = description;
|
||||
if (!string.IsNullOrWhiteSpace(layerRule))
|
||||
model.LayerRule = layerRule;
|
||||
// only messing with the hints if they're given
|
||||
if (!string.IsNullOrWhiteSpace(name))
|
||||
model.Name = name;
|
||||
if (!string.IsNullOrWhiteSpace(description))
|
||||
model.Description = description;
|
||||
if (!string.IsNullOrWhiteSpace(layerRule))
|
||||
model.LayerRule = layerRule;
|
||||
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Creating layer failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("AddLayer")]
|
||||
@@ -225,44 +218,33 @@ namespace Orchard.Widgets.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
LayerPart layerPart = _widgetsService.CreateLayer("", "", "");
|
||||
if (layerPart == null)
|
||||
return HttpNotFound();
|
||||
LayerPart layerPart = _widgetsService.CreateLayer("", "", "");
|
||||
if (layerPart == null)
|
||||
return HttpNotFound();
|
||||
|
||||
var model = Services.ContentManager.UpdateEditor(layerPart, this);
|
||||
var model = Services.ContentManager.UpdateEditor(layerPart, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Your {0} has been created.", layerPart.TypeDefinition.DisplayName));
|
||||
return RedirectToAction("Index", "Admin", new { layerId = layerPart.Id });
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Creating layer failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
return RedirectToAction("Index");
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Your {0} has been created.", layerPart.TypeDefinition.DisplayName));
|
||||
return RedirectToAction("Index", "Admin", new { layerId = layerPart.Id });
|
||||
}
|
||||
|
||||
public ActionResult EditLayer(int id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
LayerPart layerPart = _widgetsService.GetLayer(id);
|
||||
if (layerPart == null)
|
||||
return HttpNotFound();
|
||||
LayerPart layerPart = _widgetsService.GetLayer(id);
|
||||
if (layerPart == null)
|
||||
return HttpNotFound();
|
||||
|
||||
dynamic model = Services.ContentManager.BuildEditor(layerPart);
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Editing layer failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
|
||||
return RedirectToAction("Index", "Admin");
|
||||
}
|
||||
dynamic model = Services.ContentManager.BuildEditor(layerPart);
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("EditLayer")]
|
||||
@@ -271,24 +253,20 @@ namespace Orchard.Widgets.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
LayerPart layerPart = _widgetsService.GetLayer(id);
|
||||
if (layerPart == null)
|
||||
return HttpNotFound();
|
||||
LayerPart layerPart = _widgetsService.GetLayer(id);
|
||||
if (layerPart == null)
|
||||
return HttpNotFound();
|
||||
|
||||
var model = Services.ContentManager.UpdateEditor(layerPart, this);
|
||||
var model = Services.ContentManager.UpdateEditor(layerPart, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Your {0} has been saved.", layerPart.TypeDefinition.DisplayName));
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Editing layer failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Your {0} has been saved.", layerPart.TypeDefinition.DisplayName));
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
}
|
||||
|
||||
@@ -302,7 +280,8 @@ namespace Orchard.Widgets.Controllers {
|
||||
_widgetsService.DeleteLayer(id);
|
||||
Services.Notifier.Information(T("Layer was successfully deleted"));
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Removing Layer failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
Logger.Error(T("Removing Layer failed: {0}", exception.Message).Text);
|
||||
Services.Notifier.Error(T("Removing Layer failed: {0}", exception.Message));
|
||||
}
|
||||
|
||||
return RedirectToAction("Index", "Admin");
|
||||
@@ -313,19 +292,19 @@ namespace Orchard.Widgets.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
WidgetPart widgetPart = null;
|
||||
widgetPart = _widgetsService.GetWidget(id);
|
||||
if (widgetPart == null) {
|
||||
Services.Notifier.Error(T("Widget not found: {0}", id));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
try {
|
||||
widgetPart = _widgetsService.GetWidget(id);
|
||||
if (widgetPart == null) {
|
||||
Services.Notifier.Error(T("Widget not found: {0}", id));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
dynamic model = Services.ContentManager.BuildEditor(widgetPart);
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.Error(exception, T("Editing widget failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
Logger.Error(T("Editing widget failed: {0}", exception.Message).Text);
|
||||
Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message));
|
||||
|
||||
if (widgetPart != null && widgetPart.LayerPart != null)
|
||||
return RedirectToAction("Index", "Admin", new { layerId = widgetPart.LayerPart.Id });
|
||||
@@ -341,11 +320,10 @@ namespace Orchard.Widgets.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
WidgetPart widgetPart = null;
|
||||
widgetPart = _widgetsService.GetWidget(id);
|
||||
if (widgetPart == null)
|
||||
return HttpNotFound();
|
||||
try {
|
||||
widgetPart = _widgetsService.GetWidget(id);
|
||||
if (widgetPart == null)
|
||||
return HttpNotFound();
|
||||
|
||||
var model = Services.ContentManager.UpdateEditor(widgetPart, this);
|
||||
// override the CommonPart's persisting of the current container
|
||||
widgetPart.LayerPart = _widgetsService.GetLayer(layerId);
|
||||
@@ -357,7 +335,8 @@ namespace Orchard.Widgets.Controllers {
|
||||
|
||||
Services.Notifier.Information(T("Your {0} has been saved.", widgetPart.TypeDefinition.DisplayName));
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Editing widget failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
Logger.Error(T("Editing widget failed: {0}", exception.Message).Text);
|
||||
Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message));
|
||||
}
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
@@ -373,16 +352,16 @@ namespace Orchard.Widgets.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
WidgetPart widgetPart = null;
|
||||
widgetPart = _widgetsService.GetWidget(id);
|
||||
if (widgetPart == null)
|
||||
return HttpNotFound();
|
||||
try {
|
||||
widgetPart = _widgetsService.GetWidget(id);
|
||||
if (widgetPart == null)
|
||||
return HttpNotFound();
|
||||
|
||||
_widgetsService.DeleteWidget(widgetPart.Id);
|
||||
Services.Notifier.Information(T("Widget was successfully deleted"));
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.Error(exception, T("Removing Widget failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
Logger.Error(T("Removing Widget failed: {0}", exception.Message).Text);
|
||||
Services.Notifier.Error(T("Removing Widget failed: {0}", exception.Message));
|
||||
}
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
|
@@ -16,6 +16,7 @@ using Orchard.Environment.ShellBuilders;
|
||||
using Orchard.Environment.State;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Events;
|
||||
using Orchard.Exceptions;
|
||||
using Orchard.FileSystems.AppData;
|
||||
using Orchard.FileSystems.Dependencies;
|
||||
using Orchard.FileSystems.LockFile;
|
||||
@@ -58,6 +59,7 @@ namespace Orchard.Environment {
|
||||
builder.RegisterType<OrchardFrameworkAssemblyNameResolver>().As<IAssemblyNameResolver>().SingleInstance();
|
||||
builder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
|
||||
builder.RegisterType<ViewsBackgroundCompilation>().As<IViewsBackgroundCompilation>().SingleInstance();
|
||||
builder.RegisterType<DefaultExceptionPolicy>().As<IExceptionPolicy>().SingleInstance();
|
||||
|
||||
RegisterVolatileProvider<WebSiteFolder, IWebSiteFolder>(builder);
|
||||
RegisterVolatileProvider<AppDataFolder, IAppDataFolder>(builder);
|
||||
|
@@ -3,17 +3,17 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Orchard.Exceptions;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Events {
|
||||
public class DefaultOrchardEventBus : IEventBus {
|
||||
private readonly Func<IEnumerable<IEventHandler>> _eventHandlers;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IExceptionPolicy _exceptionPolicy;
|
||||
|
||||
public DefaultOrchardEventBus(Func<IEnumerable<IEventHandler>> eventHandlers) {
|
||||
public DefaultOrchardEventBus(Func<IEnumerable<IEventHandler>> eventHandlers, IExceptionPolicy exceptionPolicy) {
|
||||
_eventHandlers = eventHandlers;
|
||||
_notifier = new Notifier();
|
||||
_exceptionPolicy = exceptionPolicy;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
@@ -49,11 +49,10 @@ namespace Orchard.Events {
|
||||
try {
|
||||
return TryInvoke(eventHandler, interfaceName, methodName, eventData, out returnValue);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
_notifier.Error(T("{2} thrown from {0} by {1}",
|
||||
messageName,
|
||||
eventHandler.GetType().FullName,
|
||||
ex.GetType().Name));
|
||||
catch (Exception exception) {
|
||||
if (!_exceptionPolicy.HandleException(this, exception)) {
|
||||
throw;
|
||||
}
|
||||
|
||||
returnValue = null;
|
||||
return false;
|
||||
|
73
src/Orchard/Exceptions/DefaultExceptionPolicy.cs
Normal file
73
src/Orchard/Exceptions/DefaultExceptionPolicy.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
using Orchard.Events;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Exceptions {
|
||||
public class DefaultExceptionPolicy : IExceptionPolicy {
|
||||
private readonly INotifier _notifier;
|
||||
private readonly Lazy<IAuthorizer> _authorizer;
|
||||
|
||||
public DefaultExceptionPolicy() {
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public DefaultExceptionPolicy(INotifier notifier, Lazy<IAuthorizer> authorizer) {
|
||||
_notifier = notifier;
|
||||
_authorizer = authorizer;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public bool HandleException(object sender, Exception exception) {
|
||||
if (IsFatal(exception)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sender is IEventBus && exception is OrchardFatalException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger.Error(exception.Message);
|
||||
|
||||
do {
|
||||
RaiseNotification(exception);
|
||||
exception = exception.InnerException;
|
||||
} while (exception != null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsFatal(Exception exception) {
|
||||
return
|
||||
exception is OrchardSecurityException ||
|
||||
exception is StackOverflowException ||
|
||||
exception is AccessViolationException ||
|
||||
exception is AppDomainUnloadedException ||
|
||||
exception is ThreadAbortException ||
|
||||
exception is SecurityException ||
|
||||
exception is SEHException;
|
||||
}
|
||||
|
||||
private void RaiseNotification(Exception exception) {
|
||||
if (_notifier == null || _authorizer.Value == null) {
|
||||
return;
|
||||
}
|
||||
if (exception is OrchardException) {
|
||||
_notifier.Error((exception as OrchardException).LocalizedMessage);
|
||||
}
|
||||
else if (_authorizer.Value.Authorize(StandardPermissions.SiteOwner)) {
|
||||
_notifier.Error(T(exception.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,12 +8,15 @@ using IFilterProvider = Orchard.Mvc.Filters.IFilterProvider;
|
||||
|
||||
namespace Orchard.Exceptions.Filters {
|
||||
public class UnhandledExceptionFilter : FilterProvider, IActionFilter {
|
||||
private readonly IExceptionPolicy _exceptionPolicy;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly Lazy<IEnumerable<IFilterProvider>> _filterProviders;
|
||||
|
||||
public UnhandledExceptionFilter(
|
||||
IExceptionPolicy exceptionPolicy,
|
||||
IOrchardServices orchardServices,
|
||||
Lazy<IEnumerable<IFilterProvider>> filters) {
|
||||
_exceptionPolicy = exceptionPolicy;
|
||||
_orchardServices = orchardServices;
|
||||
_filterProviders = filters;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -26,30 +29,31 @@ namespace Orchard.Exceptions.Filters {
|
||||
|
||||
public void OnActionExecuted(ActionExecutedContext filterContext) {
|
||||
if (!filterContext.ExceptionHandled && filterContext.Exception != null) {
|
||||
var shape = _orchardServices.New.ErrorPage();
|
||||
shape.Message = filterContext.Exception.Message;
|
||||
shape.Exception = filterContext.Exception;
|
||||
Logger.Error(filterContext.Exception.Message);
|
||||
if (_exceptionPolicy.HandleException(this, filterContext.Exception)) {
|
||||
var shape = _orchardServices.New.ErrorPage();
|
||||
shape.Message = filterContext.Exception.Message;
|
||||
shape.Exception = filterContext.Exception;
|
||||
|
||||
filterContext.ExceptionHandled = true;
|
||||
filterContext.ExceptionHandled = true;
|
||||
|
||||
// inform exception filters of the exception that was suppressed
|
||||
var filterInfo = new FilterInfo();
|
||||
foreach (var filterProvider in _filterProviders.Value) {
|
||||
filterProvider.AddFilters(filterInfo);
|
||||
}
|
||||
// inform exception filters of the exception that was suppressed
|
||||
var filterInfo = new FilterInfo();
|
||||
foreach (var filterProvider in _filterProviders.Value) {
|
||||
filterProvider.AddFilters(filterInfo);
|
||||
}
|
||||
|
||||
var exceptionContext = new ExceptionContext(filterContext.Controller.ControllerContext, filterContext.Exception);
|
||||
foreach (var exceptionFilter in filterInfo.ExceptionFilters) {
|
||||
exceptionFilter.OnException(exceptionContext);
|
||||
}
|
||||
var exceptionContext = new ExceptionContext(filterContext.Controller.ControllerContext, filterContext.Exception);
|
||||
foreach (var exceptionFilter in filterInfo.ExceptionFilters) {
|
||||
exceptionFilter.OnException(exceptionContext);
|
||||
}
|
||||
|
||||
if (exceptionContext.ExceptionHandled) {
|
||||
filterContext.Result = exceptionContext.Result;
|
||||
}
|
||||
else {
|
||||
filterContext.Result = new ShapeResult(filterContext.Controller, shape);
|
||||
filterContext.RequestContext.HttpContext.Response.StatusCode = 500;
|
||||
if (exceptionContext.ExceptionHandled) {
|
||||
filterContext.Result = exceptionContext.Result;
|
||||
}
|
||||
else {
|
||||
filterContext.Result = new ShapeResult(filterContext.Controller, shape);
|
||||
filterContext.RequestContext.HttpContext.Response.StatusCode = 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
src/Orchard/Exceptions/IExceptionPolicy.cs
Normal file
8
src/Orchard/Exceptions/IExceptionPolicy.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
namespace Orchard.Exceptions {
|
||||
public interface IExceptionPolicy : ISingletonDependency {
|
||||
/* return false if the exception should be rethrown by the caller */
|
||||
bool HandleException(object sender, Exception exception);
|
||||
}
|
||||
}
|
@@ -224,7 +224,9 @@
|
||||
<Compile Include="Environment\WorkContextImplementation.cs" />
|
||||
<Compile Include="Environment\WorkContextModule.cs" />
|
||||
<Compile Include="Environment\WorkContextProperty.cs" />
|
||||
<Compile Include="Exceptions\DefaultExceptionPolicy.cs" />
|
||||
<Compile Include="Exceptions\Filters\UnhandledExceptionFilter.cs" />
|
||||
<Compile Include="Exceptions\IExceptionPolicy.cs" />
|
||||
<Compile Include="FileSystems\Dependencies\IExtensionDependenciesManager.cs" />
|
||||
<Compile Include="FileSystems\Dependencies\DefaultExtensionDependenciesManager.cs" />
|
||||
<Compile Include="FileSystems\LockFile\ILockFile.cs" />
|
||||
@@ -251,6 +253,7 @@
|
||||
<Compile Include="Mvc\ShapeResult.cs" />
|
||||
<Compile Include="Mvc\Spooling\HtmlStringWriter.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\Razor\IRazorCompilationEvents.cs" />
|
||||
<Compile Include="OrchardFatalException.cs" />
|
||||
<Compile Include="Recipes\Events\IRecipeSchedulerEventHandler.cs" />
|
||||
<Compile Include="Recipes\Models\Recipe.cs" />
|
||||
<Compile Include="Recipes\Models\RecipeContext.cs" />
|
||||
@@ -531,7 +534,6 @@
|
||||
<Compile Include="Messaging\Services\IMessageManager.cs" />
|
||||
<Compile Include="Messaging\Services\IMessagingChannel.cs" />
|
||||
<Compile Include="IWorkContextAccessor.cs" />
|
||||
<Compile Include="Utility\Extensions\ControllerExtensions.cs" />
|
||||
<Compile Include="Utility\Extensions\VirtualPathProviderExtensions.cs" />
|
||||
<Compile Include="Validation\PathValidation.cs" />
|
||||
<Compile Include="Wcf\OrchardDependencyInjectionServiceBehavior.cs" />
|
||||
|
26
src/Orchard/OrchardFatalException.cs
Normal file
26
src/Orchard/OrchardFatalException.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard {
|
||||
[Serializable]
|
||||
public class OrchardFatalException : Exception {
|
||||
private readonly LocalizedString _localizedMessage;
|
||||
|
||||
public OrchardFatalException(LocalizedString message)
|
||||
: base(message.Text) {
|
||||
_localizedMessage = message;
|
||||
}
|
||||
|
||||
public OrchardFatalException(LocalizedString message, Exception innerException)
|
||||
: base(message.Text, innerException) {
|
||||
_localizedMessage = message;
|
||||
}
|
||||
|
||||
protected OrchardFatalException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context) {
|
||||
}
|
||||
|
||||
public LocalizedString LocalizedMessage { get { return _localizedMessage; } }
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Utility.Extensions {
|
||||
public static class ControllerExtensions {
|
||||
public static void Error(this Controller controller,
|
||||
Exception exception,
|
||||
LocalizedString localizedString,
|
||||
ILogger logger,
|
||||
INotifier notifier) {
|
||||
|
||||
logger.Error(exception, localizedString.ToString());
|
||||
notifier.Error(localizedString);
|
||||
|
||||
for (Exception innerException = exception; innerException != null ; innerException = innerException.InnerException) {
|
||||
notifier.Error(new LocalizedString(innerException.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user