Merge with 1.x

--HG--
branch : autoroute
This commit is contained in:
Sebastien Ros
2012-02-10 17:09:17 -08:00
2 changed files with 7 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -10,6 +11,7 @@ namespace Orchard.Events {
public class DefaultOrchardEventBus : IEventBus {
private readonly Func<IEnumerable<IEventHandler>> _eventHandlers;
private readonly IExceptionPolicy _exceptionPolicy;
private static readonly ConcurrentDictionary<string, MethodInfo> _interfaceMethodsCache = new ConcurrentDictionary<string, MethodInfo>();
public DefaultOrchardEventBus(Func<IEnumerable<IEventHandler>> eventHandlers, IExceptionPolicy exceptionPolicy) {
_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) {
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) {
var parameters = new List<object>();
foreach (var methodParameter in method.GetParameters()) {

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -8,6 +9,7 @@ using Castle.Core.Interceptor;
namespace Orchard.Events {
public class EventsInterceptor : IInterceptor {
private readonly IEventBus _eventBus;
private static readonly ConcurrentDictionary<Type,MethodInfo> _enumerableOfTypeTDictionary = new ConcurrentDictionary<Type, MethodInfo>();
public EventsInterceptor(IEventBus eventBus) {
_eventBus = eventBus;
@@ -36,7 +38,7 @@ namespace Orchard.Events {
// acquire method:
// static IEnumerable<T> IEnumerable.OfType<T>(this IEnumerable source)
// 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 });
}
}
@@ -52,5 +54,4 @@ namespace Orchard.Events {
}
}
}