Exemplo n.º 1
0
        private void HandleNotification(string method, JToken parameters)
        {
            NotificationMethod notificationMethod = null;

            notificationMethods.TryGetValue(method, out notificationMethod);
            if (notificationMethod == null)
            {
                WriteServerLog(String.Format("No notification handler was registered for method \"{0}\"", method));
            }
            else
            {
                NotificationType notificationType = notificationMethod.Type;
                object           objParams        = null;
                if (parameters != null)
                {
                    objParams = parameters.ToObject(notificationType.ParamsType);
                }
                try
                {
                    notificationMethod.HandleNotification(notificationType, objParams);
                }
                catch (Exception e)
                {
                    WriteServerLog(String.Format("Notification handler for {0} failed : {1}", notificationType.GetType().Name, e.Message));
                    ResponseResultOrError error = new ResponseResultOrError()
                    {
                        code = ErrorCodes.InternalError, message = e.Message, data = parameters?.ToString()
                    };
                    Reply(method, error);
                }
            }
        }
Exemplo n.º 2
0
        private void HandleNotification(string method, JToken parameters)
        {
            NotificationMethod notificationMethod = null;

            notificationMethods.TryGetValue(method, out notificationMethod);
            if (notificationMethod == null)
            {
                WriteServerLog(String.Format("No notification handler was registered for method \"{0}\"", method));
            }
            else
            {
                NotificationType notificationType = notificationMethod.Type;
                object           objParams        = null;
                if (parameters != null)
                {
                    objParams = parameters.ToObject(notificationType.ParamsType);
                }
                try
                {
                    notificationMethod.HandleNotification(notificationType, objParams);
                }
                catch (Exception e)
                {
                    WriteServerLog(String.Format("Notification handler for {0} failed : {1}", notificationType.GetType().Name, e.Message));
                }
            }
        }