示例#1
0
        /// <summary>
        /// Dispatch the requests and get the responses.
        /// </summary>
        /// <param name="serviceName">The service name to dispatch.</param>
        /// <param name="requests">The requests to handle.</param>
        /// <param name="cancellationToken">The cancellation token which can cancel this method.</param>
        /// <returns>The handled response.</returns>
        public async Task <JsonRpcResponse[]> DispatchRequestsAsync(string serviceName, JsonRpcRequest[] requests, CancellationToken cancellationToken = default)
        {
            var service = JsonRpcCallManager.GetService(serviceName);

            if (service == null)
            {
                throw new InvalidOperationException($"Service {serviceName} does not exist.");
            }
            if (requests.Length == 1)
            {
                var request  = requests[0];
                var response = await GetResponseAsync(service, request, cancellationToken).ConfigureAwait(false);

                return(new[] { response });
            }
            //batch call.
            var responseList = new List <JsonRpcResponse>();

            foreach (var request in requests)
            {
                var response = await GetResponseAsync(service, request, cancellationToken).ConfigureAwait(false);

                if (response != null)
                {
                    responseList.Add(response);
                }
            }

            return(responseList.ToArray());
        }
示例#2
0
        /// <summary>
        /// Get service's SMD data by service name.
        /// </summary>
        /// <param name="serviceName">The service name to handle.</param>
        /// <returns>The SMD data for the service.</returns>
        public Task <byte[]> GetServiceSmdData(string serviceName)
        {
            var service = JsonRpcCallManager.GetService(serviceName);

            if (service == null)
            {
                throw new InvalidOperationException($"Service {serviceName} does not exist.");
            }
            return(Task.FromResult(service.SmdData));
        }
示例#3
0
 /// <summary>
 /// Check whether the service exists.
 /// </summary>
 /// <param name="serviceName">The service name.</param>
 /// <returns>True exists otherwise false.</returns>
 public bool ServiceExists(string serviceName)
 {
     return(JsonRpcCallManager.GetService(serviceName) != null);
 }