コード例 #1
0
 public JsonRpcDirectHandler(IJsonRpcServiceHost serviceHost)
 {
     if (serviceHost == null)
     {
         throw new ArgumentNullException(nameof(serviceHost));
     }
     ServiceHost = serviceHost;
 }
コード例 #2
0
        public static void Main(string[] args)
        {
            var debugMode = args.Any(a => a.Equals("--debug", StringComparison.OrdinalIgnoreCase));

            if (debugMode)
            {
                logWriter           = File.CreateText("messages-" + DateTime.Now.ToString("yyyyMMdd") + ".log");
                logWriter.AutoFlush = true;
            }
            using (logWriter)
                using (var cin = Console.OpenStandardInput())
                    using (var bcin = new BufferedStream(cin))
                        using (var cout = Console.OpenStandardOutput())
                            using (var reader = new PartwiseStreamMessageReader(bcin))
                                using (var writer = new PartwiseStreamMessageWriter(cout))
                                {
                                    var contractResolver = new JsonRpcContractResolver
                                    {
                                        NamingStrategy          = new CamelCaseJsonRpcNamingStrategy(),
                                        ParameterValueConverter = new CamelCaseJsonValueConverter(),
                                    };
                                    var clientHandler = new StreamRpcClientHandler();
                                    var client        = new JsonRpcClient(clientHandler);
                                    if (debugMode)
                                    {
                                        // We want to capture log all the LSP server-to-client calls as well
                                        clientHandler.MessageSending += (_, e) =>
                                        {
                                            lock (logWriter)
                                            {
                                                logWriter.WriteLine("{0} <C{1}", Utility.GetTimeStamp(), e.Message);
                                            }
                                        };
                                        clientHandler.MessageReceiving += (_, e) =>
                                        {
                                            lock (logWriter) logWriter.WriteLine("{0} >C{1}", Utility.GetTimeStamp(), e.Message);
                                        };
                                    }
                                    // Configure & build service host
                                    var session = new LanguageServerSession(client, contractResolver);
                                    IJsonRpcServiceHost host = BuildServiceHost(logWriter, contractResolver, debugMode);
                                    var serverHandler        = new StreamRpcServerHandler(host,
                                                                                          StreamRpcServerHandlerOptions.ConsistentResponseSequence |
                                                                                          StreamRpcServerHandlerOptions.SupportsRequestCancellation);
                                    serverHandler.DefaultFeatures.Set(session);
                                    // If we want server to stop, just stop the "source"
                                    using (serverHandler.Attach(reader, writer))
                                        using (clientHandler.Attach(reader, writer))
                                        {
                                            // Wait for the "stop" request.
                                            session.CancellationToken.WaitHandle.WaitOne();
                                        }
                                    logWriter?.WriteLine("Exited");
                                }
        }
コード例 #3
0
 public RequestContext(IJsonRpcServiceHost serviceHost, IServiceFactory serviceFactory,
                       IFeatureCollection features, RequestMessage request, CancellationToken cancellationToken)
 {
     ServiceHost    = serviceHost ?? throw new ArgumentNullException(nameof(serviceHost));
     ServiceFactory = serviceFactory;
     Request        = request ?? throw new ArgumentNullException(nameof(request));
     Features       = features;
     if (!request.IsNotification)
     {
         Response = new ResponseMessage(request.Id);
     }
     CancellationToken = cancellationToken;
 }
コード例 #4
0
ファイル: ClientTests.cs プロジェクト: qipa/JsonRpc.Standard
 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
     };
 }
