Beispiel #1
0
 private ParameterDescriptor[] LazilyFetchParametersCollection()
 {
     return(DescriptorUtil.LazilyFetchOrCreate <ParameterInfo, ParameterDescriptor>(
                ref _parametersCache /* cacheLocation */,
                () => {
         ParameterInfo[] parameters = BeginMethod.GetParameters();
         return parameters.Take(parameters.Length - 2);     // leave off the AsyncCallback + state parameters
     } /* intializer */,
                parameterInfo => new ReflectedParameterDescriptor(parameterInfo, this) /* converter */));
 }
Beispiel #2
0
        public override IAsyncResult BeginExecute(ControllerContext controllerContext, IDictionary <string, object> parameters, AsyncCallback callback, object state)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            ParameterInfo[]      parameterInfos     = BeginMethod.GetParameters();
            IEnumerable <object> rawParameterValues = from parameterInfo in parameterInfos
                                                      select ExtractParameterFromDictionary(parameterInfo, parameters, BeginMethod);

            List <object> parametersList = rawParameterValues.Take(parameterInfos.Length - 2).ToList();

            MethodDispatcher beginDispatcher = DispatcherCache.GetDispatcher(BeginMethod);
            MethodDispatcher endDispatcher   = DispatcherCache.GetDispatcher(EndMethod);

            // need to add callback + state object to list
            BeginInvokeCallback beginCallback = (innerCallback, innerState) => {
                parametersList.Add(innerCallback);
                parametersList.Add(innerState);
                object[] parametersArray = parametersList.ToArray();

                IAsyncResult innerAsyncResult = (IAsyncResult)beginDispatcher.Execute(controllerContext.Controller, parametersArray);
                return(innerAsyncResult);
            };

            AsyncCallback <object> endCallback = ar => {
                object actionReturnValue = endDispatcher.Execute(controllerContext.Controller, new object[] { ar });
                return(actionReturnValue);
            };

            // Set the timeout and go
            IAsyncManagerContainer helperContainer = controllerContext.Controller as IAsyncManagerContainer;
            int timeout = (helperContainer != null) ? helperContainer.AsyncManager.Timeout : Timeout.Infinite;

            return(AsyncResultWrapper.WrapWithTimeout(callback, state, beginCallback, endCallback, timeout, _executeTag));
        }