Example #1
0
        /// <summary>
        /// Writes a message file.
        /// </summary>
        /// <param name="path">The file path.</param>
        /// <param name="msg">The message.</param>
        /// <param name="msgInfo">The message metadata.</param>
        internal void WriteMessage(string path, QueuedMsg msg, QueuedMsgInfo msgInfo)
        {
            byte[] md5Hash;

            using (var fsMsg = new EnhancedFileStream(path, FileMode.Create, FileAccess.ReadWrite))
            {
                // Write the file header

                fsMsg.WriteInt32(MsgMagic);         // Magic Number
                fsMsg.WriteInt32(0);                // Format Version
                fsMsg.WriteInt32(0);                // Reserved
                fsMsg.WriteBytesNoLen(md5Zeros);    // MD5 hash placeholder

                // Write the message body.

                fsMsg.WriteBytes32(msg.BodyRaw);

                // Write the metadata.

                fsMsg.WriteString16(msgInfo.ToString());

                // Compute and save the MD5 hash

                fsMsg.Position = MsgHeaderSize;
                md5Hash        = MD5Hasher.Compute(fsMsg, fsMsg.Length - fsMsg.Position);
                fsMsg.Position = MsgMD5Offset;
                fsMsg.WriteBytesNoLen(md5Hash);
            }
        }
Example #2
0
        /// <summary>
        /// Adds a message to the backing store and updates the <see cref="QueuedMsgInfo.PersistID" />
        /// and <see cref="QueuedMsgInfo.ProviderData" /> fields in the <see cref="QueuedMsgInfo" />
        /// instance passed.
        /// </summary>
        /// <param name="msgInfo">The message metadata.</param>
        /// <param name="msg">The message.</param>
        public void Add(QueuedMsgInfo msgInfo, QueuedMsg msg)
        {
            using (TimedLock.Lock(this))
            {
                if (messages == null)
                {
                    throw new ObjectDisposedException(this.GetType().Name);
                }

                msgInfo.PersistID    = msg.ID;
                msgInfo.ProviderData = msg;
                messages[msg.ID]     = msgInfo;
            }
        }
Example #3
0
 /// <summary>
 /// Initializes the record with information from a <see cref="QueuedMsg" />
 /// and sets default values for all remaining fields.
 /// </summary>
 /// <param name="persistID">
 /// The <see cref="IMsgQueueStore" /> specific ID used to identify and
 /// locate the message.
 /// </param>
 /// <param name="msg">The message</param>
 public QueuedMsgInfo(object persistID, QueuedMsg msg)
 {
     this.PersistID        = persistID;
     this.ID               = msg.ID;
     this.SessionID        = msg.SessionID;
     this.TargetEP         = msg.TargetEP;
     this.ResponseEP       = msg.ResponseEP;
     this.Priority         = msg.Priority;
     this.Flags            = msg.Flags;
     this.SendTime         = msg.SendTime;
     this.ExpireTime       = msg.ExpireTime;
     this.DeliveryTime     = DateTime.MinValue;
     this.BodySize         = msg.BodyRaw.Length;
     this.DeliveryAttempts = 0;
     this.LockID           = Guid.Empty;
     this.ProviderData     = null;
 }
Example #4
0
        /// <summary>
        /// Adds a message to the backing store and updates the <see cref="QueuedMsgInfo.PersistID" />
        /// and <see cref="QueuedMsgInfo.ProviderData" /> fields in the <see cref="QueuedMsgInfo" />
        /// instance passed.
        /// </summary>
        /// <param name="msgInfo">The message metadata.</param>
        /// <param name="msg">The message.</param>
        public void Add(QueuedMsgInfo msgInfo, QueuedMsg msg)
        {
            using (TimedLock.Lock(this))
            {
                if (messages == null)
                {
                    throw new ObjectDisposedException(this.GetType().Name);
                }

                string msgPath;

                msgPath = GetMessagePath(msgInfo.ID, true);
                WriteMessage(msgPath, msg, msgInfo);

                msgInfo.PersistID    = msg.ID;
                msgInfo.ProviderData = msgPath;
                messages[msg.ID]     = msgInfo;
            }
        }