Exemplo n.º 1
0
        internal static InvokeInfo GetInvokeInfo(NamesPair pair)
        {
            var vkInfo = new InvokeInfo
            {
                ServiceTypeInfo =
                    TypeList.FirstOrDefault(
                        t =>
                        String.Compare(t.ServiceType.Name, pair.ServiceName, StringComparison.OrdinalIgnoreCase) ==
                        0)
            };

            if (vkInfo.ServiceTypeInfo == null)
            {
                return(null);
            }

            vkInfo.MethodAttrInfo = GetServiceMethod(vkInfo.ServiceTypeInfo, pair.MethodName);
            if (vkInfo.MethodAttrInfo == null)
            {
                return(null);
            }


            if (vkInfo.MethodAttrInfo.MethodInfo.IsStatic == false)
            {
                vkInfo.ServiceInstance = Activator.CreateInstance(vkInfo.ServiceTypeInfo.ServiceType);
            }

            return(vkInfo);
        }
Exemplo n.º 2
0
        public void Test1()
        {
            InvokeInfo   invokeInfo1 = new InvokeInfo();
            IHttpHandler handler1    = ActionHandler.CreateHandler(invokeInfo1);

            Assert.AreEqual(typeof(ActionHandler), handler1.GetType());
        }
Exemplo n.º 3
0
        internal IHttpHandler GetHttpHandler(HttpContext context, UrlActionInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }


            // 获取内部表示的调用信息
            ControllerResolver controllerResolver = new ControllerResolver(context);
            InvokeInfo         vkInfo             = controllerResolver.GetActionInvokeInfo(info);

            if (vkInfo == null)
            {
                IHttpHandler handler = Http404DebugModule.TryGetHttp404PageHandler(context);
                if (handler != null)
                {
                    return(handler);
                }
                else
                {
                    return(null);
                }
            }


            // 创建能够调用Action的HttpHandler
            return(ActionHandlerFactory.CreateHandler(vkInfo));
        }
Exemplo n.º 4
0
        IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context,
                                                    string requestType, string virtualPath, string physicalPath)
        {
            // 说明:这里不使用virtualPath变量,因为不同的配置,这个变量的值会不一样。
            // 例如:/mvc/*/*.aspx 和 /mvc/*
            // 为了映射HTTP处理器,下面直接使用context.Request.Path

            string requestPath = context.Request.Path;
            string vPath       = context.GetRealVirtualPath();

            // 尝试根据请求路径获取Action
            ControllerResolver controllerResolver = new ControllerResolver(context);
            InvokeInfo         vkInfo             = controllerResolver.GetActionInvokeInfo(vPath);

            // 如果没有找到合适的Action,并且请求的是一个ASPX页面,则按ASP.NET默认的方式来继续处理
            if (vkInfo == null)
            {
                if (requestPath.EndsWithIgnoreCase(".aspx") &&
                    System.IO.File.Exists(context.Request.PhysicalPath))
                {
                    // 调用ASP.NET默认的Page处理器工厂来处理
                    return(_msPageHandlerFactory.GetHandler(context, requestType, requestPath, physicalPath));
                }
                else
                {
                    ExceptionHelper.Throw404Exception(context);
                }
            }

            return(ActionHandlerFactory.CreateHandler(vkInfo));
        }
Exemplo n.º 5
0
        internal object[] InvokeMethod(ulong hash, int index, params object[] parameters)
        {
            using (var conn = (RpcConnection2)_connectionPool.Get())
            {
                conn.Connect();

                var invoke_info = new InvokeInfo
                {
                    ServiceHash = hash,
                    MethodIndex = index,
                    Parameters  = parameters
                };
                conn.Write(invoke_info).Wait();

                // Read the result of the invocation.
                var retObj = conn.ReadObject <InvokeReturn>().Result;
                if (retObj.ReturnType == (int)MessageType.UnknownMethod)
                {
                    throw new Exception("Unknown method.");
                }
                if (retObj.ReturnType == (int)MessageType.ThrowException)
                {
                    throw (Exception)retObj.ReturnParameters[0];
                }

                object[] outParams = retObj.ReturnParameters;
                return(outParams);
            }
        }
