Ejemplo n.º 1
0
        public object Execute(string method, params object[] arguments)
        {
            lock (_lock)
            {
                IntercomMessage message = new IntercomMessage(method, arguments);
                _formatter.Serialize(_serviceStream, message);
                var result = (IntercomMessage)_formatter.Deserialize(_serviceStream);

                if (result.MethodName == Constants.Result)
                {
                    return(result.Arguments[0]);
                }
                else if (result.MethodName == Constants.Exception)
                {
                    throw (Exception)result.Arguments[0];
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 2
0
        private void DoCycle(CancellationToken cancellationToken)
        {
            do
            {
                IntercomMessage resultMessage = null;
                try
                {
                    var  message = (IntercomMessage)_formatter.Deserialize(_serviceStream);
                    bool oneWay  = _typeInfoProvider.GetIsOneWayMethod(message.MethodName);

                    if (oneWay)
                    {
                        Task.Run(() => ExecuteMethod(message));
                        _formatter.Serialize(_serviceStream, new IntercomMessage(Constants.OneWay, null));
                    }
                    else
                    {
                        var result = ExecuteMethod(message);

                        resultMessage = new IntercomMessage(Constants.Result, new object[] { result });
                        _formatter.Serialize(_serviceStream, resultMessage);
                    }
                }
                catch (SerializationException) // connection is broken
                {
                    if (!_reconnectable)
                    {
                        ConnectionClosed?.Invoke(this, EventArgs.Empty);
                        Dispose();
                    }
                }
                catch (Exception ex)
                {
                    resultMessage = new IntercomMessage(Constants.Exception, new object[] { ex });
                    _formatter.Serialize(_serviceStream, resultMessage);
                }
            } while (!cancellationToken.IsCancellationRequested && !_reconnectable);
        }
Ejemplo n.º 3
0
        private object ExecuteMethod(IntercomMessage message)
        {
            var methodInfo = _typeInfoProvider.GetMethodInfo(message.MethodName);

            return(methodInfo.Invoke(_service, message.Arguments));
        }