mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Removed the FailFast option on EventHandler. Will call notifier instead.
--HG-- branch : 1.x extra : transplant_source : %A6%BA%F1%8A%F8%28R%05%7D%5C%F3%9D%27%3D%FD%C2%3B%88%82%AF
This commit is contained in:
@@ -4,28 +4,27 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Events {
|
||||
public class DefaultOrchardEventBus : IEventBus {
|
||||
private readonly Func<IEnumerable<IEventHandler>> _eventHandlers;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public DefaultOrchardEventBus(Func<IEnumerable<IEventHandler>> eventHandlers) {
|
||||
_eventHandlers = eventHandlers;
|
||||
Logger = NullLogger.Instance;
|
||||
_notifier = new Notifier();
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
|
||||
public IEnumerable Notify(string messageName, IDictionary<string, object> eventData) {
|
||||
// call ToArray to ensure evaluation has taken place
|
||||
return NotifyHandlers(messageName, eventData, true/*failFast*/).ToArray();
|
||||
return NotifyHandlers(messageName, eventData).ToArray();
|
||||
}
|
||||
|
||||
private IEnumerable<object> NotifyHandlers(string messageName, IDictionary<string, object> eventData, bool failFast) {
|
||||
private IEnumerable<object> NotifyHandlers(string messageName, IDictionary<string, object> eventData) {
|
||||
string[] parameters = messageName.Split('.');
|
||||
if (parameters.Length != 2) {
|
||||
throw new ArgumentException(T("{0} is not formatted correctly", messageName).Text);
|
||||
@@ -36,7 +35,7 @@ namespace Orchard.Events {
|
||||
var eventHandlers = _eventHandlers();
|
||||
foreach (var eventHandler in eventHandlers) {
|
||||
IEnumerable returnValue;
|
||||
if (TryNotifyHandler(eventHandler, messageName, interfaceName, methodName, eventData, failFast, out returnValue)) {
|
||||
if (TryNotifyHandler(eventHandler, messageName, interfaceName, methodName, eventData, out returnValue)) {
|
||||
if (returnValue != null) {
|
||||
foreach (var value in returnValue) {
|
||||
yield return value;
|
||||
@@ -46,18 +45,15 @@ namespace Orchard.Events {
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryNotifyHandler(IEventHandler eventHandler, string messageName, string interfaceName, string methodName, IDictionary<string, object> eventData, bool failFast, out IEnumerable returnValue) {
|
||||
private bool TryNotifyHandler(IEventHandler eventHandler, string messageName, string interfaceName, string methodName, IDictionary<string, object> eventData, out IEnumerable returnValue) {
|
||||
try {
|
||||
return TryInvoke(eventHandler, interfaceName, methodName, eventData, out returnValue);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "{2} thrown from {0} by {1}",
|
||||
messageName,
|
||||
eventHandler.GetType().FullName,
|
||||
ex.GetType().Name);
|
||||
|
||||
if (failFast)
|
||||
throw;
|
||||
_notifier.Error(T("{2} thrown from {0} by {1}",
|
||||
messageName,
|
||||
eventHandler.GetType().FullName,
|
||||
ex.GetType().Name));
|
||||
|
||||
returnValue = null;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user