Exemplo n.º 6
0
        public ActionResult UserService()
        {
            var strRel = string.Empty;

            try
            {
                InvokeInfo vkInfo = ReflectionHelper.GetActionInvokeInfo(_FunctionName);
                if (vkInfo == null)
                {
                    strRel = error("请求的方法错误!", "X0008");
                }
                else
                {
                    strRel = (string)ActionExecutor.ExecuteAction(param, vkInfo);
                }
            }
            catch (Exception e)
            {
                strRel = error(_FunctionName, e.Message);
            }
            _Log.AppendLine("返回信息:" + strRel);
            Logger.WirteMessageLog(_Log.ToString());

            var strRel2 = RSAHelper.RSAEncrypt(strRel, param.PublicKey);

            return(Content(strRel2));
        }
Exemplo n.º 7
0
        public static IHttpHandler CreateHandler(InvokeInfo vkInfo)
        {
            SessionMode mode = vkInfo.GetSessionMode();

            if (mode == SessionMode.NotSupport)
            {
                return new ActionHandler {
                           InvokeInfo = vkInfo
                }
            }
            ;

            else if (mode == SessionMode.ReadOnly)
            {
                return new ReadOnlySessionActionHandler {
                           InvokeInfo = vkInfo
                }
            }
            ;

            else
            {
                return new RequiresSessionActionHandler {
                           InvokeInfo = vkInfo
                }
            };
        }
    }
Exemplo n.º 8
0
 protected static void _invoke()
 {
     if (Time.realtimeSinceStartup >= invokeInfo.delay + invokeInfo.time)
     {
         invokeInfo.action();
         invokeInfo = null;
         EditorApplication.update -= _invoke;
     }
 }
Exemplo n.º 9
0
 protected static void invoke(float delay, System.Action action)
 {
     if (invokeInfo != null)
     {
         Debug.Log("invokeInfo != null");
     }
     invokeInfo = new InvokeInfo {
         delay = delay, action = action, time = Time.realtimeSinceStartup
     };
     EditorApplication.update += _invoke;
 }
Exemplo n.º 10
0
        public T GetInstanceMethodHandler <TInstance, T>(TInstance entity, string methodName, BindingFlags bindingFlags, bool castParameters = false, Type forcedResultType = null, Type forcedThisArgType = null, int?parametersCount = null) where TInstance : class
        {
            object method;
            var    key = new HelperKey(entity.GetType(), methodName, typeof(T), castParameters, forcedResultType, forcedThisArgType, parametersCount);

            if (!InvokeInfo.TryGetValue(key, out method))
            {
                method          = CreateInstanceMethodHandler <TInstance, T>(entity, methodName, bindingFlags, castParameters, forcedResultType, forcedThisArgType, parametersCount);
                InvokeInfo[key] = method;
            }
            return((T)method);
        }
Exemplo n.º 11
0
        public void Test2()
        {
            InvokeInfo invokeInfo2 = new InvokeInfo();

            invokeInfo2.Action = new ActionDescription(typeof(ActionHandlerTest).GetMethod("Test1"));
            invokeInfo2.Action.GetType().SetValue("SessionMode",
                                                  invokeInfo2.Action, new SessionModeAttribute(SessionMode.Support));

            IHttpHandler handler2 = ActionHandler.CreateHandler(invokeInfo2);

            Assert.AreEqual(typeof(RequiresSessionActionHandler), handler2.GetType());
        }
