public LensMessage RegisterFile(FileInfo file, string vendor, string ID, DocKey docKey, char type) { try { if (!file.Exists) { throw new LensException(ErrorIndex.FILE_NOT_EXISTS); } byte[] data = LensMessage.ReadFile(file); String docType = LensMessage.GetDocType(file.Name); return(RegisterBinaryData(data, docType, vendor, ID, docKey, type)); } catch (LensException lex) { throw lex; } catch (SocketException sex) { throw new LensException(ErrorIndex.IO_READ_ERROR, sex); } catch (IOException iex) { throw new LensException(ErrorIndex.IO_READ_ERROR, iex); } 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); } }
public LensMessage RegisterText(string text, string vendor, string ID, DocKey docKey, char type) { return(RegisterBinaryData(LensMessage.ToBytes(text), "", vendor, ID, docKey, type)); }