private void packet(String data) { XElement xmlData = XElement.Parse(data); switch (xmlData.Name.LocalName) { case "biznot": protocolVersion = xmlData.Attribute("version").Value; connected(); break; case "auth": { var response = xmlData.Elements(); foreach (XElement element in response) { if (element.Name.LocalName == "response") { MChatResponse mChatResponse = new MChatResponse { code = int.Parse(element.Attribute("code").Value), message = element.Value }; protocolResponse?.Invoke(BNSProtocolState.Authentication, mChatResponse); if (mChatResponse.code == 200) { register(); } } } } break; case "register": { var response = xmlData.Elements(); foreach (XElement element in response) { if (element.Name.LocalName == "response") { MChatResponse mChatResponse = new MChatResponse { code = int.Parse(element.Attribute("code").Value), message = element.Value }; protocolResponse?.Invoke(BNSProtocolState.Registration, mChatResponse); } } } break; case "payment": { var response = xmlData.Elements(); foreach (XElement element in response) { if (element.Name.LocalName == "response") { MChatResponse mChatResponse = new MChatResponse { code = int.Parse(element.Attribute("code").Value), message = element.Value }; protocolResponse?.Invoke(BNSProtocolState.PaymentNotification, mChatResponse); Disconnect(); } } } break; default: break; } }