public StreamJsonRpcAPICompatibillity()
        {
            var(sjrClientPipes, serverDomainPipes) = FullDuplexStream.CreatePipePair();
            this.SJRclient = new JsonRpc(new HeaderDelimitedMessageHandler(sjrClientPipes, new JsonMessageFormatter()));
            this.SJRclient.StartListening();
            serverDomain = new PipeIOHeaderDelimitedRpcDomain(serverDomainPipes.Input, serverDomainPipes.Output);
            _            = serverDomain.StartAsync();

            var server = new Server();
            var entry  = RpcMethodEntry.FromDelegate <Action>(server.NoOp);

            serverDomain.AddMethod(nameof(Server.NoOp), entry);
            var mulEntry = RpcMethodEntry.FromDelegate <Mul>(server.Mul);

            serverDomain.AddMethod(nameof(Server.Mul), mulEntry);

            var cancelEntry = RpcMethodEntry.FromDelegate <CancelAsync>(server.CancelAsync);

            serverDomain.AddMethod(nameof(Server.CancelAsync), cancelEntry);
            var(sjrServerPipes, clientDomainPipes) = FullDuplexStream.CreatePipePair();
            this.SJRserver = new JsonRpc(new HeaderDelimitedMessageHandler(sjrServerPipes, new JsonMessageFormatter()));
            this.SJRserver.AddLocalRpcTarget(new Server());
            this.SJRserver.StartListening();
            clientDomain = new PipeIOHeaderDelimitedRpcDomain(clientDomainPipes.Input, clientDomainPipes.Output);
            _            = clientDomain.StartAsync();

            noOpMethodHandle   = new RpcMethodHandle <Empty>(clientDomain, nameof(Server.NoOp));
            mulMethodHandle    = new RpcMethodHandle <MulParams, int>(clientDomain, nameof(Server.Mul));
            cancelMethodHandle = new RpcMethodHandle <Empty>(clientDomain, nameof(Server.SJRCancelAsync));
        }
Ejemplo n.º 2
0
        public void CancelByID()
        {
            var entry = RpcMethodEntry.FromDelegate <InjectIDAsync>(async id =>
            {
                var cancellationToken = id.AsRpcCancellationToken();
                await Task.Delay(1919810, cancellationToken);
            });

            var handle = NewMethodAtA <ValueTuple>("WaitForBeast", entry);

            var cts = new CancellationTokenSource();

            var req = handle.RequestAsync(new ValueTuple(), cts.Token);

            //await Task.Delay(810);

            cts.Cancel();
            Assert.ThrowsAsync <OperationCanceledException>(() => req.AsTask());
        }
Ejemplo n.º 3
0
        public VSStreamJsonRpc()
        {
            var duplex = FullDuplexStream.CreatePipePair();

            this.SJRclientRpc = new JsonRpc(new HeaderDelimitedMessageHandler(duplex.Item1, new JsonMessageFormatter()));
            this.SJRclientRpc.StartListening();
            this.SJRserverRpc = new JsonRpc(new HeaderDelimitedMessageHandler(duplex.Item2, new JsonMessageFormatter()));
            this.SJRserverRpc.AddLocalRpcTarget(new Server());
            this.SJRserverRpc.StartListening();

            var(aPipes, bPipes) = FullDuplexStream.CreatePipePair();
            var domainA = new IO.PipeIOHeaderDelimitedRpcDomain(aPipes.Input, aPipes.Output);
            var domainB = new IO.PipeIOHeaderDelimitedRpcDomain(bPipes.Input, bPipes.Output);

            _ = domainA.StartAsync();
            _ = domainB.StartAsync();
            var entry = RpcMethodEntry.FromDelegate <Action>(new Server().NoOp);

            domainA.AddMethod(nameof(Server.NoOp), entry);
            rpcMethodHandle = new RpcMethodHandle <Empty>(domainB, nameof(Server.NoOp));
        }