#17284: Exceptions should log errors

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2011-02-08 11:22:47 -08:00
parent 406ab0e71a
commit a8a48ab4e1
15 changed files with 199 additions and 167 deletions

View File

@@ -13,6 +13,7 @@ using Orchard.UI.Navigation;
using Orchard.UI.Notify;
using Orchard.Comments.ViewModels;
using Orchard.Comments.Services;
using Orchard.Utility.Extensions;
namespace Orchard.Comments.Controllers {
using Orchard.Settings;
@@ -80,9 +81,9 @@ namespace Orchard.Comments.Controllers {
Pager = pagerShape
};
return View(model);
}
catch (Exception exception) {
Services.Notifier.Error(T("Listing comments failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Listing comments failed: {0}", exception.Message), Logger, Services.Notifier);
return View(new CommentsIndexViewModel());
}
}
@@ -134,9 +135,9 @@ namespace Orchard.Comments.Controllers {
default:
throw new ArgumentOutOfRangeException();
}
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing comments failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Editing comments failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index", "Admin", new { options = viewModel.Options });
}
@@ -176,9 +177,9 @@ namespace Orchard.Comments.Controllers {
CommentsClosedOnItem = _commentService.CommentsDisabledForCommentedContent(id),
};
return View(model);
}
catch (Exception exception) {
Services.Notifier.Error(T("Listing comments failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Listing comments failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index");
}
}
@@ -230,9 +231,9 @@ namespace Orchard.Comments.Controllers {
default:
throw new ArgumentOutOfRangeException();
}
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing comments failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Editing comments failed: {0}", exception.Message), Logger, Services.Notifier);
return Details(viewModel.CommentedItemId, viewModel.Options);
}
@@ -246,9 +247,8 @@ namespace Orchard.Comments.Controllers {
return new HttpUnauthorizedResult();
_commentService.DisableCommentsForCommentedContent(commentedItemId);
}
catch (Exception exception) {
Services.Notifier.Error(T("Disabling Comments failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Disabling Comments failed: {0}", exception.Message), Logger, Services.Notifier);
}
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
}
@@ -260,9 +260,8 @@ namespace Orchard.Comments.Controllers {
return new HttpUnauthorizedResult();
_commentService.EnableCommentsForCommentedContent(commentedItemId);
}
catch (Exception exception) {
Services.Notifier.Error(T("Enabling Comments failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Enabling Comments failed: {0}", exception.Message), Logger, Services.Notifier);
}
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
}
@@ -280,9 +279,9 @@ namespace Orchard.Comments.Controllers {
};
return View(viewModel);
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing comment failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Editing comment failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index");
}
}
@@ -297,9 +296,9 @@ namespace Orchard.Comments.Controllers {
_commentService.UpdateComment(viewModel.Id, viewModel.Name, viewModel.Email, viewModel.SiteName, viewModel.CommentText, viewModel.Status);
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing Comment failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Editing comment failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}
@@ -314,9 +313,8 @@ namespace Orchard.Comments.Controllers {
_commentService.ApproveComment(id);
return this.RedirectLocal(returnUrl, () => RedirectToAction("Details", new { id = commentedOn }));
}
catch (Exception exception) {
Services.Notifier.Error(T("Approving comment failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Approving comment failed: {0}", exception.Message), Logger, Services.Notifier);
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
}
@@ -332,9 +330,9 @@ namespace Orchard.Comments.Controllers {
_commentService.UnapproveComment(id);
return this.RedirectLocal(returnUrl, () => RedirectToAction("Details", new { id = commentedOn }));
}
catch (Exception exception) {
Services.Notifier.Error(T("Unapproving comment failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Unapproving comment failed: {0}", exception.Message), Logger, Services.Notifier);
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
}
}
@@ -349,9 +347,9 @@ namespace Orchard.Comments.Controllers {
_commentService.MarkCommentAsSpam(id);
return this.RedirectLocal(returnUrl, () => RedirectToAction("Details", new { id = commentedOn }));
}
catch (Exception exception) {
Services.Notifier.Error(T("Marking comment as spam failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Marking comment as spam failed: {0}", exception.Message), Logger, Services.Notifier);
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
}
}
@@ -366,9 +364,9 @@ namespace Orchard.Comments.Controllers {
_commentService.DeleteComment(id);
return this.RedirectLocal(returnUrl, () => RedirectToAction("Details", new { id = commentedOn }));
}
catch (Exception exception) {
Services.Notifier.Error(T("Deleting comment failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Deleting comment failed: {0}", exception.Message), Logger, Services.Notifier);
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
}
}

