Exemplo n.º 1
0
        /// <summary>
        /// Handles Messages sent from the client
        /// </summary>
        /// <param name="response">the message from the client</param>
        public virtual void HandleResponse(NotificationResponse response)
        {
            try
            {
                if (TraceMessagesClient && response.NotificationType != NotificationType.KeepAlive && response.NotificationType != NotificationType.Acknowledge)
                {
                    Logger.LogTrace("WebSocket: Server << Client: " + NotificationResponse.LogNotification(response));
                }

                if (response.IsMessage || (response.NotificationType == NotificationType.KeepAlive && NotifyForKeepalives))
                {
                    OnNotification(response);
                }
            }
            catch (Exception e)
            {
                if (TraceMessagesClient)
                {
                    try
                    {
                        response.Reply(Notification.Invalid());
                    }
                    catch (Exception)
                    {
                        return;
                    }
                }

                Logger.LogError("Invalid WebSocket Response from Client\n" + e.SafeToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses a Notification response from string
        /// </summary>
        /// <param name="input">the response string</param>
        /// <param name="response">the current response</param>
        /// <param name="URL">the url of the request</param>
        public static void ParseNotificationResponse(string input, NotificationResponse response, string URL)
        {
            if (input.Length <= 0)
            {
                return;
            }

            JsonNotificationPacket packet;

            try
            {
                packet = new JsonNotificationPacket(input);
            }
            catch (Exception)
            {
                if (input.Contains(NotificationType.Invalid.ToString()))
                {
                    return;
                }

                response.Reply(Notification.Invalid());
                return;
            }

            response._values          = packet.Values;
            response.NotificationType = packet.NotificationType;
            response._noreply         = packet.noreply;

            string ssid = packet.SSID;

            response.SessionData = new SessionIdentificatorSlim(URL, ssid);

            switch (response.NotificationType)
            {
            case NotificationType.Message:
                response.IsMessage = true;
                packet.Values.TryGetValue("msg", out response.Message);
                break;

            default:
                response.IsMessage = false;
                break;
            }
        }