Esempio n. 1
0
        public static async Task RunClientAsync(Stream clientStream)
        {
            await Task.Yield(); // We want this task to run on another thread.

            var clientHandler = new StreamRpcClientHandler();

            using (var reader = new ByLineTextMessageReader(clientStream))
                using (var writer = new ByLineTextMessageWriter(clientStream))
                    using (clientHandler.Attach(reader, writer))
                    {
                        var client  = new JsonRpcClient(clientHandler);
                        var builder = new JsonRpcProxyBuilder
                        {
                            ContractResolver = myContractResolver
                        };
                        var proxy = builder.CreateProxy <ILibraryService>(client);
                        ClientWriteLine("Add books…");
                        await proxy.PutBookAsync(new Book("Somewhere Within the Shadows", "Juan Díaz Canales & Juanjo Guarnido",
                                                          new DateTime(2004, 1, 1),
                                                          "1596878177"));

                        await proxy.PutBookAsync(new Book("Arctic Nation", "Juan Díaz Canales & Juanjo Guarnido",
                                                          new DateTime(2004, 1, 1),
                                                          "0743479351"));

                        ClientWriteLine("Available books:");
                        foreach (var isbn in await proxy.EnumBooksIsbn())
                        {
                            var book = await proxy.GetBookAsync(isbn);

                            ClientWriteLine(book);
                        }
                        ClientWriteLine("Attempt to query for an inexistent ISBN…");
                        try
                        {
                            await proxy.GetBookAsync("test", true);
                        }
                        catch (JsonRpcRemoteException ex)
                        {
                            ClientWriteLine(ex);
                        }
                        ClientWriteLine("Attempt to pass some invalid argument…");
                        try
                        {
                            await proxy.PutBookAsync(null);
                        }
                        catch (JsonRpcRemoteException ex)
                        {
                            ClientWriteLine(ex);
                        }
                        ClientWriteLine("Will shut down server in 5 seconds…");
                        await Task.Delay(5000);

                        proxy.Terminate();
                    }
        }