Exemplo n.º 12
0
        public T GetStaticMethodHandler <T>(Type entityType, string methodName, BindingFlags bindingFlags, bool castParameters = false, Type forcedResultType = null, Type forcedThisArgType = null) where T : class
        {
            object method;
            var    key = new HelperKey(entityType, methodName, typeof(T));

            if (!InvokeInfo.TryGetValue(key, out method))
            {
                method          = CreateMethodHandlerImpl(null, methodName, bindingFlags, entityType, typeof(T), castParameters, forcedResultType, forcedThisArgType);
                InvokeInfo[key] = method;
            }
            return((T)method);
        }
Exemplo n.º 13
0
        internal async Task ProcessRequestAsync(HttpContext context, TaskAsyncActionHandler handler)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            this.HttpContext = context;
            this.Handler     = handler;
            this.InvokeInfo  = handler.InvokeInfo;

            // 设置 BaseController 的相关属性
            SetController();

            // 在异步执行前,先保存当前同步上下文的实例,供异步完成后执行切换调用。
            SynchronizationContext syncContxt = SynchronizationContext.Current;


            // 进入请求处理阶段
            BeginRequest();

            // 安全检查
            SecurityCheck();

            // 授权检查
            AuthorizeRequest();


            //this.HttpContext.WriteHeader("ProcessRequestAsync-before-await");

            // 执行 Action
            object actionResult = await ExecuteActionAsync();

            //this.HttpContext.WriteHeader("ProcessRequestAsync-after-await");


            // 切换到原先的上下文环境,执行余下操作
            syncContxt.Send(x => {
                //System.Runtime.Remoting.Messaging.CallContext.HostContext = (HttpContext)x;

                // 设置输出缓存
                SetOutputCache();

                // 处理方法的返回结果
                //this.HttpContext.WriteHeader("call OutputResult()");
                OutputResult(actionResult);
            }, this.HttpContext);
        }
Exemplo n.º 14
0
        public T GetStaticMethodHandler <T>(Type entityType, string methodName, BindingFlags bindingFlags)
            where T : class
        {
            object method;
            var    key = new HelperKey(entityType, methodName, typeof(T), null, null, true);

            if (!InvokeInfo.TryGetValue(key, out method))
            {
                method          = CreateMethodHandlerImpl(null, methodName, bindingFlags, entityType, typeof(T), null, null, true);
                InvokeInfo[key] = method;
            }
            return((T)method);
        }
Exemplo n.º 15
0
            static internal object GetInstance(object obj, string path, out InvokeInfo[] members)
            {
                path = path.Replace(".Array.data", "");
                var split = path.Split('.');

                var    stack = split;
                object v     = obj;

                members = new InvokeInfo[stack.Length];
                try
                {
                    var i = 0;
                    foreach (var name in stack)
                    {
                        members[i] = new InvokeInfo();
                        if (name.Contains("["))
                        {
                            var n     = name.Split('[', ']');
                            var index = int.Parse(n[1]);
                            members[i].index = index;
                            v = getField(v, n[0], out members[i].member, index);
                        }
                        else
                        {
                            v = getField(v, name, out members[i].member);
                        }

                        var propertyMember = members[i].member as PropertyInfo;
                        var fieldMember    = members[i].member as FieldInfo;

                        if (fieldMember != null)
                        {
                            members[i].valueType = fieldMember.FieldType;
                        }
                        else
                        if (propertyMember != null)
                        {
                            members[i].valueType = propertyMember.PropertyType;
                        }
                        i++;
                    }
                }
                catch (System.Exception e)
                {
                    members = null;
                    Debug.LogException(e);
                    return(null);
                }

                return(v);
            }
Exemplo n.º 16
0
        public void Test3()
        {
            InvokeInfo invokeInfo3 = new InvokeInfo();

            invokeInfo3.Controller = new ControllerDescription(typeof(ActionHandlerTest));
            invokeInfo3.Controller.GetType().SetValue("SessionMode",
                                                      invokeInfo3.Controller, new SessionModeAttribute(SessionMode.ReadOnly));

            IHttpHandler handler3 = ActionHandler.CreateHandler(invokeInfo3);

            Assert.AreEqual(typeof(ReadOnlySessionActionHandler), handler3.GetType());

            Assert.AreEqual(false, handler3.IsReusable);
        }
