public Contact ParsePollPresenceAuthNotification(string data) { XmlDocument doc = new XmlDocument(); doc.LoadXml(data); XmlElement nodeId = getXmlNode(doc, "//trans:PresenceAuth-Request//trans:UserID"); Contact contact = new Contact("", nodeId.InnerText, Contact.ContactStatusEnum.authPending); return contact; }
public Contact ParsePollPresenceNotification(string data) { XmlDocument doc = new XmlDocument(); doc.LoadXml(data); XmlElement nodeId = getXmlNode(doc, "//trans:PresenceNotification-Request//trans:Presence//trans:UserID"); XmlElement nodeStatus = getXmlNode(doc, "//trans:PresenceNotification-Request//trans:Presence//pres:PresenceSubList//pres:UserAvailability//pres:PresenceValue"); XmlElement nodeAlias = getXmlNode(doc, "//trans:PresenceNotification-Request//trans:Presence//pres:PresenceSubList//pres:Alias//pres:PresenceValue"); string id = ""; string alias = ""; string status = ""; if (nodeId == null) return null; id = nodeId.InnerText; if (nodeAlias != null) alias = nodeAlias.InnerText; if (nodeStatus != null) status = nodeStatus.InnerText; Contact contact = new Contact(alias, id); switch (status.ToUpper()) { case "AVAILABLE": contact.Status = Contact.ContactStatusEnum.online; break; default: contact.Status = Contact.ContactStatusEnum.offline; break; } return contact; }
/// <summary> /// Connects to SMS2.0 service /// </summary> /// <param name="log">string with user's telephone number</param> /// <param name="nickName">string with the nickname that we want to use</param> /// <returns>Contact list of the user (arralist of Contact class</returns> public ArrayList Connect(string log, string nickName) { ArrayList contacts = new ArrayList(); try { XmlDocument retDoc = null; // ClientCapability-Request retDoc = doSMS20Request(getCapabilityData()); if (retDoc == null) return null; // Service-Request retDoc = doSMS20Request(getServiceData()); if (retDoc == null) return null; // UpdatePresence-Request retDoc = doSMS20Request(getUpdatePresenceData()); if (retDoc == null || !readResultNode(retDoc, "Status")) return null; // GetList-Request retDoc = doSMS20Request(getListData()); if (retDoc == null) return null; bool contactListExists = false; foreach (XmlElement node in getXmlNodes(retDoc, "//msg:WV-CSP-Message//msg:Session//msg:Transaction//trans:TransactionContent//trans:GetList-Response//trans:ContactList")) { if (node.InnerText == "wv:" + log + "/[email protected]") { contactListExists = true; break; } } //GetPresence-Request retDoc = doSMS20Request(getPresenceData("wv:" + log + "@movistar.es")); if (retDoc == null || !readResultNode(retDoc, "GetPresence-Response")) return null; XmlElement nodeAlias = getXmlNode(retDoc, "//msg:WV-CSP-Message//msg:Session//msg:Transaction//trans:TransactionContent//trans:GetPresence-Response//trans:Presence//pres:PresenceSubList//pres:Alias//pres:PresenceValue"); if (nodeAlias == null) { _lastError = "Alias not found"; return null; } _alias = nodeAlias.InnerText; //ListManage-Request retDoc = doSMS20Request(getListManageData(log)); if (retDoc == null || !readResultNode(retDoc, "ListManage-Response")) return null; foreach (XmlElement nodeContact in getXmlNodes(retDoc, "//msg:WV-CSP-Message//msg:Session//msg:Transaction//trans:TransactionContent//trans:ListManage-Response//trans:NickList//trans:NickName")) { string alias = null; string id = null; foreach (XmlElement node in nodeContact.ChildNodes) { switch (node.Name) { case "Name": alias = node.InnerText; break; case "UserID": id = node.InnerText; break; } } Contact contact = new Contact(alias, id); contacts.Add(contact); } if (!contactListExists) { // CreateList-Request (If not exists) retDoc = doSMS20Request(getCreateListData(log, contacts)); if (retDoc == null || !readResultNode(retDoc, "Status")) return null; } // SubscribePresence-Request retDoc = doSMS20Request(getSuscribePresenceData(log)); if (retDoc == null || !readResultNode(retDoc, "Status")) return null; if (nickName != _alias) { // UpdatePresence-Request (If out nick is different than the last one used) retDoc = doSMS20Request(getLiteUpdatePresenceData(nickName)); if (retDoc == null || !readResultNode(retDoc, "Status")) return null; _alias = nickName; } return contacts; } catch (Exception ex) { _lastError = "MAIN EX: " + ex.Message; return null; } }