mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 20:16:15 +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:
@@ -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, "~/");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user