Ejemplo n.º 1
0
        public static List <ChatMessage> GetChatMessages(DateTime?since)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            if (since.HasValue)
            {
                parameters.Add("since", DateTimeToolkit.ConvertToSubsonicTimestamp(since.Value).ToString(CultureInfo.InvariantCulture));
            }
            // Make the request
            Stream theStream = MakeGenericRequest("getChatMessages", parameters);

            List <ChatMessage> messages = new List <ChatMessage>();

            using (StreamReader sr = new StreamReader(theStream))
            {
                string result = sr.ReadToEnd();

                // Parse the resulting XML string into an XmlDocument
                XmlDocument myXML = new XmlDocument();
                myXML.LoadXml(result);
                if (myXML.ChildNodes[1].Name != "subsonic-response")
                {
                    return(messages);
                }
                if (myXML.ChildNodes[1].FirstChild.Name != "chatMessages")
                {
                    return(messages);
                }
                var messagesElement = myXML.ChildNodes[1].FirstChild;

                messages.AddRange(from XmlElement ch in messagesElement.ChildNodes where ch.Name == "chatMessage" select ChatMessage.FromXml(ch));
            }

            return(messages);
        }
Ejemplo n.º 2
0
 public static ChatMessage FromXml(XmlElement ch)
 {
     return(new ChatMessage(
                ch.Attributes["username"].Value,
                ch.Attributes["message"].Value,
                DateTimeToolkit.ConvertFromSubsonicTimestamp(double.Parse(ch.Attributes["time"].Value)) //todo : timestamps are wrong. nobody cares to tell me what i'm looking @
                ));
 }