/// <summary> /// Returns the current notification as string (json) /// </summary> /// <param name="args">the arguments listed in the message</param> /// <returns>the current notification as string (json)</returns> public string ToString(params KeyValuePair <string, string>[] args) { JsonNotificationPacket packet = new JsonNotificationPacket(NotificationType, args); if (NoReply) { packet.Values.Add(JsonNotificationPacket.NoReply_string, JsonNotificationPacket.NoReply_string); } return(packet.Serialize()); }
/// <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; } }