mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Merge with 1.x
--HG-- branch : autoroute
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -10,6 +11,7 @@ namespace Orchard.Events {
|
|||||||
public class DefaultOrchardEventBus : IEventBus {
|
public class DefaultOrchardEventBus : IEventBus {
|
||||||
private readonly Func<IEnumerable<IEventHandler>> _eventHandlers;
|
private readonly Func<IEnumerable<IEventHandler>> _eventHandlers;
|
||||||
private readonly IExceptionPolicy _exceptionPolicy;
|
private readonly IExceptionPolicy _exceptionPolicy;
|
||||||
|
private static readonly ConcurrentDictionary<string, MethodInfo> _interfaceMethodsCache = new ConcurrentDictionary<string, MethodInfo>();
|
||||||
|
|
||||||
public DefaultOrchardEventBus(Func<IEnumerable<IEventHandler>> eventHandlers, IExceptionPolicy exceptionPolicy) {
|
public DefaultOrchardEventBus(Func<IEnumerable<IEventHandler>> eventHandlers, IExceptionPolicy exceptionPolicy) {
|
||||||
_eventHandlers = eventHandlers;
|
_eventHandlers = eventHandlers;
|
||||||
@@ -71,7 +73,8 @@ namespace Orchard.Events {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryInvokeMethod(IEventHandler eventHandler, Type interfaceType, string methodName, IDictionary<string, object> arguments, out IEnumerable returnValue) {
|
private static bool TryInvokeMethod(IEventHandler eventHandler, Type interfaceType, string methodName, IDictionary<string, object> arguments, out IEnumerable returnValue) {
|
||||||
MethodInfo method = GetMatchingMethod(eventHandler, interfaceType, methodName, arguments);
|
MethodInfo method = _interfaceMethodsCache.GetOrAdd(String.Concat(interfaceType.Name, "_", methodName, "_", String.Join("_", arguments.Keys)), GetMatchingMethod(eventHandler, interfaceType, methodName, arguments));
|
||||||
|
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
var parameters = new List<object>();
|
var parameters = new List<object>();
|
||||||
foreach (var methodParameter in method.GetParameters()) {
|
foreach (var methodParameter in method.GetParameters()) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -8,6 +9,7 @@ using Castle.Core.Interceptor;
|
|||||||
namespace Orchard.Events {
|
namespace Orchard.Events {
|
||||||
public class EventsInterceptor : IInterceptor {
|
public class EventsInterceptor : IInterceptor {
|
||||||
private readonly IEventBus _eventBus;
|
private readonly IEventBus _eventBus;
|
||||||
|
private static readonly ConcurrentDictionary<Type,MethodInfo> _enumerableOfTypeTDictionary = new ConcurrentDictionary<Type, MethodInfo>();
|
||||||
|
|
||||||
public EventsInterceptor(IEventBus eventBus) {
|
public EventsInterceptor(IEventBus eventBus) {
|
||||||
_eventBus = eventBus;
|
_eventBus = eventBus;
|
||||||
@@ -36,7 +38,7 @@ namespace Orchard.Events {
|
|||||||
// acquire method:
|
// acquire method:
|
||||||
// static IEnumerable<T> IEnumerable.OfType<T>(this IEnumerable source)
|
// static IEnumerable<T> IEnumerable.OfType<T>(this IEnumerable source)
|
||||||
// where T is from returnType's IEnumerable<T>
|
// where T is from returnType's IEnumerable<T>
|
||||||
var enumerableOfTypeT = typeof(Enumerable).GetGenericMethod("OfType", returnType.GetGenericArguments(), new[] { typeof(IEnumerable) }, typeof(IEnumerable<>));
|
var enumerableOfTypeT = _enumerableOfTypeTDictionary.GetOrAdd( returnType, type => typeof(Enumerable).GetGenericMethod("OfType", type.GetGenericArguments(), new[] { typeof(IEnumerable) }, typeof(IEnumerable<>)));
|
||||||
return enumerableOfTypeT.Invoke(null, new[] { results });
|
return enumerableOfTypeT.Invoke(null, new[] { results });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,5 +54,4 @@ namespace Orchard.Events {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user