Пример #1
0
        public void Login()
        {
            QrzDataResult result;
            WebClient webClient = ThreadWebClient;
            result = new QrzDataResult(string.Format("{0}?username={1}&password={2}&agent={3}", c_ServerUrl, m_Username, m_Password, c_Agent), webClient);

            XmlElement sessionElement = result.GetElement("/qrz:QRZDatabase/qrz:Session/qrz:Key");
            if (sessionElement != null)
            {
                m_Session = sessionElement.InnerText;
                Debug.WriteLine("Session key: " + m_Session);
            }
            else
            {
                XmlElement errorElement = result.GetElement("/qrz:QRZDatabase/qrz:Session/qrz:Error");
                if (errorElement != null)
                    throw new InvalidDataException("Login to QRZ.com failed: " + errorElement.InnerText);
                else
                    throw new InvalidDataException("Login to QRZ.com failed");
            }
        }
Пример #2
0
        private QrzEntry LookupCallsign(string callsign, bool firstTry)
        {
            if (m_Session == null)
                Login();
            QrzDataResult result = new QrzDataResult(string.Format("{0}?s={1}&callsign={2}", c_ServerUrl, m_Session, callsign), ThreadWebClient);

            XmlElement callsignElement = result.GetElement("/qrz:QRZDatabase/qrz:Callsign");
            if (callsignElement != null)
            {
                QrzEntry entry = new QrzEntry();
                entry.Callsign = callsignElement["call"].InnerText;
                if (callsignElement["grid"] != null)
                    entry.Locator = new Locator(callsignElement["grid"].InnerText);
                if (callsignElement["fname"] != null && callsignElement["name"] != null)
                    entry.Name = callsignElement["fname"].InnerText + " " + callsignElement["name"].InnerText;
                return entry;
            }
            else
            {
                XmlElement errorElement = result.GetElement("/qrz:QRZDatabase/qrz:Session/qrz:Error");
                if (errorElement != null)
                {
                    // If our session key has expired, nuke it and try again - once!
                    if (errorElement.InnerText == "Invalid session key" && firstTry)
                    {
                        m_Session = null;
                        return LookupCallsign(callsign, false);
                    }

                    throw new InvalidDataException("QRZ.com lookup failed: " + errorElement.InnerText);
                }
                else
                {
                    throw new InvalidDataException("QRZ.com lookup failed");
                }
            }
        }