Esempio n. 1
0
        internal static object QueryInternal(this FastRpcClient fastRpcClient, string title, ICustomTuple customTuple, Type returnType, IRpcSerializer rpcSerializer, string extention = null, bool throwIfErrorResponseCode = false)
        {
            if (rpcSerializer == null)
            {
                throw new ArgumentNullException(nameof(rpcSerializer));
            }

            if (customTuple == null)
            {
                throw new ArgumentNullException(nameof(customTuple));
            }

            var encoding = RpcExtentionSettings.DefaultEncoding;

            var response = fastRpcClient.Query(
                encoding.GetBytes(title),
                encoding.GetBytes(rpcSerializer.Serialize(customTuple)),
                extention == null ? FrameFormat.EmptyBytes : encoding.GetBytes(extention),
                throwIfErrorResponseCode);

            if (returnType == typeof(void))
            {
                return(null);
            }

            var responseContent = response.ReadContentString();

            if (string.IsNullOrEmpty(responseContent))
            {
                return(null);
            }

            return(rpcSerializer.Deserialize(responseContent, returnType));
        }
Esempio n. 2
0
        internal static async Task <TResponse> SendReceiveAsync <TRequest, TResponse>(LightweightMethodStub methodStub, TRequest request, IRpcSerializer serializer)
            where TRequest : class
            where TResponse : class
        {
            TResponse response;

            var context      = new LightweightCallContext(new TestRpcEndPoint(), null, ImmutableArray <KeyValuePair <string, ImmutableArray <byte> > > .Empty, CancellationToken.None);
            var requestPipe  = new Pipe();
            var responsePipe = new Pipe();
            var duplexPipe   = new DirectDuplexPipe(requestPipe.Reader, responsePipe.Writer);

            await using (var pipeline = new TestPipeline(duplexPipe))
            {
                var payload = new ReadOnlySequence <byte>(serializer.Serialize(request));

                var frame = new LightweightRpcFrame(RpcFrameType.UnaryRequest, null, 1, methodStub.OperationName, RpcOperationFlags.None, 0, payload, null);

                await methodStub.HandleMessage(pipeline, frame, null, context);

                var readResult = await responsePipe.Reader.ReadAsync();

                var  buffer           = readResult.Buffer;
                bool hasResponseFrame = LightweightRpcFrame.TryRead(ref buffer, 65536, out var responseFrame) == RpcFrameState.Full;
                Assert.IsTrue(hasResponseFrame);

                response = (TResponse)serializer.Deserialize(responseFrame.Payload, typeof(TResponse));

                return(response);
            }
        }
Esempio n. 3
0
        public string Proceed(string content)
        {
            var handlerTarget  = ObjectFactory.CreateInstance(HandlerTargetType);
            var parameterTuple = (ICustomTuple)RpcSerializer.Deserialize(content, HandlerParameterTupleType);
            var parameterArray = parameterTuple.ToObjectArray();
            var result         = _fastInvokeHandler.Invoke(handlerTarget, parameterArray);

            if (result == null)
            {
                return(string.Empty);
            }
            return(RpcSerializer.Serialize(result));
        }