View File

@@ -7,9 +7,10 @@ using Orchard.Commands;
using Orchard.Experimental.ViewModels;
using Orchard.Environment.Extensions;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Themes;
using Orchard.UI.Admin;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
namespace Orchard.Experimental.Controllers {
[Themed, Admin, OrchardFeature("Orchard.Experimental.WebCommandLine")]
@@ -20,10 +21,12 @@ namespace Orchard.Experimental.Controllers {
_commandManager = commandManager;
Services = services;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public IOrchardServices Services { get; set; }
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public ActionResult Index() {
return Execute();
@@ -47,9 +50,9 @@ namespace Orchard.Experimental.Controllers {
.ToArray();
model.Results = writer.ToString();
}
}
catch(Exception exception) {
Services.Notifier.Error(T("Error executing command: {0}", exception.Message));
} catch(Exception exception) {
this.Error(exception, T("Error executing command: {0}", exception.Message), Logger, Services.Notifier);
Services.TransactionManager.Cancel();
}
return View(model);

View File

@@ -5,10 +5,12 @@ using System.Web;
using System.Web.Mvc;
using Orchard.Core.Contents.Controllers;
using Orchard.Localization;
using Orchard.Logging;
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)]
@@ -20,10 +22,12 @@ namespace Orchard.Media.Controllers {
_mediaService = mediaService;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public IOrchardServices Services { get; set;}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public ActionResult Index() {
// Root media folders
@@ -44,7 +48,8 @@ namespace Orchard.Media.Controllers {
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Deleting Folder failed: {0}", exception.Message));
this.Error(exception, T("Deleting Folder failed: {0}", exception.Message), Logger, Services.Notifier);
return View();
}
}
@@ -68,7 +73,8 @@ namespace Orchard.Media.Controllers {
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Creating Folder failed: {0}", exception.Message));
this.Error(exception, T("Creating Folder failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}
@@ -81,7 +87,8 @@ namespace Orchard.Media.Controllers {
return View(model);
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing failed: {0}", exception.Message));
this.Error(exception, T("Editing failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index");
}
}
@@ -110,9 +117,9 @@ namespace Orchard.Media.Controllers {
}
}
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Deleting failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Deleting failed: {0}", exception.Message), Logger, Services.Notifier);
return View();
}
}
@@ -136,9 +143,9 @@ namespace Orchard.Media.Controllers {
Services.Notifier.Information(T("Media folder deleted"));
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Deleting media folder failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Deleting media folder failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}
@@ -158,7 +165,8 @@ namespace Orchard.Media.Controllers {
Services.Notifier.Information(T("Media folder properties modified"));
return RedirectToAction("Index");
} catch (Exception exception) {
Services.Notifier.Error(T("Modifying media folder properties failed: {0}", exception.Message));
this.Error(exception, T("Modifying media folder properties failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}
@@ -190,9 +198,9 @@ namespace Orchard.Media.Controllers {
Services.Notifier.Information(T("Media file(s) uploaded"));
return RedirectToAction("Edit", new { name = viewModel.FolderName, mediaPath = viewModel.MediaPath });
}
catch (Exception exception) {
Services.Notifier.Error(T("Uploading media file failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Uploading media file failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}
@@ -255,7 +263,8 @@ namespace Orchard.Media.Controllers {
Services.Notifier.Information(T("Media deleted"));
return RedirectToAction("Edit", new { name = viewModel.FolderName, mediaPath = viewModel.MediaPath });
} catch (Exception exception) {
Services.Notifier.Error(T("Removing media file failed: {0}", exception.Message));
this.Error(exception, T("Removing media file failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}
@@ -286,7 +295,8 @@ namespace Orchard.Media.Controllers {
mediaPath = viewModel.MediaPath });
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing media file failed: {0}", exception.Message));
this.Error(exception, T("Editing media file failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}

View File

@@ -7,11 +7,13 @@ using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Environment.Features;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Modules.Services;
using Orchard.Modules.ViewModels;
using Orchard.Reports.Services;
using Orchard.Security;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
namespace Orchard.Modules.Controllers {
public class AdminController : Controller {
@@ -39,10 +41,12 @@ namespace Orchard.Modules.Controllers {
_shellDescriptor = shellDescriptor;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public Localizer T { get; set; }
public IOrchardServices Services { get; set; }
public ILogger Logger { get; set; }
public ActionResult Index() {
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage modules")))
@@ -111,9 +115,8 @@ namespace Orchard.Modules.Controllers {
_reportsCoordinator.Register("Data Migration", "Upgrade " + id, "Orchard installation");
_dataMigrationManager.Update(id);
Services.Notifier.Information(T("The feature {0} was updated successfully", id));
}
catch (Exception ex) {
Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, ex.Message));
} catch (Exception exception) {
this.Error(exception, T("An error occured while updating the feature {0}: {1}", id, exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Features");

View File

@@ -1,13 +1,14 @@
using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Localization;
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 {
[ValidateInput(false)]
@@ -21,10 +22,12 @@ namespace Orchard.MultiTenancy.Controllers {
Services = orchardServices;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public Localizer T { get; set; }
public IOrchardServices Services { get; set; }
public ILogger Logger { get; set; }
public ActionResult Index() {
return View(new TenantsIndexViewModel { TenantSettings = _tenantService.GetTenants() });
@@ -61,9 +64,9 @@ namespace Orchard.MultiTenancy.Controllers {
});
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Creating Tenant failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Creating Tenant failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}
@@ -115,9 +118,9 @@ namespace Orchard.MultiTenancy.Controllers {
});
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Failed to edit tenant: {0} ", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Failed to edit tenant: {0} ", exception.Message), Logger, Services.Notifier);
return View(viewModel);
}
}

View File

@@ -19,6 +19,7 @@ using Orchard.Themes;
using Orchard.UI.Admin;
using Orchard.UI.Navigation;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
using IPackageManager = Orchard.Packaging.Services.IPackageManager;
namespace Orchard.Packaging.Controllers {
@@ -100,8 +101,7 @@ namespace Orchard.Packaging.Controllers {
if (String.IsNullOrWhiteSpace(title)) {
ModelState.AddModelError("Url", T("The feed has no title.").Text);
}
}
catch {
} catch {
ModelState.AddModelError("Url", T("The url of the feed or its content is not valid.").Text);
}
@@ -112,9 +112,9 @@ namespace Orchard.Packaging.Controllers {
Services.Notifier.Information(T("The feed has been added successfully."));
return RedirectToAction("Sources");
}
catch (Exception exception) {
Services.Notifier.Error(T("Adding feed failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Adding feed failed: {0}", exception.Message), Logger, Services.Notifier);
return View(new PackagingAddSourceViewModel { Url = url });
}
}
@@ -198,10 +198,8 @@ namespace Orchard.Packaging.Controllers {
extensions = extensions.Take(pager.PageSize);
}
}
}
catch (Exception ex) {
Logger.Error(ex, "Error loading extensions from gallery source '{0}'. {1}.", source.FeedTitle, ex.Message);
Services.Notifier.Error(T("Error loading extensions from gallery source '{0}'. {1}.", source.FeedTitle, ex.Message));
} catch (Exception exception) {
this.Error(exception, T("Error loading extensions from gallery source '{0}'. {1}.", source.FeedTitle, exception.Message), Logger, Services.Notifier);
}
}
@@ -241,12 +239,8 @@ namespace Orchard.Packaging.Controllers {
else if (packageId.StartsWith(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Module))) {
Services.Notifier.Information(T("The module has been successfully installed. Its features can be enabled in the \"Configuration | Features\" page accessible from the menu."));
}
}
catch (Exception exception) {
Services.Notifier.Error(T("Package installation failed."));
for (Exception scan = exception; scan != null; scan = scan.InnerException) {
Services.Notifier.Error(T("{0}", scan.Message));
}
} catch (Exception exception) {
this.Error(exception, T("Package installation failed."), Logger, Services.Notifier);
}
return RedirectToAction(redirectTo == "Themes" ? "Themes" : "Modules");

View File

@@ -15,6 +15,7 @@ using Orchard.Security;
using Orchard.Themes;
using Orchard.UI.Admin;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
using IPackageManager = Orchard.Packaging.Services.IPackageManager;
using PackageBuilder = Orchard.Packaging.Services.PackageBuilder;
@@ -42,10 +43,12 @@ namespace Orchard.Packaging.Controllers {
Services = services;
T = NullLocalizer.Instance;
Logger = Logging.NullLogger.Instance;
}
public Localizer T { get; set; }
public IOrchardServices Services { get; set; }
public Logging.ILogger Logger { get; set; }
public ActionResult AddTheme(string returnUrl) {
if (_shellSettings.Name != ShellSettings.DefaultName || !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add themes")))
@@ -107,12 +110,8 @@ namespace Orchard.Packaging.Controllers {
}
return this.RedirectLocal(returnUrl, "~/");
}
catch (Exception exception) {
_notifier.Error(T("Package uploading and installation failed."));
for (Exception scan = exception; scan != null; scan = scan.InnerException) {
_notifier.Error(T("{0}", scan.Message));
}
} catch (Exception exception) {
this.Error(exception, T("Package uploading and installation failed."), Logger, Services.Notifier);
return Redirect(retryUrl);
}
@@ -128,11 +127,8 @@ namespace Orchard.Packaging.Controllers {
_notifier.Information(T("Uninstalled package \"{0}\"", id));
return this.RedirectLocal(returnUrl, "~/");
}
catch (Exception exception) {
for (Exception scan = exception; scan != null; scan = scan.InnerException) {
_notifier.Error(T("Uninstall failed: {0}", exception.Message));
}
} catch (Exception exception) {
this.Error(exception, T("Uninstall failed: {0}", exception.Message), Logger, Services.Notifier);
return Redirect(retryUrl);
}

View File

@@ -4,12 +4,14 @@ using System.Linq;
using System.Web.Mvc;
using Orchard.Core.Contents.Controllers;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Mvc.Extensions;
using Orchard.Roles.Models;
using Orchard.Roles.Services;
using Orchard.Roles.ViewModels;
using Orchard.Security;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
namespace Orchard.Roles.Controllers {
[ValidateInput(false)]
@@ -25,12 +27,14 @@ namespace Orchard.Roles.Controllers {
Services = services;
_roleService = roleService;
_authorizationService = authorizationService;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public IOrchardServices Services { get; set; }
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public ActionResult Index() {
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage roles")))
@@ -54,9 +58,9 @@ namespace Orchard.Roles.Controllers {
}
}
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Deleting Role failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Deleting Role failed: {0}", exception.Message), Logger, Services.Notifier);
return View();
}
}
@@ -86,9 +90,9 @@ namespace Orchard.Roles.Controllers {
}
}
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Creating Role failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Creating Role failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Create");
}
}
@@ -138,9 +142,9 @@ namespace Orchard.Roles.Controllers {
Services.Notifier.Information(T("Your Role has been saved."));
return RedirectToAction("Edit", new { id });
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing Role failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Editing Role failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Edit", id);
}
}
@@ -163,7 +167,8 @@ namespace Orchard.Roles.Controllers {
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
} catch (Exception exception) {
Services.Notifier.Error(T("Editing Role failed: {0}", exception.Message));
this.Error(exception, T("Editing Role failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Edit", id);
}
}

View File

@@ -13,6 +13,7 @@ using Orchard.UI.Navigation;
using Orchard.UI.Notify;
using Orchard.Collections;
using Orchard.Themes;
using Orchard.Utility.Extensions;
namespace Orchard.Search.Controllers {
using Orchard.Settings;
@@ -55,10 +56,8 @@ namespace Orchard.Search.Controllers {
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
searchFields,
searchHit => searchHit);
}
catch(Exception e) {
Services.Notifier.Error(T("Invalid search query: {0}", q));
Logger.Error(e, "Invalid search query: " + q);
} catch(Exception exception) {
this.Error(exception, T("Invalid search query: {0}", exception.Message), Logger, Services.Notifier);
}
var list = Shape.List();

View File

@@ -2,11 +2,13 @@
using System.Web.Mvc;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Logging;
using Orchard.Setup.Services;
using Orchard.Setup.ViewModels;
using Orchard.Localization;
using Orchard.Themes;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
namespace Orchard.Setup.Controllers {
[ValidateInput(false), Themed]
@@ -19,10 +21,13 @@ namespace Orchard.Setup.Controllers {
_viewsBackgroundCompilation = viewsBackgroundCompilation;
_notifier = notifier;
_setupService = setupService;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
private ActionResult IndexViewResult(SetupViewModel model) {
return View(model);
@@ -87,12 +92,9 @@ namespace Orchard.Setup.Controllers {
// redirect to the welcome page.
return Redirect("~/");
}
catch (Exception exception) {
_notifier.Error(T("Setup failed:"));
for (var scan = exception; scan != null; scan = scan.InnerException) {
_notifier.Error(new LocalizedString(scan.Message));
}
} catch (Exception exception) {
this.Error(exception, T("Setup failed:"), Logger, _notifier);
return IndexViewResult(model);
}
}

View File

@@ -8,6 +8,7 @@ using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Environment.Features;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Mvc.Extensions;
using Orchard.Reports.Services;
using Orchard.Security;
@@ -15,6 +16,7 @@ using Orchard.Themes.Preview;
using Orchard.Themes.Services;
using Orchard.Themes.ViewModels;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
namespace Orchard.Themes.Controllers {
[ValidateInput(false)]
@@ -50,10 +52,12 @@ namespace Orchard.Themes.Controllers {
_reportsCoordinator = reportsCoordinator;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public IOrchardServices Services { get; set; }
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public ActionResult Index() {
try {
@@ -74,9 +78,9 @@ namespace Orchard.Themes.Controllers {
InstallThemes = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "PackagingServices") != null,
BrowseToGallery = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "Gallery") != null
});
}
catch (Exception exception) {
Services.Notifier.Error(T("Listing themes failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Listing themes failed: {0}", exception.Message), Logger, Services.Notifier);
return View(new ThemesIndexViewModel());
}
}
@@ -88,9 +92,9 @@ namespace Orchard.Themes.Controllers {
return new HttpUnauthorizedResult();
_previewTheme.SetPreviewTheme(themeName);
return this.RedirectLocal(returnUrl, "~/");
}
catch (Exception exception) {
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Previewing theme failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index");
}
}
@@ -102,10 +106,10 @@ namespace Orchard.Themes.Controllers {
return new HttpUnauthorizedResult();
_previewTheme.SetPreviewTheme(null);
_siteThemeService.SetSiteTheme(themeName);
} catch (Exception exception) {
this.Error(exception, T("Previewing theme failed: {0}", exception.Message), Logger, Services.Notifier);
}
catch (Exception exception) {
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
}
return RedirectToAction("Index");
}
@@ -115,9 +119,8 @@ namespace Orchard.Themes.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
return new HttpUnauthorizedResult();
_previewTheme.SetPreviewTheme(null);
}
catch (Exception exception) {
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Previewing theme failed: {0}", exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index");
}
@@ -129,9 +132,8 @@ namespace Orchard.Themes.Controllers {
return new HttpUnauthorizedResult();
_themeService.EnableThemeFeatures(themeName);
}
catch (Exception exception) {
Services.Notifier.Error(T("Enabling theme failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Enabling theme failed: {0}", exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index");
}
@@ -143,9 +145,8 @@ namespace Orchard.Themes.Controllers {
return new HttpUnauthorizedResult();
_themeService.DisableThemeFeatures(themeName);
}
catch (Exception exception) {
Services.Notifier.Error(T("Disabling theme failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Disabling theme failed: {0}", exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index");
}
@@ -158,9 +159,8 @@ namespace Orchard.Themes.Controllers {
_themeService.EnableThemeFeatures(themeName);
_siteThemeService.SetSiteTheme(themeName);
}
catch (Exception exception) {
Services.Notifier.Error(T("Activating theme failed: " + exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Activating theme failed: {0}", exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index");
}
@@ -177,9 +177,8 @@ namespace Orchard.Themes.Controllers {
_reportsCoordinator.Register("Data Migration", "Upgrade " + themeName, "Orchard installation");
_dataMigrationManager.Update(themeName);
Services.Notifier.Information(T("The theme {0} was updated succesfuly", themeName));
}
catch (Exception ex) {
Services.Notifier.Error(T("An error occured while updating the theme {0}: {1}", themeName, ex.Message));
} catch (Exception exception) {
this.Error(exception, T("An error occured while updating the theme {0}: {1}", themeName, exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index");

View File

@@ -200,8 +200,7 @@ namespace Orchard.Users.Controllers {
ModelState.AddModelError("_FORM",
T("The current password is incorrect or the new password is invalid."));
return ChangePassword();
}
catch {
} catch {
ModelState.AddModelError("_FORM", T("The current password is incorrect or the new password is invalid."));
return ChangePassword();
}

View File

@@ -5,8 +5,10 @@ using System.Linq;
using Orchard.ContentManagement;
using Orchard.Core.Contents.Controllers;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.UI.Admin;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
using Orchard.Widgets.Models;
using Orchard.Widgets.Services;
using Orchard.Widgets.ViewModels;
@@ -28,10 +30,12 @@ namespace Orchard.Widgets.Controllers {
_widgetsService = widgetsService;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
private IOrchardServices Services { get; set; }
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public ActionResult Index(int? id) {
IEnumerable<LayerPart> layers = _widgetsService.GetLayers();
@@ -90,9 +94,8 @@ namespace Orchard.Widgets.Controllers {
_widgetsService.MoveWidgetUp(int.Parse(moveUpAction));
}
}
}
catch (Exception exception) {
Services.Notifier.Error(T("Moving widget failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Moving widget failed: {0}", exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index", "Admin", new { id });
@@ -116,7 +119,8 @@ namespace Orchard.Widgets.Controllers {
return View((object)model);
}
catch (Exception exception) {
Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
this.Error(exception, T("Creating widget failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index", "Admin", new { id = layerId });
}
}
@@ -139,9 +143,8 @@ namespace Orchard.Widgets.Controllers {
}
Services.Notifier.Information(T("Your {0} has been created.", widgetPart.TypeDefinition.DisplayName));
}
catch (Exception exception) {
Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Creating widget failed: {0}", exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index", "Admin", new { id = layerId });
@@ -159,9 +162,8 @@ namespace Orchard.Widgets.Controllers {
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) {
Services.Notifier.Error(T("Creating layer failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Creating layer failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index");
}
}
@@ -186,9 +188,8 @@ namespace Orchard.Widgets.Controllers {
Services.Notifier.Information(T("Your {0} has been created.", layerPart.TypeDefinition.DisplayName));
return RedirectToAction("Index", "Admin", new { id = layerPart.Id });
}
catch (Exception exception) {
Services.Notifier.Error(T("Creating layer failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Creating layer failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index");
}
}
@@ -206,9 +207,9 @@ namespace Orchard.Widgets.Controllers {
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) {
Services.Notifier.Error(T("Editing layer failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Editing layer failed: {0}", exception.Message), Logger, Services.Notifier);
return RedirectToAction("Index", "Admin", new { id });
}
}
@@ -233,9 +234,8 @@ namespace Orchard.Widgets.Controllers {
}
Services.Notifier.Information(T("Your {0} has been saved.", layerPart.TypeDefinition.DisplayName));
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing layer failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Editing layer failed: {0}", exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index", "Admin", new { id });
@@ -250,9 +250,8 @@ namespace Orchard.Widgets.Controllers {
try {
_widgetsService.DeleteLayer(id);
Services.Notifier.Information(T("Layer was successfully deleted"));
}
catch (Exception exception) {
Services.Notifier.Error(T("Removing Layer failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Removing Layer failed: {0}", exception.Message), Logger, Services.Notifier);
}
return RedirectToAction("Index");
@@ -275,7 +274,7 @@ namespace Orchard.Widgets.Controllers {
return View((object)model);
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message));
this.Error(exception, T("Editing widget failed: {0}", exception.Message), Logger, Services.Notifier);
if (widgetPart != null)
return RedirectToAction("Index", "Admin", new { id = widgetPart.LayerPart.Id });
@@ -305,9 +304,8 @@ namespace Orchard.Widgets.Controllers {
}
Services.Notifier.Information(T("Your {0} has been saved.", widgetPart.TypeDefinition.DisplayName));
}
catch (Exception exception) {
Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Editing widget failed: {0}", exception.Message), Logger, Services.Notifier);
}
return widgetPart != null ?
@@ -329,9 +327,8 @@ namespace Orchard.Widgets.Controllers {
_widgetsService.DeleteWidget(widgetPart.Id);
Services.Notifier.Information(T("Widget was successfully deleted"));
}
catch (Exception exception) {
Services.Notifier.Error(T("Removing Widget failed: {0}", exception.Message));
} catch (Exception exception) {
this.Error(exception, T("Removing Widget failed: {0}", exception.Message), Logger, Services.Notifier);
}
return widgetPart != null ?

View File

@@ -457,6 +457,7 @@
<Compile Include="Messaging\Services\IMessageManager.cs" />
<Compile Include="Messaging\Services\IMessagingChannel.cs" />
<Compile Include="IWorkContextAccessor.cs" />
<Compile Include="Utility\Extensions\ControllerExtensions.cs" />
<Compile Include="Validation\PathValidation.cs" />
<Compile Include="WorkContextExtensions.cs" />
<Compile Include="Mvc\ViewEngines\Razor\RazorCompilationEventsShim.cs" />

View File

@@ -0,0 +1,23 @@
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));
}
}
}
}