Exemplo n.º 17
0
        public static IHttpHandler CreateHandler(InvokeInfo vkInfo)
        {
            // 对异步的支持,只限于返回值类型是 Task 或者 Task<T>
            // 所以这里只判断是不是Task类型的返回值,如果是,则表示是一个异步Action

            if (vkInfo.Action.MethodInfo.IsTaskMethod())
            {
                return(TaskAsyncActionHandler.CreateHandler(vkInfo));
            }

            else
            {
                return(ActionHandler.CreateHandler(vkInfo));
            }
        }
Exemplo n.º 18
0
        public T GetInstanceMethodHandler <T>(object entity, string methodName, BindingFlags bindingFlags,
                                              Type instanceType, int?parametersCount = null, Type[] typeParameters = null, bool callVirtIfNeeded = true)
        {
            object method;
            var    key = new HelperKey(instanceType, methodName, typeof(T), parametersCount, typeParameters,
                                       callVirtIfNeeded);

            if (!InvokeInfo.TryGetValue(key, out method))
            {
                method = CreateInstanceMethodHandler <T>(entity, methodName, bindingFlags, instanceType, parametersCount,
                                                         typeParameters, callVirtIfNeeded);
                InvokeInfo[key] = method;
            }
            return((T)method);
        }
Exemplo n.º 19
0
        internal async Task ProcessRequestAsync(HttpContext context, TaskAsyncActionHandler handler)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            this.HttpContext = context;
            this.Handler     = handler;
            this.InvokeInfo  = handler.InvokeInfo;

            // 设置 BaseController 的相关属性
            SetController();

            // 在异步执行前,先保存当前同步上下文的实例,供异步完成后执行切换调用。
            SynchronizationContext syncContxt = SynchronizationContext.Current;

            if (syncContxt == null)
            {
                throw new InvalidProgramException();
            }


            // 进入请求处理阶段
            ExecuteBeginRequest();

            // 安全检查
            ExecuteSecurityCheck();

            // 授权检查
            ExecuteAuthorizeRequest();

            // 执行 Action
            object actionResult = await ExecuteActionAsync();

            // 切换到原先的上下文环境,执行余下操作
            syncContxt.Send(x => {
                // 设置输出缓存
                SetOutputCache();

                // 处理方法的返回结果
                ExecuteProcessResult(actionResult);
            }, this.HttpContext);
        }
Exemplo n.º 20
0
        public object GetPropertyValue(object entity, string propertyName, BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance)
        {
            object getter;
            var    type = entity.GetType();
            var    key  = new HelperKey(type, propertyName, typeof(Func <object, object>));

            if (!InvokeInfo.TryGetValue(key, out getter))
            {
                var pi = type.GetProperty(propertyName, bindingFlags);
                getter          = CreateGetter(pi);
                InvokeInfo[key] = getter;
            }
            var func = (Func <object, object>)getter;

            return(func(entity));
        }
