private void M_Communicator_MessageReceived(object sender, BoxedObject e)
        {
            //Checking incoming data
            if (e.DataType == typeof(MethodCall))
            {
                MethodCall call = (MethodCall)Convert.ChangeType(e.Value, e.DataType);

                //Check if method call request is valid
                MethodInfo method = this.m_ServiceMethods.FirstOrDefault(m => m.Name == call.MethodName);
                if (method != null)
                {
                    object returnValue = null;
                    try
                    {
                        //Calling local method
                        returnValue = method.Invoke(this.m_InternalService, call.Parameters.Values.ToArray());
                    }
                    catch (Exception ex)
                    {
                        //If exception is catched set it as return value
                        returnValue = ex;
                    }

                    if (method.ReturnType != typeof(void) && returnValue.GetType() != typeof(Exception))
                    {
                        //If called method is not a void and no exception occured send the return
                        this.m_Communicator.OutMessages.Enqueue(new BoxedObject(new MethodCall.Response()
                        {
                            MessageId = call.MessageId,
                            Value     = returnValue
                        }));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void M_Communicator_MessageReceived(object sender, BoxedObject e)
        {
            //Checking incoming data
            if (e.DataType == typeof(MethodCall.Response))
            {
                //Response is a method return
                MethodCall.Response response = (MethodCall.Response)Convert.ChangeType(e.Value, e.DataType);

                lock (this.returnLock)
                {
                    //Setting the ResetEvent and the return value
                    if (this.returnValues.ContainsKey(response.MessageId))
                    {
                        this.returnValues[response.MessageId].ReturnValue = response.Value;
                        this.returnValues[response.MessageId].ResetEvent.Set();
                    }
                }
            }
        }