//public async Task CallZomeFunction(JsonRpcHttpClient client) //{ // return await client.Invoke<string>("info/instances").Result; //} public async Task CallZomeFunction(string holoChainServerURI) { try { HttpListener httpListener = new HttpListener(); httpListener.Prefixes.Add("http://localhost:8888/"); httpListener.Start(); HttpListenerContext context = await httpListener.GetContextAsync(); if (context.Request.IsWebSocketRequest) { HttpListenerWebSocketContext webSocketContext = await context.AcceptWebSocketAsync(null); System.Net.WebSockets.WebSocket webSocket = webSocketContext.WebSocket; StreamJsonRpc.JsonRpc client = new StreamJsonRpc.JsonRpc(new WebSocketMessageHandler(webSocket)); client.StartListening(); string result = await client.InvokeAsync <string>("info/instances"); await client.Completion; //while (webSocket.State == WebSocketState.Open) //{ // await webSocket.SendAsync() //} } } catch (Exception ex) { } }
/// <nodoc /> public ProgressReporter([NotNull] StreamJsonRpc.JsonRpc mainRpcChannel, TestContext?testContext) { Contract.Requires(mainRpcChannel != null); m_testContext = testContext; m_mainRpcChannel = mainRpcChannel; }
/// <summary> /// Creates the providers for project management and adds them as targets /// to the JSON-RPC layer. /// </summary> public ProjectManagementProvider(GetAppState getAppState, StreamJsonRpc.JsonRpc rpcChannel) { m_moduleInformationProvider = new ModuleInformationProvider(getAppState); rpcChannel.AddLocalRpcTarget(m_moduleInformationProvider); m_addSourceFileToProjectProvider = new AddSourceFileToProjectProvider(getAppState); rpcChannel.AddLocalRpcTarget(m_addSourceFileToProjectProvider); }
//------------------------------------------------------------------------------------------------ // construction //------------------------------------------------------------------------------------------------ public DeribitTradingService(DeribitService deribit, IMapper mapper, IDeribitJsonRpcProxy rpcproxy, StreamJsonRpc.JsonRpc jsonrpc) { this.deribit = deribit; this.mapper = mapper; this.rpcproxy = rpcproxy; this.jsonrpc = jsonrpc; }
private App(StreamJsonRpc.JsonRpc mainRpcChannel, TestContext testContext) { m_progressReporter = new ProgressReporter(mainRpcChannel, testContext); m_testContext = testContext; m_mainRpcChannel = mainRpcChannel; m_tracer = new Tracer(); // We need to create the project management provider before we start listening on the // RPC channel as you cannot attach them after it has started listening. m_projectManagementProvider = new ProjectManagementProvider(GetAppStateDelegate(), m_mainRpcChannel); }
private App(StreamJsonRpc.JsonRpc mainRpcChannel, TestContext testContext) { m_progressReporter = new ProgressReporter(mainRpcChannel, testContext); m_testContext = testContext; m_mainRpcChannel = mainRpcChannel; m_mainRpcChannel.AddLocalRpcTarget(this, new JsonRpcTargetOptions { AllowNonPublicInvocation = true }); m_tracer = new Tracer(); // We need to create the project management provider before we start listening on the // RPC channel as you cannot attach them after it has started listening. m_projectManagementProvider = new ProjectManagementProvider(GetAppStateDelegate(), m_mainRpcChannel); }
/// <nodoc/> public App(Stream clientStream, Stream serverStream, string pathToLogFile) { Contract.Requires(clientStream != null); Contract.Requires(serverStream != null); Contract.Requires(!string.IsNullOrEmpty(pathToLogFile)); ContentHashingUtilities.SetDefaultHashType(); // Note that we cannot start listening (i.e. use Attach) until // we have finished constructing the app. // Otherwise we can receive an incoming message // before we finish initialization. var jsonRpcChannel = new JsonRpcWithException(clientStream, serverStream, this); m_mainRpcChannel = jsonRpcChannel; m_mainRpcChannel.AddLocalRpcTarget(this, new JsonRpcTargetOptions { AllowNonPublicInvocation = true }); // We need to create the project management provider before we start listening on the // RPC channel as you cannot attach them after it has started listening. m_projectManagementProvider = new ProjectManagementProvider(GetAppStateDelegate(), m_mainRpcChannel); m_tracer = new Tracer(m_mainRpcChannel, pathToLogFile, EventLevel.Verbose, EventLevel.Informational); m_progressReporter = new ProgressReporter(m_mainRpcChannel, testContext: null); Logger.LanguageServerStarted(LoggingContext); Logger.LanguageServerLogFileLocation(LoggingContext, pathToLogFile); jsonRpcChannel.SetLoggingContext(Logger, LoggingContext); // Change minimal number of threads for performance reasons. // 5 is a reasonable number that should prevent thread pool exhaustion and will not spawn too many threads. ThreadPoolHelper.ConfigureWorkerThreadPools(Environment.ProcessorCount, 5); // This must be last after initialization m_mainRpcChannel.StartListening(); SubscribeToUnhandledErrors(); }
public Listener(StreamJsonRpc.JsonRpc rpc, IVsFolderWorkspaceService workspaceService, IServiceProvider site) { this._rpc = rpc; this._rpc.Disconnected += _rpc_Disconnected; // Ignore some common directories _matcher.AddExclude("**/.vs/**/*.*"); // Ignore files that end with ~ or TMP _matcher.AddExclude("**/*~"); _matcher.AddExclude("**/*TMP"); // Depending upon if this is a workspace or a solution, listen to different change events. if (workspaceService != null && workspaceService.CurrentWorkspace != null) { workspaceService.CurrentWorkspace.GetService <IFileWatcherService>().OnFileSystemChanged += OnFileChanged; _root = workspaceService.CurrentWorkspace.Location; } else { var path = GetSolutionDirectory(site); if (path != null) { _solutionWatcher = new System.IO.FileSystemWatcher(); _solutionWatcher.Path = path; _solutionWatcher.IncludeSubdirectories = true; _solutionWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.Size; _solutionWatcher.Changed += OnFileChanged_Sync; _solutionWatcher.Created += OnFileChanged_Sync; _solutionWatcher.Deleted += OnFileChanged_Sync; _solutionWatcher.Renamed += OnFileChanged_Sync; _solutionWatcher.EnableRaisingEvents = true; _root = _solutionWatcher.Path; } } }
//------------------------------------------------------------------------------------------------ // construction //------------------------------------------------------------------------------------------------ public DeribitJsonRpcService ( IDeribitService deribit, IDeribitWebSocketService wsservice, DeribitConfig config ) { // dependencies this.deribit = deribit; this.deribitconfig = config; this.wsservice = wsservice; // logger this.logger = Serilog.Log.ForContext <DeribitJsonRpcService>(); // message formatter JsonMessageFormatter messageformatter = new JsonMessageFormatter() { Encoding = Encoding.UTF8, ProtocolVersion = new Version(2, 0), }; // attach json rpc to websocket WebSocketMessageHandler wsmh = new WebSocketMessageHandler(wsservice.ClientWebSocket); this.JsonRpc = new StreamJsonRpc.JsonRpc(wsmh); // build proxy // https://github.com/microsoft/vs-streamjsonrpc/blob/master/doc/dynamicproxy.md this.RpcProxy = this.JsonRpc.Attach <IDeribitJsonRpcProxy>(new JsonRpcProxyOptions { ServerRequiresNamedArguments = true, }); // tracing if (config.EnableJsonRpcTracing) { var listener = new global::SerilogTraceListener.SerilogTraceListener(); this.JsonRpc.TraceSource.Listeners.Add(listener); this.JsonRpc.TraceSource.Switch.Level = System.Diagnostics.SourceLevels.Information; this.logger.Verbose("JsonRpc tracing enabled"); } }
/// <summary> /// Initializes a new instance of the <see cref="JsonRpc"/> class and immediately starts listening. /// </summary> /// <param name="sendingStream">The stream used to transmit messages. May be null.</param> /// <param name="receivingStream">The stream used to receive messages. May be null.</param> /// <param name="target">An optional target object to invoke when incoming RPC requests arrive.</param> /// <returns>The initialized and listening <see cref="JsonRpc"/> object.</returns> public static JsonRpc Attach(Stream sendingStream, Stream receivingStream, object target = null) { if (sendingStream == null && receivingStream == null) { throw new ArgumentException(Resources.BothReadableWritableAreNull); } var rpc = new JsonRpc(sendingStream, receivingStream, target); try { if (receivingStream != null) { rpc.StartListening(); } return(rpc); } catch { rpc.Dispose(); throw; } }
internal static App CreateForTesting(StreamJsonRpc.JsonRpc jsonRpc, TestContext testContext) { Contract.Requires(jsonRpc != null); return(new App(jsonRpc, testContext)); }
public OutputWindowReporter(StreamJsonRpc.JsonRpc pushRpc) { m_pushRpc = pushRpc; }