diff --git a/src/Orchard.Tests/Events/EventTests.cs b/src/Orchard.Tests/Events/EventTests.cs index e01498b87..b6bee29ec 100644 --- a/src/Orchard.Tests/Events/EventTests.cs +++ b/src/Orchard.Tests/Events/EventTests.cs @@ -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().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterInstance(_eventHandler).As(); @@ -229,4 +231,10 @@ namespace Orchard.Tests.Events { } } } + + class StubExceptionPolicy : IExceptionPolicy { + public bool HandleException(object sender, Exception exception) { + return true; + } + } } diff --git a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs index ed24965ea..4e66ca437 100644 --- a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs +++ b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs @@ -128,52 +128,47 @@ namespace Orchard.Core.Contents.Controllers { [HttpPost, ActionName("List")] [FormValueRequired("submit.BulkEdit")] public ActionResult ListPOST(ContentOptions options, IEnumerable 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")); } diff --git a/src/Orchard.Web/Core/HomePage/Controllers/HomeController.cs b/src/Orchard.Web/Core/HomePage/Controllers/HomeController.cs index d45d6b08a..20e591511 100644 --- a/src/Orchard.Web/Core/HomePage/Controllers/HomeController.cs +++ b/src/Orchard.Web/Core/HomePage/Controllers/HomeController.cs @@ -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(); } } - } \ No newline at end of file diff --git a/src/Orchard.Web/Core/Shapes/Views/ErrorPage.cshtml b/src/Orchard.Web/Core/Shapes/Views/ErrorPage.cshtml index ff16adae0..5367584ed 100644 --- a/src/Orchard.Web/Core/Shapes/Views/ErrorPage.cshtml +++ b/src/Orchard.Web/Core/Shapes/Views/ErrorPage.cshtml @@ -1,8 +1,6 @@ 

@Html.TitleForPage(T("Oops. Something went wrong ... sorry"))

-

@T("An unhandled exception has occurred. The exception message was : {0}", @Model.Message).Text

-
-

@T("Please refresh the page. If the error persists, go back.").Text

+

@T("An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back").Text

diff --git a/src/Orchard.Web/Modules/Orchard.Media/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Media/Controllers/AdminController.cs index 918ed39f2..dd1b67df1 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Media/Controllers/AdminController.cs @@ -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); } diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Modules/Controllers/AdminController.cs index b6e7af25e..305630f46 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Modules/Controllers/AdminController.cs @@ -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"); diff --git a/src/Orchard.Web/Modules/Orchard.MultiTenancy/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.MultiTenancy/Controllers/AdminController.cs index 8bd2cf769..521831bc3 100644 --- a/src/Orchard.Web/Modules/Orchard.MultiTenancy/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.MultiTenancy/Controllers/AdminController.cs @@ -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); } } diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs index 3193c72d1..026cdac90 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs @@ -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)); } } diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/PackagingServicesController.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/PackagingServicesController.cs index c02c09e80..5decf5b4d 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/PackagingServicesController.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/PackagingServicesController.cs @@ -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, "~/"); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs index 42482ed19..e68154111 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs @@ -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 rolePermissions = new List(); - 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 rolePermissions = new List(); + 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")); } } } diff --git a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs index b08d5f158..996eca8f1 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs +++ b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs @@ -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(); diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Controllers/SetupController.cs b/src/Orchard.Web/Modules/Orchard.Setup/Controllers/SetupController.cs index f614fcdc8..8cb4af8d3 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Controllers/SetupController.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Controllers/SetupController.cs @@ -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)) { diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Controllers/HomeController.cs b/src/Orchard.Web/Modules/Orchard.Tags/Controllers/HomeController.cs index 4e120966e..685bcfec0 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Controllers/HomeController.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Controllers/HomeController.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Web.Mvc; using Orchard.ContentManagement; diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs index 9e93f78e7..d5cb1b249 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs @@ -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"); diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs index 66230d3c3..526d26f90 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs @@ -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(widgetType); + if (widgetPart == null) + return HttpNotFound(); try { - WidgetPart widgetPart = Services.ContentManager.New(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("Layer"); - if (layerPart == null) - return HttpNotFound(); + LayerPart layerPart = Services.ContentManager.New("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")); diff --git a/src/Orchard/Environment/OrchardStarter.cs b/src/Orchard/Environment/OrchardStarter.cs index c781ab137..93de32d73 100644 --- a/src/Orchard/Environment/OrchardStarter.cs +++ b/src/Orchard/Environment/OrchardStarter.cs @@ -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().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); RegisterVolatileProvider(builder); RegisterVolatileProvider(builder); diff --git a/src/Orchard/Events/DefaultOrchardEventBus.cs b/src/Orchard/Events/DefaultOrchardEventBus.cs index eca1e7b2a..59c651000 100644 --- a/src/Orchard/Events/DefaultOrchardEventBus.cs +++ b/src/Orchard/Events/DefaultOrchardEventBus.cs @@ -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> _eventHandlers; - private readonly INotifier _notifier; + private readonly IExceptionPolicy _exceptionPolicy; - public DefaultOrchardEventBus(Func> eventHandlers) { + public DefaultOrchardEventBus(Func> 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; diff --git a/src/Orchard/Exceptions/DefaultExceptionPolicy.cs b/src/Orchard/Exceptions/DefaultExceptionPolicy.cs new file mode 100644 index 000000000..85d40ebb0 --- /dev/null +++ b/src/Orchard/Exceptions/DefaultExceptionPolicy.cs @@ -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 _authorizer; + + public DefaultExceptionPolicy() { + Logger = NullLogger.Instance; + T = NullLocalizer.Instance; + } + + public DefaultExceptionPolicy(INotifier notifier, Lazy 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)); + } + } + } +} diff --git a/src/Orchard/Exceptions/Filters/UnhandledExceptionFilter.cs b/src/Orchard/Exceptions/Filters/UnhandledExceptionFilter.cs index 66b76bc7e..8db9ff54f 100644 --- a/src/Orchard/Exceptions/Filters/UnhandledExceptionFilter.cs +++ b/src/Orchard/Exceptions/Filters/UnhandledExceptionFilter.cs @@ -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> _filterProviders; public UnhandledExceptionFilter( + IExceptionPolicy exceptionPolicy, IOrchardServices orchardServices, Lazy> 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; + } } } } diff --git a/src/Orchard/Exceptions/IExceptionPolicy.cs b/src/Orchard/Exceptions/IExceptionPolicy.cs new file mode 100644 index 000000000..5c5aaa92f --- /dev/null +++ b/src/Orchard/Exceptions/IExceptionPolicy.cs @@ -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); + } +} diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 76a9b5a55..06c999d2d 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -224,7 +224,9 @@ + + @@ -251,6 +253,7 @@ + @@ -531,7 +534,6 @@ - diff --git a/src/Orchard/OrchardFatalException.cs b/src/Orchard/OrchardFatalException.cs new file mode 100644 index 000000000..fbbc2b061 --- /dev/null +++ b/src/Orchard/OrchardFatalException.cs @@ -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; } } + } +} diff --git a/src/Orchard/Utility/Extensions/ControllerExtensions.cs b/src/Orchard/Utility/Extensions/ControllerExtensions.cs deleted file mode 100644 index 7ed4dc1c4..000000000 --- a/src/Orchard/Utility/Extensions/ControllerExtensions.cs +++ /dev/null @@ -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)); - } - } - } -} \ No newline at end of file