public void SetPresence(JabberContactShow show, Hashtable status, int priority) { if ((Object)show != null) { Show = show; Status = status; Priority = priority; //string stanza = XMPP.IM.Presence (); } }
void loadData() { if (Type != null) { if (Type != "available" && Type != "unavailable" && Type != "subscribe" && Type != "subscribed" && Type != "unsubscribe" && Type != "unsubscribed" && Type != "probe" && Type != "error") { throw new IncorrectTypeOfAttribute("Presence \"type\" = {available, unavailable, subscribe, subscribed, unsubscribe, unsusbscribed, probe, error}."); } } else { Type = "available"; } XmlNode presence = XmlDoc.FirstChild; if (presence.Name == "presence") { if (Type == "error") { // TODO: Error } else { if (presence.HasChildNodes) { bool show = false, priority = false; if (Type == "unavailable") { show = true; Show = JabberContactShow.Offline; } foreach (XmlNode node in presence.ChildNodes) { switch (node.Name) { case "show": { if (!show) { show = true; if (node.Attributes != null && node.Attributes.Count == 0) { string showText = node.InnerText; if (showText != "away" && showText != "chat" && showText != "xa" && showText != "dnd") { throw new IncorrectTypeOfNode("Presence \"show\" = {away, chat, xa, dnd}."); } else { Show = (JabberContactShow)Enum.Parse(typeof(JabberContactShow), showText, true); } } else { throw new IncorrectNumberOfAttributes("Presence \"show\" must not have attributes."); } } else { throw new IncorrectNumberOfNodes("Presence must have only one \"show\" child."); } break; } case "status": { if (node.Attributes != null && node.Attributes.Count <= 1) { if (Status == null) { Status = new Hashtable(); } string lang = null; if (node.Attributes["xml:lang"] != null) { lang = node.Attributes["xml:lang"].InnerText; } if (lang == null) { lang = ""; } Status.Add(lang, node.InnerText); } else { throw new IncorrectNumberOfAttributes("Presence \"status\" can only have one \"xml:lang\" attribute."); } break; } case "priority": { if (!priority) { priority = true; if (node.Attributes != null && node.Attributes.Count == 0) { Priority = Convert.ToInt32(node.InnerText); if (Priority < -128 || Priority > 127) { throw new IncorrectTypeOfNode("Presence \"priority\" must be in range [-128:+127]."); } } else { throw new IncorrectNumberOfAttributes("Presence \"priority\" must not have attributes."); } } else { throw new IncorrectNumberOfNodes("Presence must have only one \"priority\" child."); } break; } } } if (!show) { Show = JabberContactShow.Online; } } } } else { // launch error: incorrect node throw new IncorrectNameOfNode("Expecting \"presence\" node."); } }