コード例 #1
0
        public CallAggregationCallDescription GetOrAddCall(string methodName, IEnumerable <object> parameters)
        {
            CallAggregationCallDescription result = null;

            lock (callLocker){
                foreach (var item in Calls)
                {
                    if (item.MethodName == methodName && parameters.SequenceEqual(item.Parameters))
                    {
                        result = item;
                        break;
                    }
                }
                if (result == null)
                {
                    result = new CallAggregationCallDescription(methodName, parameters);
                    Calls.Add(result);
                }
            }

            return(result);
        }
コード例 #2
0
        private async Task <CallAggregationResult> CallServiceAsync(CallAggregationServiceDescription service, CallAggregationCallDescription call)
        {
#if (!SILVERLIGHT)
            Stopwatch sw = null;
            if (call.MeasureDuration)
            {
                sw = new Stopwatch();
                sw.Start();
            }
#endif
            var param1            = Expression.Parameter(typeof(CallAggregationService));
            var method            = service.ContractType.GetMethod(call.MethodName);
            var returnType        = method.ReturnType.GetGenericArguments().First();
            var callServiceMethod = CallServiceMethodInfo.MakeGenericMethod(service.ContractType, returnType);

            var delegateParam1 = Expression.Parameter(service.ContractType);
            var callDelegate   = Expression.Lambda(
                Expression.Call(
                    delegateParam1,
                    method,
                    call.Parameters.Select((p, i) => Expression.Constant(p, method.GetParameters()[i].ParameterType))
                    ),
                delegateParam1);

            var body = Expression.Call(
                param1,
                callServiceMethod,
                callDelegate
                );

            var compiled = Expression.Lambda <Func <CallAggregationService, Task <object> > >(body, param1).Compile();
            var result   = await compiled(this);

            var aggResult = call.CreateResult(result);
#if (!SILVERLIGHT)
            if (call.MeasureDuration)
            {
                sw.Stop();
                aggResult.Duration = sw.Elapsed;
            }
#endif

            return(aggResult);
        }