public void TestInstanceMethods() { var handler1 = new MethodHandler <Event>(intBox1.Increment); var handler2 = new MethodHandler <Event>(intBox1.Increment); var handler3 = new MethodHandler <Event>(intBox1.Decrement); var handler4 = new MethodHandler <Event>(intBox2.Decrement); // Properties Assert.True(handler1.Action.Equals(handler2.Action)); Assert.False(handler2.Action.Equals(handler3.Action)); Assert.False(handler3.Action.Equals(handler4.Action)); // Invocation Event e = new Event(); handler1.Invoke(e); Assert.Equal(1, intBox1.Value); handler2.Invoke(e); Assert.Equal(2, intBox1.Value); handler3.Invoke(e); Assert.Equal(1, intBox1.Value); Assert.Equal(0, intBox2.Value); handler4.Invoke(e); Assert.Equal(1, intBox1.Value); Assert.Equal(-1, intBox2.Value); // Equality Assert.True(handler1.Equals(handler2)); Assert.False(handler2.Equals(handler3)); Assert.False(handler3.Equals(handler4)); }
static public Variable ExecuteMethodDeclaration(node methodNode) { //string type = methodNode.nodes[0].body; string Identifier = methodNode.nodes[0].body; string[] args = new string[methodNode.nodes[1].nodes.Count]; int i = 0; foreach (node argNode in methodNode.nodes[1].nodes) { args[i] = argNode.body; i++; } node body = methodNode.nodes[2]; if (!MethodHandler.Exists(Identifier)) { MethodHandler.Add(Identifier, args, body); } else { SkryptMethod found = MethodHandler.GetSk(Identifier); int foundIndex = MethodContainer.SKmethods.IndexOf(found); MethodContainer.SKmethods[foundIndex].methodNode = body; } Variable returnVariable = new Variable(Identifier, "method", body); return(returnVariable); }
private void Register(object service, SOAServiceAttribute[] soa) { if (soa.Length > 0) { foreach (Type itype in soa[0].Services) { if (itype.IsInterface) { foreach (MethodInfo method in itype.GetMembers()) { StringBuilder key = new StringBuilder(); List<Type> pst = new List<Type>(); key.Append(itype.Name).Append(".").Append(method.Name); key.Append("("); ParameterInfo[] pis = method.GetParameters(); for (int i = 0; i < pis.Length; i++) { pst.Add(pis[i].ParameterType); if (i > 0) key.Append(","); key.Append(pis[i].ParameterType.Name); } key.Append(")"); MethodInfo implMethod = service.GetType().GetMethod(method.Name, pst.ToArray()); if (implMethod != null) { MethodHandler handler = new MethodHandler { Obj = service, Method = implMethod, Parameters = pis }; mHandlers[key.ToString()] = handler; } } } } } }
public void ShouldRunTwoMethodsOnceEach() { var counter1 = 0; Action @delegate1 = () => { counter1++; }; MethodHandler.RunOnce(@delegate1); var counter2 = 0; Action @delegate2 = () => { counter2++; }; MethodHandler.RunOnce(@delegate2); MethodHandler.RunOnce(@delegate1); MethodHandler.RunOnce(@delegate2); Assert.AreEqual(1, counter1); Assert.AreEqual(1, counter2); }
public void ShouldRunTwoMethodsOnceEachOnSeperateThreads() { var counter1 = 0; var counter2 = 0; var random = new Random(); Action @delegate1 = () => { counter1++; Thread.Sleep(random.Next(500, 2500)); }; Action @delegate2 = () => { counter2++; Thread.Sleep(random.Next(500, 2500)); }; var thread1 = new Thread(() => MethodHandler.RunOnce(@delegate1)); var thread2 = new Thread(() => MethodHandler.RunOnce(@delegate2)); var thread3 = new Thread(() => MethodHandler.RunOnce(@delegate1)); var thread4 = new Thread(() => MethodHandler.RunOnce(@delegate2)); thread1.Start(); thread2.Start(); thread3.Start(); thread4.Start(); thread1.Join(); thread2.Join(); thread3.Join(); thread4.Join(); Assert.AreEqual(1, counter1); Assert.AreEqual(1, counter2); }
/** * Add a method handler to this object. The interface for the method handler must have already * been added by calling AddInterface(). * * @param member Interface member implemented by handler. * @param handler Method handler. * * @return * - QStatus.OK if the method handler was added. * - An error status otherwise */ public QStatus AddMethodHandler(InterfaceDescription.Member member, MethodHandler handler) { InternalMethodHandler internalMethodHandler = (IntPtr bus, IntPtr m, IntPtr msg) => { MethodHandler h = handler; h(new InterfaceDescription.Member(m), new Message(msg)); }; _methodHandlerDelegateRefHolder.Add(internalMethodHandler); GCHandle membGch = GCHandle.Alloc(member._member, GCHandleType.Pinned); MethodEntry entry; entry.member = membGch.AddrOfPinnedObject(); entry.method_handler = Marshal.GetFunctionPointerForDelegate(internalMethodHandler); GCHandle gch = GCHandle.Alloc(entry, GCHandleType.Pinned); QStatus ret = alljoyn_busobject_addmethodhandlers(_busObject, gch.AddrOfPinnedObject(), (UIntPtr)1); gch.Free(); membGch.Free(); return(ret); }
public void TestInstanceMethods() { var handler1 = new MethodHandler<Event>(intBox1.Increment); var handler2 = new MethodHandler<Event>(intBox1.Increment); var handler3 = new MethodHandler<Event>(intBox1.Decrement); var handler4 = new MethodHandler<Event>(intBox2.Decrement); // Properties Assert.True(handler1.Action.Equals(handler2.Action)); Assert.False(handler2.Action.Equals(handler3.Action)); Assert.False(handler3.Action.Equals(handler4.Action)); // Invocation Event e = new Event(); handler1.Invoke(e); Assert.AreEqual(1, intBox1.Value); handler2.Invoke(e); Assert.AreEqual(2, intBox1.Value); handler3.Invoke(e); Assert.AreEqual(1, intBox1.Value); Assert.AreEqual(0, intBox2.Value); handler4.Invoke(e); Assert.AreEqual(1, intBox1.Value); Assert.AreEqual(-1, intBox2.Value); // Equality Assert.True(handler1.Equals(handler2)); Assert.False(handler2.Equals(handler3)); Assert.False(handler3.Equals(handler4)); }
public static int BeginInvokeNoneException(MethodHandler method) { ThreadStart start = null; int runResult = 0; try { if (start == null) { start = delegate { try { method(); runResult = 1; } catch { runResult = -1; } }; } new Thread(start).Start(); while (runResult == 0) { Thread.Sleep(50); } } catch { } return(runResult); }
private void Compile() { TextEditor.Document.MarkerStrategy.RemoveAll(marker => true); var profile = (CompilerProfile)SelVersion.SelectedItem; var isUnitySilverLightProfile = profile == Compiler.UnitySilverLightProfile; _compiler.Compile(TextEditor.Text, GetReferences(true, profile), Settings.Default.Language, profile); if (!_compiler.Errors.HasErrors) { MethodDefinition = FindMatchingMethod(); if (isUnitySilverLightProfile && MethodDefinition != null) { CecilHelper.PatchAssemblyNames(MethodDefinition.Module, Compiler.MicrosoftPublicKeyToken, Compiler.MicrosoftVersion, Compiler.UnitySilverLightPublicKeyToken, Compiler.UnitySilverLightVersion); } ButOk.Enabled = MethodDefinition != null; VerticalSplitContainer.Panel2Collapsed = true; } else { MethodDefinition = null; ButOk.Enabled = false; CompilerErrorBindingSource.DataSource = _compiler.Errors; VerticalSplitContainer.Panel2Collapsed = false; //Add error markers to the TextEditor foreach (CompilerError error in _compiler.Errors) { if (error.Line <= 0) { continue; } var offset = TextEditor.Document.PositionToOffset(new TextLocation(error.Column, error.Line - 1)); var length = TextEditor.Document.LineSegmentCollection[error.Line - 1].Length - error.Column + 1; if (length <= 0) { length = 1; } else { offset--; } var color = (error.IsWarning) ? Color.Orange : Color.Red; var marker = new TextMarker(offset, length, TextMarkerType.WaveLine, color) { ToolTip = error.ErrorText }; TextEditor.Document.MarkerStrategy.AddMarker(marker); } } TextEditor.Refresh(); MethodHandler.HandleItem(MethodDefinition); }
private void LoadController(IApplication application) { Utils.LoadAssembly(a => { foreach (Type type in a.GetTypes()) { if (IKende.IKendeCore.GetTypeAttributes<ControllerAttribute>(type, false).Length > 0 && !type.IsAbstract) { "load {0} controller".Log4Info(type); object controller = Activator.CreateInstance(type); Controllers.Add(controller); foreach (System.Reflection.MethodInfo method in type.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)) { try { ParameterInfo[] pis = method.GetParameters(); if (pis.Length == 2 && (pis[0].ParameterType == typeof(ISession))) { IMethodHandler handler = new MethodHandler(controller, method, application); mControllerHandlers[pis[1].ParameterType] = handler; "load {0}->{1} action success".Log4Info(type, method.Name); } } catch (Exception e_) { "load {0}->{1} action error".Log4Error(e_, type, method.Name); } } } } }); }
protected static BaseHandler GetMember(ScriptState luaState, object o, string memberName) { var runtime = LuaRuntimePool.GetRuntime(luaState); var type = o as Type; if (type != null) { // index(t, k) remove k param // call static method、field、protery LuaCore.RemoveValue(luaState, 1); } else { type = o.GetType(); } var key = ScriptHelper.GenerateKey(type, memberName); var handler = runtime.ClassMgr.Cache[key] as BaseHandler; if (handler == null) { #region Create Handler const BindingFlags flags = ReflectionHelper.DefBindingFlags | BindingFlags.Static; var members = type.GetMember(memberName, flags); if (members.Length > 0) { var member = members[0]; switch (member.MemberType) { case MemberTypes.Field: handler = new FieldHandler(luaState); handler.Initilaze(new[] { ReflectionHelper.GetField((FieldInfo)member) }); break; case MemberTypes.Property: handler = new PropertyHandler(luaState); handler.Initilaze(new[] { ReflectionHelper.GetProperty((PropertyInfo)member) }); break; case MemberTypes.Method: handler = new MethodHandler(luaState); handler.Initilaze(new MethodFinder(type, memberName, members)); break; } } if (handler != null) { runtime.ClassMgr.Cache.Add(key, handler); } #endregion } if (handler != null) { handler.ChangeInstance(o); } return(handler); }
internal FastMethod(ConstructorInfo method, bool doNotCreate = false) { parameters = method.GetParameters(); this.method = method; #if NET472 || NETCOREAPP2_1 fastMethod = EmitHelper.CreateMethodHandler(method, doNotCreate); #endif }
/// <summary> /// Construct a new <see cref="FastMethod"/> associated with an existing method. /// </summary> /// <param name="method">The method.</param> /// <remarks>the constructor is kept private as the FastMethod constructor itself is expensive and instance MUST be cached for performance improvement</remarks> internal FastMethod(MethodBase method) { parameters = method.GetParameters(); this.method = method; #if NET472 || NETCOREAPP2_1 fastMethod = EmitHelper.CreateMethodHandler(method); #endif }
internal FastMethod(ConstructorInfo method, bool doNotCreate = false) { parameters = method.GetParameters(); this.method = method; #if __NET__ || __NETCORE__ fastMethod = EmitHelper.CreateMethodHandler(method, doNotCreate); #else #endif }
/// <summary> /// Construct a new <see cref="FastMethod"/> associated with an existing method. /// </summary> /// <param name="method">The method.</param> /// <remarks>the constructor is kept private as the FastMethod constructor itself is expensive and instance MUST be cached for performance improvement</remarks> internal FastMethod(MethodBase method) { parameters = method.GetParameters(); this.method = method; #if __NET__ || __NETCORE__ fastMethod = EmitHelper.CreateMethodHandler(method); #else #endif }
public void CleanUp() { var module = null as ModularityModule; while (ModularityApplicationObserver.Modules.Any()) { ModularityApplicationObserver.Modules.TryDequeue(out module); } MethodHandler.ClearHandlers(); }
public static void Main() { MethodHandler mh = MethodSample; C a = new C("Hello", "hello"); C b = new C("World", "world"); C c = new C("!", "!!!"); mh(b, a, c); }
public static void InvokeNoneException(MethodHandler method) { try { method(); } catch { } }
public static void RegisterHandler(MethodHandler parent, StreamingHubHandler[] hubHandlers) { var handlers = VerifyDuplicate(hubHandlers); var hashDict = new UniqueHashDictionary <StreamingHubHandler>(handlers); lock (cache) { cache.Add(parent, hashDict); } }
public static T Invoke <T>(MethodHandler <T> method, int timeout) { ThreadStart start = null; T result = default(T); Exception exception = null; DateTime now = DateTime.Now; try { if (start == null) { start = delegate { try { result = method(); } catch (Exception exception1) { exception = exception1; } }; } Thread thread = new Thread(start); thread.Start(); while (thread.IsAlive) { if (timeout > 0) { TimeSpan span = (TimeSpan)(DateTime.Now - now); if (span.TotalMilliseconds > timeout) { goto Label_0082; } } Application.DoEvents(); Thread.Sleep(5); } goto Label_00A6; Label_0082: exception = new Exception("Method invoke has time out"); thread.Abort(); } catch (Exception e) { //exception = exception; } Label_00A6: if (exception != null) { throw exception; } return(result); }
internal void Handle() { try { Console.WriteLine("Begin resolving requests..."); Message request = ReceiveRequest(clientSocket); string methods = request.Content; Console.WriteLine("Methods"); Console.WriteLine(request.Content); string transResponses = ""; string[] transMeth = methods.Split("&"); List <Transaction> transactions = new List <Transaction>(); Console.WriteLine(transMeth.Length); foreach (string tranMeth in transMeth) { Transaction transaction = new Transaction(); transactions.Add(transaction); transaction.SetOperations(tranMeth); ProviderTransaction providerTransaction = new ProviderTransaction(); providerTransaction.StoreTransaction(transaction); System.Threading.Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(transaction.Run)); myThread.Start(); //myThread.Join(); } Exception exception = null; Message response = null; MethodHandler methodHandler = null; //tratare lista metode Thread.Sleep(2000); response = new Message(); foreach (Transaction t in transactions) { response.Content = t.response; if (exception != null) { response = new Message(); response.Content = exception.Message; } SendResponse(clientSocket, response); Console.WriteLine("Response sent"); } } catch (Exception serviceException) { Console.WriteLine("Service exception " + serviceException.Message); } finally { clientSocket.Shutdown(SocketShutdown.Both); clientSocket.Close(); } }
public void ShouldRunOnce() { var counter = 0; Action @delegate = () => { counter++; }; MethodHandler.RunOnce(@delegate); MethodHandler.RunOnce(@delegate); Assert.AreEqual(1, counter); }
public void OnStreamEvent(Notify notify) { bool onStatus = notify.ServiceCall.ServiceMethodName.Equals("onStatus"); if (!onStatus) { if (notify.ServiceCall.ServiceMethodName.Equals("onMetaData")) { RaiseOnMetaData(notify.ServiceCall.Arguments[0] as IDictionary); } if (notify.ServiceCall.ServiceMethodName.Equals("onPlayStatus")) { RaiseOnPlayStatus(notify.ServiceCall.Arguments[0] as IDictionary); } MethodInfo mi = MethodHandler.GetMethod(_client.GetType(), notify.ServiceCall.ServiceMethodName, notify.ServiceCall.Arguments, false, false); if (mi != null) { ParameterInfo[] parameterInfos = mi.GetParameters(); object[] args = new object[parameterInfos.Length]; notify.ServiceCall.Arguments.CopyTo(args, 0); TypeHelper.NarrowValues(args, parameterInfos); try { InvocationHandler invocationHandler = new InvocationHandler(mi); object result = invocationHandler.Invoke(_client, args); } catch (Exception exception) { notify.ServiceCall.Exception = exception; notify.ServiceCall.Status = FluorineFx.Messaging.Rtmp.Service.Call.STATUS_INVOCATION_EXCEPTION; //log.Error("Error while invoking method " + call.ServiceMethodName + " on client", exception); } } else { string msg = __Res.GetString(__Res.Invocation_NoSuitableMethod, notify.ServiceCall.ServiceMethodName, _client.GetType().Name); this.RaiseNetStatus(new FluorineException(msg)); } } else { object[] args = notify.ServiceCall.Arguments; ASObject statusASO = null; if ((args != null) && (args.Length > 0)) { statusASO = args[0] as ASObject; } this.RaiseNetStatus(statusASO); } }
static void Main() { MethodHandler a = MethodSampleA; MethodHandler b = MethodSampleB; MethodHandler c = MethodSampleC; A instance1 = a("Hello"); A instance2 = b("World"); A instance3 = c("!"); Console.WriteLine(instance1.Name); Console.WriteLine(instance2.Name); Console.WriteLine(instance3.Name); }
public static void Invoke(MethodHandler method, int timeout) { ThreadStart start = null; Exception exception = null; DateTime now = DateTime.Now; try { if (start == null) { start = delegate { try { method(); } catch (Exception exception1) { exception = exception1; } }; } Thread thread = new Thread(start); thread.Start(); while (thread.IsAlive) { if (timeout > 0) { TimeSpan span = (TimeSpan)(DateTime.Now - now); if (span.TotalMilliseconds > timeout) { goto Label_0072; } } Thread.Sleep(10); } goto Label_0096; Label_0072: exception = new Exception("Method invoke has time out"); thread.Abort(); } catch (Exception e) { //exception = exception; } Label_0096: if (exception != null) { throw exception; } }
public static void Main() { MethodHandler da = MethodSampleA; MethodHandler db = MethodSampleB; MethodHandler dc = MethodSampleC; C a = new C("Hello", "hello"); C b = new C("World", "world"); C c = new C("!", "!!!"); Console.WriteLine(da(a)); Console.WriteLine(db(b)); Console.WriteLine(dc(c)); }
private bool Compile() { TextEditor.Document.MarkerStrategy.RemoveAll(MarkerSelector); _compiler.Compile(TextEditor.Text, GetReferences(true), Settings.Default.Language, SelVersion.Text); if (!_compiler.Errors.HasErrors) { MethodDefinition = FindMatchingMethod(); ButOk.Enabled = MethodDefinition != null; VerticalSplitContainer.Panel2Collapsed = true; } else { MethodDefinition = null; ButOk.Enabled = false; CompilerErrorBindingSource.DataSource = _compiler.Errors; VerticalSplitContainer.Panel2Collapsed = false; //Add error markers to the TextEditor foreach (CompilerError error in _compiler.Errors) { if (error.Line > 0) { int offset = TextEditor.Document.PositionToOffset(new TextLocation(error.Column, error.Line - 1)); int length = TextEditor.Document.LineSegmentCollection[error.Line - 1].Length - error.Column + 1; if (length <= 0) { length = 1; } else { offset--; } Color color = (error.IsWarning) ? Color.Orange : Color.Red; var marker = new TextMarker(offset, length, TextMarkerType.WaveLine, color) { ToolTip = error.ErrorText }; TextEditor.Document.MarkerStrategy.AddMarker(marker); } } } TextEditor.Refresh(); MethodHandler.HandleItem(MethodDefinition); return(_compiler.Errors.HasErrors); }
public ClientActionHandler(MethodInfo method) { this.MethodInfo = method; MethodHandler = new MethodHandler(method); ResultType = method.ReturnType; PropertyInfo pi = method.ReturnType.GetProperty("Result", BindingFlags.Public | BindingFlags.Instance); if (pi != null) { ResultProperty = new PropertyHandler(pi); } IsTaskResult = ResultType.BaseType == typeof(Task) || ResultType == typeof(Task); IsVoid = ResultType == typeof(void); ResponseType = GetResponseType(); }
public SCollect(object inInstance, Type type, IReflectionProvider provider) { _instance = inInstance; bool isHashSet = type.IsHashSet(); if (isHashSet) { _addToHashSet = provider.GetDelegate(type.GetMethod("Add")); _list = null; } else { _addToHashSet = null; _list = inInstance as IList; } }
/// <summary> /// Registers a method that can be called as a command. /// </summary> /// <param name="confirmationRequired">True to confirm the command before its execution.</param> /// <param name="uniqueName">The unique command name.</param> /// <param name="o">The object instance that holds the method.</param> /// <param name="method">The method.</param> /// <param name="parallelMode">Parallel command mode.</param> /// <param name="enabled">A companion function that knows how to compute whether the command is enabled or not.</param> /// <returns>The registered command handler.</returns> public ICommandHandler Register(bool confirmationRequired, NormalizedPath uniqueName, object o, MethodInfo method, ParallelCommandMode parallelMode, Func <bool> enabled = null) { if (_commands.ContainsKey(uniqueName)) { throw new ArgumentException($"Already registered command '{uniqueName}'.", nameof(uniqueName)); } var parameters = method.GetParameters(); if (parameters.Length == 0 || !typeof(IActivityMonitor).IsAssignableFrom(parameters[0].ParameterType)) { throw new ArgumentException($"Method {method} for command '{uniqueName}' must have a first IActivityMonitor parameter.", nameof(method)); } var h = new MethodHandler(confirmationRequired, uniqueName, o, method, parallelMode, parameters, enabled); _commands.Add(uniqueName, h); return(h); }
/// <summary> /// 通过委托方法添加方法缓存 /// </summary> /// <param name="handler">委托</param> /// <param name="parames">委托的参数,按顺序</param> /// <param name="maxErrorTimes">重复执行次数,如果超过则需手动处理</param> public static void AddMethodCacheByHandler(MethodHandler handler, object[] parames, int maxErrorTimes = 10) { System.Threading.Tasks.Task.Run(() => { MethodCache methodCache = new MethodCache() { MethodHandler = handler, Parameters = parames, MaxErrorTimes = maxErrorTimes }; string error; bool result = Execute(methodCache, out error); if (!result) { AddMethodCache(methodCache); } }); }
public ActionHandler(Type controllerType, MethodInfo method, object controller) { ControllerType = controllerType; Controller = controller; Method = method; MethodHandler = new MethodHandler(method); ResultType = method.ReturnType; PropertyInfo pi = method.ReturnType.GetProperty("Result", BindingFlags.Public | BindingFlags.Instance); if (pi != null) { ResultProperty = new PropertyHandler(pi); } foreach (var p in method.GetParameters()) { Parameters.Add(new ActionParameter(p)); } }
/// <summary> /// Registers a method that can be called as a command. /// </summary> /// <param name="confirmationRequired">True to confirm the command before its execution.</param> /// <param name="uniqueName">The unique command name.</param> /// <param name="o">The object instance that holds the method.</param> /// <param name="method">The method.</param> /// <param name="enabled">A companion function that knows how to compte whether the command is enabled or not.</param> /// <returns>The registered command handler.</returns> public ICommandHandler Register(bool confirmationRequired, NormalizedPath uniqueName, object o, MethodInfo method, Func <bool> enabled = null) { if (_commands.ContainsKey(uniqueName)) { throw new ArgumentException($"Already registered command '{uniqueName}'.", nameof(uniqueName)); } var parameters = method.GetParameters(); if (parameters.Length == 0 || !typeof(IActivityMonitor).IsAssignableFrom(parameters[0].ParameterType)) { throw new ArgumentException($"Method {method} for command '{uniqueName}' must have a first IActivityMonitor parameter.", nameof(method)); } var parallelAttribute = method.GetCustomAttribute <ParallelCommandAttribute>(); var backgroundAttribute = method.GetCustomAttribute <BackgroundCommandAttribute>(); bool?runParallel = parallelAttribute == null ? false : parallelAttribute.AlwaysRunInParallel ? true : (bool?)null; bool?runBackground = backgroundAttribute == null ? false : backgroundAttribute.AlwaysRunInBackground ? true : (bool?)null; var h = new MethodHandler(confirmationRequired, runParallel, runBackground, uniqueName, o, method, parameters, enabled); _commands.Add(uniqueName, h); return(h); }
public void TestStaticMethods() { var handler1 = new MethodHandler<Event>(IntBox.StaticIncrement); var handler2 = new MethodHandler<Event>(IntBox.StaticIncrement); var handler3 = new MethodHandler<Event>(IntBox.StaticDecrement); // Properties Assert.True(handler1.Action.Equals(handler2.Action)); Assert.False(handler2.Action.Equals(handler3.Action)); // Invocation Event e = new Event(); handler1.Invoke(e); Assert.AreEqual(1, IntBox.StaticValue); handler2.Invoke(e); Assert.AreEqual(2, IntBox.StaticValue); handler3.Invoke(e); Assert.AreEqual(1, IntBox.StaticValue); // Equality Assert.True(handler1.Equals(handler2)); Assert.False(handler2.Equals(handler3)); }
public SpeedTester(MethodHandler methodToTest) { this.method = methodToTest; }
/// <summary> /// Executes the method immediately, using a coroutine host global to your Unity game. /// </summary> /// <returns>The async.</returns> /// <param name="callback">An optional callback when this method returns (which may never happen).</param> public virtual Coroutine ExecuteAsync(MethodHandler callback = null) { this.OnUntypedResponse += callback; return (Coroutine)this; }
/** * Add a method handler to this object. The interface for the method handler must have already * been added by calling AddInterface(). * * @param member Interface member implemented by handler. * @param handler Method handler. * * @return * - QStatus.OK if the method handler was added. * - An error status otherwise */ public QStatus AddMethodHandler(InterfaceDescription.Member member, MethodHandler handler) { InternalMethodHandler internalMethodHandler = (IntPtr bus, IntPtr m, IntPtr msg) => { MethodHandler h = handler; h(new InterfaceDescription.Member(m), new Message(msg)); }; _methodHandlerDelegateRefHolder.Add(internalMethodHandler); GCHandle membGch = GCHandle.Alloc(member._member, GCHandleType.Pinned); MethodEntry entry; entry.member = membGch.AddrOfPinnedObject(); entry.method_handler = Marshal.GetFunctionPointerForDelegate(internalMethodHandler); GCHandle gch = GCHandle.Alloc(entry, GCHandleType.Pinned); QStatus ret = alljoyn_busobject_addmethodhandlers(_busObject, gch.AddrOfPinnedObject(), (UIntPtr)1); gch.Free(); membGch.Free(); return ret; }
private void LoadSoa(IApplication application) { Utils.LoadAssembly(a => { foreach (Type type in a.GetTypes()) { SOAServiceAttribute[] soa = IKende.IKendeCore.GetTypeAttributes<SOAServiceAttribute>(type, false); if (soa.Length > 0 && !type.IsAbstract) { foreach (Type itype in soa[0].Services) { if (itype.IsInterface) { object service = Activator.CreateInstance(type); foreach (MethodInfo method in itype.GetMembers()) { StringBuilder key = new StringBuilder(); List<Type> pst = new List<Type>(); key.Append(itype.Name).Append(".").Append(method.Name); key.Append("("); ParameterInfo[] pis = method.GetParameters(); for (int i = 0; i < pis.Length; i++) { pst.Add(pis[i].ParameterType); if (i > 0) key.Append(","); key.Append(pis[i].ParameterType.Name); } key.Append(")"); MethodInfo implMethod = service.GetType().GetMethod(method.Name, pst.ToArray()); if (implMethod != null) { MethodHandler handler = new MethodHandler(service, implMethod, mApplication); handler.Parameters = implMethod.GetParameters(); mSoaHandlers[key.ToString()] = handler; } "Load SOA Service {0}".Log4Info(key); } } } } } }); }