Example #1
0
        protected ProtoConnection(TcpClient tcpClient, IStreamManager streamManager, ServiceAssembly serviceAssembly)
            : base(tcpClient)
        {
            Require.NotNull(streamManager, "streamManager");
            Require.NotNull(serviceAssembly, "serviceAssembly");

            _serviceAssembly = serviceAssembly;
            _sendStreamManager = new SendStreamManager();
            _receiveStreamManager = new ReceiveStreamManager(streamManager);
        }
Example #2
0
        public Client(object client, ServiceAssembly serviceAssembly, Service service)
        {
            Require.NotNull(client, "client");
            Require.NotNull(serviceAssembly, "serviceAssembly");

            Instance = client;
            ServiceAssembly = serviceAssembly;
            Service = service;

            SyncRoot = new object();
        }
Example #3
0
        public Service(Type serviceType, ServiceMethodCollection methods, ServiceMessageByIdCollection messagesById, ServiceAssembly serviceAssembly)
        {
            Require.NotNull(serviceType, "serviceType");
            Require.NotNull(methods, "methods");
            Require.NotNull(messagesById, "messagesById");
            Require.NotNull(serviceAssembly, "serviceAssembly");

            Type = serviceType;
            ServiceAssembly = serviceAssembly;
            Methods = methods;
            Messages = messagesById;

            var callbackAttributes = serviceType.GetCustomAttributes(typeof(ProtoCallbackContractAttribute), true);

            if (callbackAttributes.Length > 0)
            {
                Debug.Assert(callbackAttributes.Length == 1);

                CallbackContractType = ((ProtoCallbackContractAttribute)callbackAttributes[0]).Type;
            }
        }
Example #4
0
        public ServiceMethod(MethodInfo method, ProtoMethodAttribute attribute, ServiceAssembly assembly)
        {
            Require.NotNull(method, "method");
            Require.NotNull(attribute, "attribute");

            _attribute = attribute;

            var parameters = method.GetParameters();

            if (parameters.Length != 1)
                throw new ProtoChannelException(String.Format("Invalid service method signature for method '{0}'; service methods must accept a ProtoMessage parameter and must return a ProtoMessage or void", method));

            ServiceMessage request;

            if (!assembly.MessagesByType.TryGetValue(parameters[0].ParameterType, out request))
                throw new ProtoChannelException(String.Format("Assembly '{0}' does not contain a message type '{1}'", assembly.Assembly, parameters[0].ParameterType));

            Request = request;

            if (method.ReturnType != typeof(void))
            {
                if (attribute.IsOneWay)
                    throw new ProtoChannelException(String.Format("Invalid service method signature for method '{0}'; IsOneWay methods must return void", method));

                ServiceMessage response;

                if (!assembly.MessagesByType.TryGetValue(method.ReturnType, out response))
                    throw new ProtoChannelException(String.Format("Assembly '{0}' does not contain a message type '{1}'", assembly.Assembly, method.ReturnType));

                Response = response;

                _invoker = ReflectionOptimizer.BuildMessageInvoker(method);
            }
            else
            {
                _voidInvoker = ReflectionOptimizer.BuildVoidMessageInvoker(method);
            }
        }