} // AccumulateByte // Subroutine to write the partial to a file...should only be called on block boundaries. public void WritePartialToFile() { try { if (bytData.Length < 255) { return; } var messageStore = new MessageStore(DatabaseFactory.Get()); // // Write or append the byte data to the output file // var bytOrig = messageStore.GetTemporaryInboundMessage(strMID); int intLen = bytOrig.Length; if (intLen > 0) { Array.Resize(ref bytOrig, intLen + bytData.Length + 1); bytData.CopyTo(bytOrig, intLen); messageStore.SaveTemporaryInboundMessage(strMID, bytOrig); } else { messageStore.SaveTemporaryInboundMessage(strMID, bytData); } bytData = new byte[0]; } catch (Exception ex) { _log.Error("[PartialSessions, WritePartialToFile] Error: " + ex.Message); } } // WritePartialToFile
} // PurgeCurrentPartial // Function to retrieve the partial file to be re processed by MessageInbound public byte[] RetrievePartial(string MID) { var messageStore = new MessageStore(DatabaseFactory.Get()); byte[] bytFiledata = messageStore.GetTemporaryInboundMessage(MID); if (bytFiledata.Length == 0) { blnFirstRcvdBlk = false; blnRemoveHdr8 = false; } return(bytFiledata); } // RetrievePartial
private int IsPartialMessage(string MID, string Length) { // Function to check and return if any partially received MIDs are saved // Returns 0 if none or if current file size >= Length or an error, // otherwise the length of data already received. var intBytesReceived = default(int); byte[] bytFiledata; try { var dataStore = new MessageStore(DatabaseFactory.Get()); bytFiledata = dataStore.GetTemporaryInboundMessage(MID); if (bytFiledata.Length > 0) { // Assume any partial will be a multiple of 250 real bytes as the last block of < 250 bytes // would indicate a completed file... if (bytFiledata.Length > 255) { intBytesReceived = bytFiledata.Length - (bytFiledata[1] + 2 + 2 * (bytFiledata.Length / 250)); if (intBytesReceived < 250 | intBytesReceived % 250 != 0) { // Problem with partial... _log.Error("IsPartialMessage: Computed Bytes received is not modulo 250, Partial MID: " + MID + " Purged!"); dataStore.DeleteTemporaryInboundMessage(MID); intBytesReceived = 0; } else if (intBytesReceived >= Convert.ToInt32(Length)) { _log.Error("IsPartialMessage: Partial Length exceeded proposed length, Partial MID: " + MID + " Purged!"); dataStore.DeleteTemporaryInboundMessage(MID); intBytesReceived = 0; } } else { _log.Error("IsPartialMessage: Partial Files size < 255, Partial MID: " + MID + " Purged!"); dataStore.DeleteTemporaryInboundMessage(MID); } } return(intBytesReceived); } catch (Exception e) { var dataStore = new MessageStore(DatabaseFactory.Get()); dataStore.DeleteTemporaryInboundMessage(MID); _log.Error("[IsPartialMessage] " + e.Message); return(0); } } // IsPartialMessage