Exemplo n.º 21
0
        public void SetPropertyValue(object entity, string propertyName, object value, BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance)
        {
            object setter;
            var    type = entity.GetType();
            var    key  = new HelperKey(type, propertyName, typeof(Action <object, object>));

            if (!InvokeInfo.TryGetValue(key, out setter))
            {
                var pi = type.GetProperty(propertyName, bindingFlags);
                setter          = CreateSetter(pi);
                InvokeInfo[key] = setter;
            }
            var del = (Action <object, object>)setter;

            del(entity, value);
        }
        /// <summary>
        /// 实现IHttpHandlerFactory接口,从当前请求获取IHttpHandler
        /// </summary>
        /// <param name="context"></param>
        /// <param name="requestType"></param>
        /// <param name="virtualPath"></param>
        /// <param name="physicalPath"></param>
        /// <returns></returns>
        public IHttpHandler GetHandler(HttpContext context,
                                       string requestType, string virtualPath, string physicalPath)
        {
            // 说明:这里不使用virtualPath变量,因为不同的配置,这个变量的值会不一样。
            // 例如:/Ajax/*/*.aspx 和 /Ajax/*
            // 为了映射HTTP处理器,下面直接使用context.Request.Path

            string vPath = context.GetRealVirtualPath();



            // 根据请求路径,定位到要执行的Action
            UrlActionInfo info = ParseUrl(context, vPath);

            if (info == null)
            {
                IHttpHandler handler = Http404DebugModule.TryGetHttp404PageHandler(context);
                if (handler != null)
                {
                    return(handler);
                }

                ExceptionHelper.Throw404Exception(context);
            }

            info.SetHttpcontext(context);



            // 获取内部表示的调用信息
            ControllerResolver controllerResolver = new ControllerResolver(context);
            InvokeInfo         vkInfo             = controllerResolver.GetActionInvokeInfo(info);

            if (vkInfo == null)
            {
                IHttpHandler handler = Http404DebugModule.TryGetHttp404PageHandler(context);
                if (handler != null)
                {
                    return(handler);
                }

                ExceptionHelper.Throw404Exception(context);
            }

            // 创建能够调用Action的HttpHandler
            return(ActionHandlerFactory.CreateHandler(vkInfo));
        }
Exemplo n.º 23
0
        public static IAsyncResult BeginInvokeEx(this Delegate dlg, AsyncCallback callback, object obj, params object[] args)
        {
            var iar        = new AsyncResult(dlg, obj);
            var invokeInfo = new InvokeInfo {
                result = iar, callback = callback, state = obj, args = args
            };

            if (_delQueueUserWorkItem != null)
            {
                _delQueueUserWorkItem(DoDelegate, invokeInfo);
            }
            else
            {
                CrestronInvoke.BeginInvoke(DoDelegate, invokeInfo);
            }
            return(iar);
        }
Exemplo n.º 24
0
        private static InvokeInfo getInvokeInfo <T>(Type t)
        {
            lock (_methodTable)
            {
                InvokeInfo i;
                if (_methodTable.TryGetValue(t, out i))
                {
                    return(i);
                }

                MethodInfo am = t.GetMethod("Add", new Type[] { typeof(T) });
                if (am == null)
                {
                    throw new Ice.MarshalException("Cannot patch a collection without an Add() method");
                }

                PropertyInfo pi = t.GetProperty("Item");
                if (pi == null)
                {
                    throw new Ice.MarshalException("Cannot patch a collection without an indexer");
                }
                MethodInfo sm = pi.GetSetMethod();
                if (sm == null)
                {
                    throw new Ice.MarshalException("Cannot patch a collection without an indexer to set a value");
                }

                pi = t.GetProperty("Count");
                if (pi == null)
                {
                    throw new Ice.MarshalException("Cannot patch a collection without a Count property");
                }
                MethodInfo cm = pi.GetGetMethod();
                if (cm == null)
                {
                    throw new Ice.MarshalException("Cannot patch a collection without a readable Count property");
                }

                i = new InvokeInfo(am, sm, cm);
                _methodTable.Add(t, i);
                return(i);
            }
        }
