public LensMessage GetInfo() { String message = "<bgtcmd><info></info></bgtcmd>"; LensMessage inMessage = LensMessage.Create(message, LensMessage.XML_TYPE); return(SendMessage(inMessage)); }
public LensMessage TagBinaryDataWithRTF(byte[] data, string docType, char type) { try { switch (type) { case MSLens.RESUME_TYPE: case MSLens.POSTING_TYPE: break; default: throw new LensException(ErrorIndex.INVALID_DOC_TYPE); } byte[] body = null; int extraLen = 0; if (docType != null && docType.Length > 0) { extraLen += docType.Length; } body = new byte[data.Length + 2 + extraLen]; int index = 0; body[index++] = (byte)type; if (extraLen > 0) { char[] docTypeBytes = docType.ToCharArray(); for (int i = 0; i < docTypeBytes.Length; i++) { body[index++] = (byte)docTypeBytes[i]; } } body[index++] = (byte)'\0'; for (int i = 0; i < data.Length; i++) { body[index++] = data[i]; } //String messageData = LensMessage.toString(body); LensMessage tagMessage = LensMessage.Create(body, LensMessage.TAG_RTF_TYPE); return(SendMessage(tagMessage)); } catch (LensException lex) { throw lex; } catch (Exception ex) { throw new LensException(ErrorIndex.INTERNAL_ERR, ex); } }
public bool Ping() { LensMessage message = LensMessage.Create("", LensMessage.PING_TYPE); if (mTimeoutEnabled) { SendMessage(message, mTransactionTimeout); } else { SendMessage(message, 0); } return(true); }
public LensMessage ConvertBinaryData(byte[] data, string docType) { try { byte[] hint = null; byte[] body = null; if (docType != null) { hint = LensMessage.ToBytes(docType); } if (hint == null || hint.Length < 1) { body = new byte[data.Length + 1]; } else { body = new byte[hint.Length + data.Length + 1]; } int index = 0; if (hint != null) { for (int i = 0; i < hint.Length; i++) { body[index++] = hint[i]; } } body[index++] = Convert.ToByte('\0'); for (int i = 0; i < data.Length; i++) { body[index++] = data[i]; } //String messageData = LensMessage.toString(body); LensMessage convertMessage = LensMessage.Create(body, LensMessage.CONVERT_TYPE); return(SendMessage(convertMessage)); } catch (LensException lex) { throw lex; } catch (Exception ex) { throw new LensException(ErrorIndex.INTERNAL_ERR, ex); } }
public LensMessage Unregister(string vendor, DocKey docKey, char type) { string message = null; switch (type) { case MSLens.RESUME_TYPE: message = "<bgtcmd><unregister type = 'resume' vendor='" + vendor + "' key='" + docKey.GetKey() + "'/></bgtcmd>"; break; case MSLens.POSTING_TYPE: message = "<bgtcmd><unregister type = 'posting' vendor='" + vendor + "' key='" + docKey.GetKey() + "'/></bgtcmd>"; break; default: throw new LensException(ErrorIndex.INVALID_DOC_TYPE); } LensMessage unregMessage = LensMessage.Create(message, LensMessage.XML_TYPE); return(SendMessage(unregMessage)); }
public LensMessage Unregister(string vendor, string docID, DocKey docKey, char type) { String message = null; switch (type) { case MSLens.RESUME_TYPE: message = "<bgtcmd><unregister type = 'resume' vendor='" + vendor + "' id='" + docID + "'/></bgtcmd>"; break; case MSLens.POSTING_TYPE: message = "<bgtcmd><unregister type = 'posting' vendor='" + vendor + "' id='" + docID + "'/></bgtcmd>"; break; default: throw new LensException(ErrorIndex.INVALID_DOC_TYPE); } LensMessage unregMessage = LensMessage.Create(message, LensMessage.XML_TYPE); LensMessage outMessage = SendMessage(unregMessage); String result = outMessage.GetMessageData(); // this is cheating, but we just need to extract the key value int pos = result.IndexOf("key='"); if (pos != -1) { pos += 5; // skip key=' String key = result.Substring(pos, result.IndexOf("'", pos)); docKey.SetKey(ulong.Parse(key)); } else { docKey.SetKey(0); } return(outMessage); }
public LensMessage RegisterBinaryData(byte[] data, string docType, string vendor, string ID, DocKey docKey, char type) { try { LensMessage tagMessage = TagBinaryData(data, docType, type); String result = tagMessage.GetMessageData(); int spos, epos; String cmd = ""; try { switch (type) { case MSLens.RESUME_TYPE: spos = result.IndexOf("<resume"); epos = result.LastIndexOf("</resume>") + 9; cmd = "<bgtcmd><register type='resume' vendor='"; cmd += vendor; cmd += "' id='"; cmd += ID; cmd += "'>"; cmd += result.Substring(spos, epos - spos + 1); cmd += "</register></bgtcmd>"; break; case MSLens.POSTING_TYPE: spos = result.IndexOf("<posting"); epos = result.LastIndexOf("</posting>") + 10; cmd = "<bgtcmd><register type='posting' vendor='"; cmd += vendor; cmd += "' id='"; cmd += ID; cmd += "'>"; cmd += result.Substring(spos, epos); cmd += "</register></bgtcmd>"; break; default: throw new LensException(ErrorIndex.INVALID_DOC_TYPE); } } catch (LensException lex) { throw lex; } catch (IndexOutOfRangeException) { throw new LensException(ErrorIndex.TAG_TEXT_NOT_GENERATED); //return LensMessage.CreateErrorMessage("Tag text not generated."); } LensMessage regMessage = SendMessage(LensMessage.Create(cmd, LensMessage.XML_TYPE)); result = regMessage.GetMessageData(); // this is cheating, but we just need to extract the key value int pos = result.IndexOf("key='"); if (pos != -1) { pos += 5; // skip key=' string key = result.Substring(pos, result.IndexOf("'", pos)); docKey.SetKey(ulong.Parse(key)); } else { docKey.SetKey(0); } return(regMessage); } catch (LensException lex) { throw lex; } catch (Exception ex) { throw new LensException(ErrorIndex.INTERNAL_ERR, ex); } }
private LensMessage ReadMessage() { Header header = null; byte[] buffer = null; if (!IsOpen()) { throw new LensException(ErrorIndex.SESSION_NOT_OPEN); } // Read the message header first try { header = ReadHeader(); } catch (SocketException sex) { if (mTimedout) { throw new LensException(ErrorIndex.TIMEOUT_ERROR); } throw new LensException(ErrorIndex.INVALID_HEADER, sex); } catch (IOException ex) { if (mTimedout) { throw new LensException(ErrorIndex.TIMEOUT_ERROR); } throw new LensException(ErrorIndex.INVALID_HEADER, ex); } if (header.GetLength() == 0) { throw new LensException(ErrorIndex.INVALID_MESSAGE, new ApplicationException("The message length returned from LENS is 0.")); } //System.Threading.Thread.Sleep(2000);//Delay needed for slower Systems //Read the message body try { // Shouldn't we checkig the validity of the message size?? // EP 15/01/07: Yes, we should! Checked below. try { buffer = new byte[header.GetDataLength()]; int index = 0; while (index < buffer.Length) { int i = tcpClient.GetStream().ReadByte(); if (i == -1) { break; } buffer[index++] = (byte)i; } } catch (SocketException sex) { if (mTimedout) { throw new LensException(ErrorIndex.TIMEOUT_ERROR); } throw new LensException(ErrorIndex.READ_ERROR, sex); } catch (IOException iex) { if (mTimedout) { throw new LensException(ErrorIndex.TIMEOUT_ERROR); } throw new LensException(ErrorIndex.READ_ERROR, iex); } catch (Exception ex) { throw new ApplicationException(string.Format("Failed to read message body. Header values:" + " length = {0}, flags = {1}, version = {2}, ID = {3}, type = {4}", header.GetLength(), header.GetFlags(), header.GetVersion(), header.GetMessageID(), header.GetMessageType()), ex); } } catch (Exception ex) { throw new LensException(ErrorIndex.INTERNAL_ERR, ex); } //Compose a LensMessage and send back to caller return(LensMessage.Create(header, buffer)); }