Esempio n. 2
0
        public LanguageServerSession(JsonRpcClient rpcClient, IJsonRpcContractResolver contractResolver)
        {
            Check.ArgumentNull(nameof(rpcClient), rpcClient);

            RpcClient = rpcClient;
            var builder = new JsonRpcProxyBuilder {
                ContractResolver = contractResolver
            };

            Client = new ClientProxy(builder, rpcClient);
        }
        public SessionState(JsonRpcClient rpcClient, JsonRpcContractResolver contractResolver)
        {
            RpcClient = rpcClient ?? throw new ArgumentNullException(nameof(rpcClient));
            var builder = new JsonRpcProxyBuilder {
                ContractResolver = contractResolver
            };

            Client         = new ClientProxy(builder, rpcClient);
            DocumentStates = new ConcurrentDictionary <Uri, DocumentState>();
            Project        = new SphinxProject();
        }
        public LanguageServerSession(JsonRpcClient rpcClient, IJsonRpcContractResolver contractResolver)
        {
            RpcClient = rpcClient ?? throw new ArgumentNullException(nameof(rpcClient));
            var builder = new JsonRpcProxyBuilder {
                ContractResolver = contractResolver
            };

            Client             = new ClientProxy(builder, rpcClient);
            Documents          = new ConcurrentDictionary <Uri, SessionDocument>();
            DiagnosticProvider = new DiagnosticProvider();
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a client-side proxy method aggregator instance with specified
 /// <see cref="JsonRpcProxyBuilder"/> and <see cref="JsonRpcClient"/>.
 /// </summary>
 /// <param name="proxyBuilder">The builder used to build implementations for the stub interfaces.</param>
 /// <param name="rpcClient">The client used to send JSON RPC requests.</param>
 /// <exception cref="ArgumentNullException">Either <paramref name="proxyBuilder"/> or <paramref name="rpcClient"/> is <c>null</c>.</exception>
 public ClientProxy(JsonRpcProxyBuilder proxyBuilder, JsonRpcClient rpcClient)
 {
     ProxyBuilder  = proxyBuilder ?? throw new ArgumentNullException(nameof(proxyBuilder));
     RpcClient     = rpcClient ?? throw new ArgumentNullException(nameof(rpcClient));
     _Client       = new Lazy <IClient>(() => ProxyBuilder.CreateProxy <IClient>(RpcClient));
     _Document     = new Lazy <IDocument>(() => ProxyBuilder.CreateProxy <IDocument>(RpcClient));
     _Telemetry    = new Lazy <ITelemetry>(() => ProxyBuilder.CreateProxy <ITelemetry>(RpcClient));
     _TextDocument = new Lazy <ITextDocument>(() => ProxyBuilder.CreateProxy <ITextDocument>(RpcClient));
     _Window       = new Lazy <IWindow>(() => ProxyBuilder.CreateProxy <IWindow>(RpcClient));
     _Workspace    = new Lazy <IWorkspace>(() => ProxyBuilder.CreateProxy <IWorkspace>(RpcClient));
 }
Esempio n. 6
0
 public ClientTests(ITestOutputHelper output) : base(output)
 {
     serviceHost = Utility.CreateJsonRpcServiceHost(this);
     handler     = new JsonRpcDirectHandler(serviceHost);
     client      = new JsonRpcClient(handler);
     client.RequestCancelling += (_, e) =>
     {
         ((JsonRpcClient)_).SendNotificationAsync("cancelRequest", JToken.FromObject(new { id = e.RequestId }),
                                                  CancellationToken.None);
     };
     proxyBuilder = new JsonRpcProxyBuilder {
         ContractResolver = Utility.DefaultContractResolver
     };
 }
Esempio n. 7
0
        private async Task RunClientAsync(Stream clientStream)
        {
            await Task.Yield(); // We want this task to run on another thread.

            // Initialize the client connection to the RPC server.
            var clientHandler = new StreamRpcClientHandler();

            using (var reader = new ByLineTextMessageReader(clientStream))
                using (var writer = new ByLineTextMessageWriter(clientStream))
                    using (clientHandler.Attach(reader, writer))
                    {
                        var builder = new JsonRpcProxyBuilder
                        {
                            ContractResolver = MyContractResolver
                        };

                        var proxy = builder.CreateProxy <Shared.IFileMonitor>(new JsonRpcClient(clientHandler));

                        // Create the function hooks after connection to the server.
                        CreateHooks();

                        try
                        {
                            while (true)
                            {
                                Thread.Sleep(500);

                                if (_queue.Count > 0)
                                {
                                    string[] package = null;

                                    lock (_queue)
                                    {
                                        package = _queue.ToArray();

                                        _queue.Clear();
                                    }
                                    await proxy.OnCreateFile(package);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ClientWriteLine(ex.ToString());
                        }
                    }
        }
            public ClientTestHelper(MessageReader reader, MessageWriter writer)
            {
                ClientHandler       = new StreamRpcClientHandler();
                Client              = new JsonRpcClient(ClientHandler);
                ClientMessageReader = reader;
                ClientMessageWriter = writer;
                // We use positional parameters when issuing cancelRequest request. Just for more test coverage.
                Client.RequestCancelling += (_, e) => { Client.SendNotificationAsync("cancelRequest", new JArray(e.RequestId.Value), CancellationToken.None); };
                disposables.Add(ClientHandler.Attach(ClientMessageReader, ClientMessageWriter));

                var proxyBuilder = new JsonRpcProxyBuilder {
                    ContractResolver = Utility.DefaultContractResolver
                };

                ClientStub             = proxyBuilder.CreateProxy <ITestRpcContract>(Client);
                ClientExceptionStub    = proxyBuilder.CreateProxy <ITestRpcExceptionContract>(Client);
                ClientCancellationStub = proxyBuilder.CreateProxy <ITestRpcCancellationContract>(Client);
            }
Esempio n. 9
0
        public async Task ClientInteropTest()
        {
            var host = Utility.CreateJsonRpcServiceHost(this);

            using (var handler = new HttpRpcClientHandler(new JsonRpcHttpMessageDirectHandler(host))
            {
                EndpointUrl = "http://localhost:1234/fakepath"
            })
            {
                var client  = new JsonRpcClient(handler);
                var builder = new JsonRpcProxyBuilder {
                    ContractResolver = Utility.DefaultContractResolver
                };
                var stub1 = builder.CreateProxy <ITestRpcContract>(client);
                var stub2 = builder.CreateProxy <ITestRpcExceptionContract>(client);
                await TestRoutines.TestStubAsync(stub1);

                await TestRoutines.TestStubAsync(stub2);
            }
        }