Exemplo n.º 25
0
    /// <summary>
    /// When something happens in game, invoke events by TriggerTime enum.
    /// Invoker info can be found in executorInfo.
    /// TriggerTime enum is Flag. Master trigger can be triggered by Sub trigger -> e.g. OnHeroInjured also triggers OnMechInjured
    /// This method is often used in game logic.
    /// (e.g. BattlePlayer.MyGameManager.EventManager.Invoke(SideEffectBundle.TriggerTime.OnSoldierKill, new ExecutorInfo(BattlePlayer.ClientId, mechId: M_MechID, targetMechId: targetMech.M_MechID));)
    /// </summary>
    /// <param name="tt"></param>
    /// <param name="executorInfo"></param>
    public void Invoke(SideEffectExecute.TriggerTime tt, ExecutorInfo executorInfo)
    {
        foreach (SideEffectExecute.TriggerTime triggerTime in Enum.GetValues(typeof(SideEffectExecute.TriggerTime)))
        {
            if ((tt & triggerTime) == tt)                                                  // this is a Flag Enum compare
            {
                InvokeTriggerTimeQueue.Enqueue(new InvokeInfo(triggerTime, executorInfo)); //all TriggerTimes enqueue
            }
        }

        while (InvokeTriggerTimeQueue.Count > 0) //Dequeue every trigger time and invoke.
        {
            InvokeInfo invokeInfo = InvokeTriggerTimeQueue.Dequeue();
            InvokeCore(invokeInfo);
        }

        RemoveAllUselessSEEs();    // if some mechs are dead or cards are removed, their SideEffectExecute would be removed from EventManager
        OnEventInvokeEndHandler(); //Ready to send data to client ends.
    }
        IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context,
                                                    string requestType, string virtualPath, string physicalPath)
        {
            // 说明:这里不使用virtualPath变量,因为不同的配置,这个变量的值会不一样。
            // 例如:/mvc/*/*.aspx 和 /mvc/*
            // 为了映射HTTP处理器,下面直接使用context.Request.Path

            string requestPath = context.Request.Path;
            string vPath       = context.GetRealVirtualPath();

            // 尝试根据请求路径获取Action
            ControllerResolver controllerResolver = new ControllerResolver(context);
            InvokeInfo         vkInfo             = controllerResolver.GetActionInvokeInfo(vPath);

            // 如果没有找到合适的Action,并且请求的是一个ASPX页面,则按ASP.NET默认的方式来继续处理
            if (vkInfo == null)
            {
                if (requestPath.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase))
                {
                    // 调用ASP.NET默认的Page处理器工厂来处理
                    try {
                        return(_msPageHandlerFactory.GetHandler(context, requestType, requestPath, physicalPath));
                    }
                    catch (Exception ex) {
                        if (controllerResolver.DiagnoseResult != null)
                        {
                            controllerResolver.DiagnoseResult.ErrorMessages.Add("System.Web.UI.PageHandlerFactory不能根据指定的URL地址创建IHttpHandler实例。");
                            controllerResolver.DiagnoseResult.ErrorMessages.Add(ex.Message);

                            return(Http404DebugModule.TryGetHttp404PageHandler(context));
                        }

                        throw;
                    }
                }
            }

            return(ActionHandlerFactory.CreateHandler(vkInfo));
        }
Exemplo n.º 27
0
        internal void ProcessRequest(HttpContext context, ActionHandler handler)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            this.HttpContext = context;
            this.Handler     = handler;
            this.InvokeInfo  = handler.InvokeInfo;

            // 设置 BaseController 的相关属性
            SetController();


            // 进入请求处理阶段
            BeginRequest();

            // 安全检查
            SecurityCheck();

            // 授权检查
            AuthorizeRequest();


            // 执行 Action
            object actionResult = ExecuteAction();

            // 设置输出缓存
            SetOutputCache();

            // 处理方法的返回结果
            OutputResult(actionResult);
        }
Exemplo n.º 28
0
        public void patch(Ice.Object v)
        {
            if (v != null && !typeof(T).IsAssignableFrom(v.GetType()))
            {
                IceInternal.Ex.throwUOE(_type, v.ice_id());
            }

            InvokeInfo info  = getInvokeInfo(_seqType);
            int        count = info.getCount(_seq);

            if (_index >= count) // Need to grow the sequence.
            {
                for (int i = count; i < _index; i++)
                {
                    info.invokeAdd(_seq, default(T));
                }
                info.invokeAdd(_seq, (T)v);
            }
            else
            {
                info.invokeSet(_seq, _index, (T)v);
            }
        }
