Esempio n. 1
0
 public async Task RouteNotification(IHandlerDescriptor descriptor, Notification notification)
 {
     using (_logger.TimeDebug("Routing Notification {Method}", notification.Method))
     {
         using (_logger.BeginScope(new KeyValuePair <string, string>[] {
             new KeyValuePair <string, string>("Method", notification.Method),
             new KeyValuePair <string, string>("Params", notification.Params?.ToString())
         }))
         {
             try
             {
                 if (descriptor.Params is null)
                 {
                     await ReflectionRequestHandlers.HandleNotification(descriptor);
                 }
                 else
                 {
                     _logger.LogDebug("Converting params for Notification {Method} to {Type}", notification.Method, descriptor.Params.FullName);
                     var @params = notification.Params.ToObject(descriptor.Params, _serializer.JsonSerializer);
                     await ReflectionRequestHandlers.HandleNotification(descriptor, @params);
                 }
             }
             catch (Exception e)
             {
                 _logger.LogCritical(Events.UnhandledRequest, e, "Failed to handle request {Method}", notification.Method);
             }
         }
     }
 }
        public async Task RouteNotification(IHandlerDescriptor handler, Notification notification)
        {
            try
            {
                Task result;
                if (handler.Params is null)
                {
                    result = ReflectionRequestHandlers.HandleNotification(handler);
                }
                else
                {
                    var @params = notification.Params.ToObject(handler.Params);
                    result = ReflectionRequestHandlers.HandleNotification(handler, @params);
                }

                await result;
            }
            catch (Exception e)
            {
                _logger.LogCritical(Events.UnhandledRequest, e, "Failed to handle request {Method}", notification.Method);
            }
        }
        public async Task RouteNotification(IHandlerDescriptor descriptor, Notification notification)
        {
            using (_logger.TimeDebug("Routing Notification {Method}", notification.Method))
            {
                using (_logger.BeginScope(new KeyValuePair <string, string>[] {
                    new KeyValuePair <string, string>("Method", notification.Method),
                    new KeyValuePair <string, string>("Params", notification.Params?.ToString())
                }))
                {
                    try
                    {
                        if (descriptor.Params is null)
                        {
                            await ReflectionRequestHandlers.HandleNotification(descriptor);
                        }
                        else
                        {
                            _logger.LogDebug("Converting params for Notification {Method} to {Type}", notification.Method, descriptor.Params.FullName);
                            var @params = notification.Params.ToObject(descriptor.Params, _serializer.JsonSerializer);

                            var lspDescriptor = descriptor as ILspHandlerDescriptor;

                            foreach (var preProcessor in _routeMatchers.ForHandlerPreProcessorMatcher()
                                     .SelectMany(strat => strat.FindPreProcessor(lspDescriptor, @params)))
                            {
                                @params = preProcessor.Process(lspDescriptor, @params);
                            }

                            await ReflectionRequestHandlers.HandleNotification(descriptor, @params);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogCritical(Events.UnhandledRequest, e, "Failed to handle request {Method}", notification.Method);
                    }
                }
            }
        }