Exemplo n.º 1
0
        public bool setReaderID(READER_ID reader_id)
        {
            string cmd = "setReaderID";
            ErrorCode = ERR_CODE_UNKNOWN_RESPONSE;
            ErrorMsg = ERR_MSG_UNKNOWN_RESPONSE;    //default error message

            try
            {
                StringBuilder sbReq = new StringBuilder();

                sbReq.Append(String.Format("{0}API?command={1}&session_id={2}&reader_id={3}&desc={4}", httpUri.AbsoluteUri, cmd, SessionId, reader_id.id, reader_id.desc));

                string resp = sendHTTPRequest(sbReq.ToString());
                if (resp == null) return false;
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(resp);
                if (isCSLResponse(ref doc, cmd) == false) return false;

                XmlNode node = doc.SelectSingleNode("CSL/Ack");
                if (node != null)
                {
                    if (node.InnerXml.StartsWith("OK", StringComparison.OrdinalIgnoreCase))
                    {
                        ErrorCode = ERR_CODE_NO_ERROR;
                        ErrorMsg = "";
                        return true;
                    }
                }
                parseErrorCode(ref doc);
                return false;
            }
            catch
            {
                ErrorCode = ERR_CODE_UNKNOWN_ERROR;
                ErrorMsg = ERR_MSG_UNKNOWN_ERROR;
                return false;
            }
        }
Exemplo n.º 2
0
        public bool getReaderID(out READER_ID rdr)
        {
            string cmd = "getReaderID";
            ErrorCode = ERR_CODE_UNKNOWN_RESPONSE;
            ErrorMsg = ERR_MSG_UNKNOWN_RESPONSE;    //default error message

            rdr.id = "";
            rdr.desc = "";

            try
            {
                StringBuilder sbReq = new StringBuilder();

                sbReq.Append(String.Format("{0}API?command={1}&session_id={2}", httpUri.AbsoluteUri, cmd, SessionId));

                string resp = sendHTTPRequest(sbReq.ToString());
                if (resp == null) return false;
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(resp);
                if (isCSLResponse(ref doc, cmd) == false) return false;

                XmlNode node = doc.SelectSingleNode("CSL/Reader");
                if (node != null)
                {
                    XmlAttributeCollection atts = node.Attributes;
                    if (atts == null) return false;
                    node = atts.GetNamedItem("desc");
                    if (node == null) return false;
                    rdr.desc = node.Value;
                    node = atts.GetNamedItem("reader_id");
                    if (node == null) return false;
                    rdr.id = node.Value;

                    ErrorCode = ERR_CODE_NO_ERROR;
                    ErrorMsg = "";
                    return true;
                }
                parseErrorCode(ref doc);
                return false;
            }
            catch
            {
                ErrorCode = ERR_CODE_UNKNOWN_ERROR;
                ErrorMsg = ERR_MSG_UNKNOWN_ERROR;
                return false;
            }
        }