Exemplo n.º 29
0
    private void InvokeCore(InvokeInfo invokeInfo)
    {
        SideEffectExecute.TriggerTime tt = invokeInfo.TriggerTime;
        ExecutorInfo executorInfo        = invokeInfo.ExecutorInfo;

        Dictionary <int, SideEffectExecute> seeDict = Events[tt];

        SideEffectExecute[] sees = seeDict.Values.ToArray();
        for (int i = 0; i < sees.Length; i++)
        {
            SideEffectExecute see = sees[i];
            if (ObsoleteSEEs.ContainsKey(see.ID))
            {
                continue;                                   //To prevent executed side effects from being executed again.
            }
            if (seeDict.ContainsKey(see.ID))
            {
                bool isTrigger = false;
                if (see.M_ExecuteSetting is ScriptExecuteSettingBase scriptExecuteSettingBase)
                {
                    isTrigger = scriptExecuteSettingBase.IsTrigger(executorInfo, see.M_ExecutorInfo);
                }
                else
                {
                    isTrigger = IsExecuteTrigger(executorInfo, see.M_ExecutorInfo, see.M_ExecuteSetting.TriggerRange); //To check out if this event invokes any side effect.
                }

                if (isTrigger)
                {
                    Trigger(see, executorInfo, tt, see.M_ExecuteSetting.TriggerRange);            // invoke main trigger method.
                }
            }
        }

        Invoke_RemoveSEE(tt, executorInfo); //Remove executed side effects with zero time left.
    }
Exemplo n.º 30
0
 internal ServiceInfo(NamesPair pair, InvokeInfo vkInfo)
 {
     this.NamesPair  = pair;
     this.InvokeInfo = vkInfo;
 }
		public void FindMethod (CallSite site, object o, object[] args)
		{
			if (o == null) {
				throw new NullReferenceException ();
			}

			InvokeInfo info = this.invokeInfo;
			if (info == null) {
				info = new InvokeInfo();
				info.lastObj = new WeakReference (o);
				info.lastArgTypes = new Type[args.Length];
				this.invokeInfo = info;
			} else {
				this.invokeInfo.lastObj.Target = o;
			}

			var arg_len = args.Length;
			for (var i = 0; i < arg_len; i++) {
				info.lastArgTypes[i] = (args != null && args[i]!=null) ? args[i].GetType () : null;
			}

			if (o is ExpandoObject) {
				var expando = (ExpandoObject)o;
				// special case .hasOwnProperty here
				if (name == "hasOwnProperty")
				{
					info.method = o.GetType().GetMethod("hasOwnProperty");
					info.args = args;
					info.del = null;
					info.generation = 0;
				}
				else
				{
					object delObj;
					expando.TryGetValue(name, out delObj);
					Delegate del = delObj as Delegate;
					if (del == null) {
						throw new Exception ("No delegate found with the name '" + name + "'");
					}
					info.method = null;
					info.del = del;
					info.generation = expando.Generation;
				}
			} else {
				MethodInfo method = null;
				bool isStatic;
				System.Type otype;
				if (o is System.Type) {
					// this is a static method invocation where o is the class
					isStatic = true;
					otype = (System.Type)o;
				} else {
					// this is a non-static method invocation
					isStatic = false;
					otype = o.GetType();
				}

				// find method for type that matches argument list
				method = FindMethodForType(site, otype, name, isStatic, args, out info.args);
				if (method == null) {

					if (!isStatic) {
						// find extension methods
						method = FindExtensionMethodForType(site, otype, name, o, args, out info.args);
					}

					if (method == null) {
						throw new Exception("No matching method found for the type '" + otype.FullName + "' with the name '" + name + "'"); 
					}
				}
				info.method = method;
				info.del = null;
				info.generation = 0;
			}

		}