コード例 #5
0
 static void Main(string[] args)
 {
     using (Stream cin = Console.OpenStandardInput())
         using (BufferedStream bcin = new BufferedStream(cin))
             using (Stream cout = Console.OpenStandardOutput())
                 using (PartwiseStreamMessageReader reader = new PartwiseStreamMessageReader(bcin))
                     using (PartwiseStreamMessageWriter writer = new PartwiseStreamMessageWriter(cout))
                     {
                         JsonRpcContractResolver contractResolver = new JsonRpcContractResolver
                         {
                             NamingStrategy          = new CamelCaseJsonRpcNamingStrategy(),
                             ParameterValueConverter = new CamelCaseJsonValueConverter(),
                         };
                         StreamRpcClientHandler clientHandler = new StreamRpcClientHandler();
                         JsonRpcClient          client        = new JsonRpcClient(clientHandler);
                         clientHandler.MessageSending += (_, e) =>
                         {
                             Console.Error.WriteLine("Sending: " + e.Message);
                         };
                         clientHandler.MessageReceiving += (_, e) =>
                         {
                             Console.Error.WriteLine("Receiving: " + e.Message);
                         };
                         LanguageServerSession     session = new LanguageServerSession(client, contractResolver);
                         JsonRpcServiceHostBuilder builder = new JsonRpcServiceHostBuilder {
                             ContractResolver = contractResolver
                         };
                         builder.UseCancellationHandling();
                         builder.Register(typeof(Program).GetTypeInfo().Assembly);
                         builder.Intercept(async(context, next) =>
                         {
                             Console.Error.WriteLine("Request: " + context.Request);
                             await next();
                             Console.Error.WriteLine("Response: " + context.Response);
                         });
                         IJsonRpcServiceHost    host          = builder.Build();
                         StreamRpcServerHandler serverHandler = new StreamRpcServerHandler(host,
                                                                                           StreamRpcServerHandlerOptions.ConsistentResponseSequence | StreamRpcServerHandlerOptions.SupportsRequestCancellation);
                         serverHandler.DefaultFeatures.Set(session);
                         using (serverHandler.Attach(reader, writer))
                             using (clientHandler.Attach(reader, writer))
                             {
                                 // Wait for the "stop" request.
                                 session.CancellationToken.WaitHandle.WaitOne();
                             }
                     }
 }
コード例 #6
0
 public StreamRpcServerHandler(IJsonRpcServiceHost serviceHost,
                               StreamRpcServerHandlerOptions options) : base(serviceHost)
 {
     Options = options;
     if ((options & StreamRpcServerHandlerOptions.SupportsRequestCancellation) ==
         StreamRpcServerHandlerOptions.SupportsRequestCancellation)
     {
         requestCtsDict             = new ConcurrentDictionary <MessageId, CancellationTokenSource>();
         requestCancellationFeature = new RequestCancellationFeature(this);
     }
     else
     {
         requestCtsDict             = null;
         requestCancellationFeature = null;
     }
     preserveResponseOrder = (options & StreamRpcServerHandlerOptions.ConsistentResponseSequence) ==
                             StreamRpcServerHandlerOptions.ConsistentResponseSequence;
 }
コード例 #7
0
ファイル: RpcService.cs プロジェクト: TheDarkCode/CoreHook
        public void HandleConnection(IPC.IConnection connection)
        {
            Console.WriteLine($"Connection received from pipe {_pipeName}");

            var pipeServer = connection.ServerStream;

            IJsonRpcServiceHost host = BuildServiceHost(_service);

            var serverHandler = new StreamRpcServerHandler(host);

            serverHandler.DefaultFeatures.Set(_session);

            using (var reader = new ByLineTextMessageReader(pipeServer))
                using (var writer = new ByLineTextMessageWriter(pipeServer))
                    using (serverHandler.Attach(reader, writer))
                    {
                        // Wait for exit
                        _session.CancellationToken.WaitHandle.WaitOne();
                    }
        }
コード例 #8
0
 public StreamRpcServerHandler(IJsonRpcServiceHost serviceHost) : this(serviceHost,
                                                                       StreamRpcServerHandlerOptions.None)
 {
 }
コード例 #9
0
 /// <inheritdoc />
 public AspNetCoreRpcServerHandler(IJsonRpcServiceHost serviceHost) : base(serviceHost)
 {
     UpdateFullContentType();
 }
コード例 #10
0
 public JsonRpcHttpMessageDirectHandler(IJsonRpcServiceHost serviceHost)
 {
     ServiceHost = serviceHost ?? throw new ArgumentNullException(nameof(serviceHost));
 }
コード例 #11
0
 public JsonRpcServerHandler(IJsonRpcServiceHost serviceHost)
 {
     ServiceHost = serviceHost ?? throw new ArgumentNullException(nameof(serviceHost));
 }
コード例 #12
0
 /// <inheritdoc />
 public AspNetCoreRpcServerHandler(IJsonRpcServiceHost serviceHost) : base(serviceHost)
 {
 }
コード例 #13
0
 public JsonRpcController(IJsonRpcServiceHost jsonRpcServiceHost)
 {
     _JsonRpcServiceHost = jsonRpcServiceHost;
 }