Example #1
0
        internal bool SaveMessageToWinlink()
        {
            // Saves the image in the mime property into the "To Winlink" table...

            EncodeMime();
            if (!string.IsNullOrEmpty(Mime))
            {
                var messageStore = new MessageStore(DatabaseFactory.Get());
                messageStore.SaveToWinlinkMessage(MessageId, UTF8Encoding.UTF8.GetBytes(Mime));
                messageStore.AddMessageIdSeen(MessageId);
                LocalDelivery();
                return(true);
            }

            ErrorDescription = "Failure to encode mime format";
            return(false);
        }
Example #2
0
        private void B2MessageInbound(byte[] bytInbound) // Flag to indicate still processing, used to handle re entrancy
        {
            Globals.Proposal objProp;

            // Code modified from RMSLLite Packet Server:
            // Processes and inbound compressed binary message stream...
            if (blnInProcess) // this handles re entrancy
            {
                queInboundData.Enqueue(bytInbound);
                return;
            }
            else
            {
                bytInProcess = bytInbound;
                queInboundData.Clear();
            }

            blnInProcess = true;
            var intResult = default(int);
            int intPosition;

Reprocess:

            // Strip the header on the first block of a new parial recovery
            int intHdr2Sumcheck = objPartialSession.StripHeaderFromPartial(ref bytInProcess);

            if (intHdr2Sumcheck != 0)
            {
                objMessageInbound.intB2Checksum = intHdr2Sumcheck;
            }

            intPosition = 0;
            Globals.UpdateProgressBar(bytInbound.Length);
            foreach (byte byt in bytInProcess)
            {
                intPosition += 1;
                intResult    = objMessageInbound.BinaryInput(byt);
                objPartialSession.AccumulateByte(byt);
                if (intResult == 2)
                {
                    // All OK - Block boundary ...update partial upon block boundary (every 250 bytes)
                    objPartialSession.WritePartialToFile();
                }
                else if (intResult == 1)
                {
                    objPartialSession.PurgeCurrentPartial(); // no longer needed as message now complete
                    if (objMessageInbound.Decompress(true) == false)
                    {
                        _log.Error("B2Protocol [423] Unable to decompress Inbound Message ");
                        // objInitialProtocol._objModem.Break() ' Break for Pactor, has no affect on other channels TODO: verify placement
                        Send("[423] Protocol Error - Unable to decompress received binary compressed message...");
                        Disconnect();
                        blnInProcess = false;
                        queInboundData.Clear();
                        return;
                    }

                    if (objMessageInbound.DecodeB2Message() == false)
                    {
                        _log.Error("B2Protocol [424] Unable to decode received binary compressed message...");
                        // objInitialProtocol._objModem.Break() ' Break for Pactor, has no affect on other channels TODO: verify placement
                        Send("[424] Protocol Error - Unable to decode received binary compressed message...");
                        Disconnect();
                        blnInProcess = false;
                        queInboundData.Clear();
                        return;
                    }

                    intInboundProposalIndex += 1;
                    intInboundMessageCount  -= 1;

                    // If the message has been successfully received and saved then
                    // record the message ID as having been seen and processed...
                    if (objMessageInbound.SaveToDatabase(objMessageInbound.MessageId))
                    {
                        var messageStoreDatabase = new MessageStore(DatabaseFactory.Get());
                        messageStoreDatabase.AddMessageIdSeen(objMessageInbound.MessageId);
                    }

                    // Save statistics...
                    intCompressedMessageBytesReceived   += objMessageInbound.Progress;
                    intUncompressedMessageBytesReceived += objMessageInbound.Size();

                    // Show message complete...
                    Globals.queChannelDisplay.Enqueue("G*** " + objMessageInbound.MessageId + " - " + objMessageInbound.Size().ToString() + "/" + objMessageInbound.Progress.ToString() + " bytes received");
                    if (intInboundMessageCount == 0)
                    {
                        objMessageInbound = null;
                        StateChange(EB2States.SendingB2Proposal);
                        B2OutboundProposal();
                        blnInProcess = false; // Added Rev  2.0.22.0 to fix second inbound session
                        queInboundData.Clear();
                        return;
                    }
                    else
                    {
                        objMessageInbound = new Message();
                        break;
                    }
                }
                else if (intResult < 0)
                {
                    objPartialSession.PurgeCurrentPartial(); // If error delete current partial to avoid potential loop.
                    _log.Error("[B2MessageInbound] Protocol Error Problem receiving B2 message...nResult: " + intResult.ToString());
                    // objInitialProtocol._objModem.Break() ' Break for Pactor, has no affect on other channels TODO: verify placement
                    Send("[425/" + intResult.ToString() + "] Protocol Error - Problem receiving B2 message...");
                    Disconnect();
                    blnInProcess = false;
                    queInboundData.Clear();
                    return;
                }
            }

            if (intResult == 0 | intResult == 2)
            {
                if (queInboundData.Count == 0)
                {
                    blnInProcess = false;
                    return;
                }
                else
                {
                    try
                    {
                        bytInProcess = (byte[])queInboundData.Dequeue();
                    }
                    catch
                    {
                        blnInProcess = false;
                        return;
                    }

                    while (queInboundData.Count > 0)
                    {
                        try
                        {
                            Globals.AppendBuffer(ref bytInProcess, (byte[])queInboundData.Dequeue());
                        }
                        catch
                        {
                            return;
                        }
                    }

                    goto Reprocess;
                }
            }
            // There may be all or part of the next message in the bytInProcess() array...
            else if (intPosition < bytInProcess.Length)
            {
                var binMore = new byte[(bytInProcess.Length - intPosition)];
                for (int intCount = 0, loopTo = binMore.Length - 1; intCount <= loopTo; intCount++)
                {
                    binMore[intCount] = bytInProcess[intPosition];
                    intPosition      += 1;
                }

                objProp = cllInboundMessageIDs[intInboundProposalIndex];
                string strMID = objProp.msgID;
                // Dim strTemp() As String = CStr(cllAcceptedInboundMids(intInboundProposalIndex)).Split(Chr(32))
                var bytReceived = objPartialSession.RetrievePartial(strMID);
                if (true) // If bytReceived.Length = 0 Then ' TODO: This temporarily bypasses partial file recovery
                {
                    objPartialSession.StartNewPartial(strMID);
                    bytInProcess = binMore;
                    while (queInboundData.Count > 0)
                    {
                        try
                        {
                            Globals.AppendBuffer(ref bytInProcess, (byte[])queInboundData.Dequeue());
                        }
                        catch
                        {
                            break;
                        }
                    }

                    goto Reprocess;
                }
                else // Here is where partial recovery is and there is still a latent bug here TODO:
                {
                    bytInProcess = bytReceived;
                    objPartialSession.StartNewPartial(strMID);

                    // Set this so the first header info is stripped from the first received Block...
                    objPartialSession.blnFirstRcvdBlk = true;
                    // ' Set this so the extra 8 byte header is also stripped (may not be in first block!)
                    objPartialSession.blnRemoveHdr8 = true;
                    objPartialSession.StripHeaderFromPartial(ref binMore); // TODO: not sure what to do with sumcheck?
                    objPartialSession.blnFirstRcvdBlk = false;
                    objPartialSession.blnRemoveHdr8   = false;
                    Globals.AppendBuffer(ref bytInProcess, binMore);
                    while (queInboundData.Count > 0)
                    {
                        try
                        {
                            Globals.AppendBuffer(ref bytInProcess, (byte[])queInboundData.Dequeue());
                        }
                        catch
                        {
                            break;
                        }
                    }

                    objPartialSession.StartNewPartial(strMID);
                    goto Reprocess;
                }
            }

            blnInProcess = false;
        } // B2MessageInbound