Пример #1
0
        /// <summary>
        /// The AddMessage method adds an instance of a FIX message
        /// to the database file that is associated with the specified
        /// session. The index file is updated to reflect the position
        /// in the database of the message that is being added.
        /// </summary>
        /// <param name="sessionId">
        /// The session id of the session the message relates to.
        /// </param>
        /// <param name="msg">
        /// The FIX message to be added to the database.
        /// </param>
        public void AddMessage(string sessionId, FixMessage msg)
        {
            // REC: Create the details instance for the task:
            TaskDetails_Add taskDetails = new TaskDetails_Add(sessionId, msg);

            // REC: Enqueue the task for asynchronous execution:
            _sequencer.Enqueue(AddMessage_Entrypoint, taskDetails);
        }
Пример #2
0
        /// <summary>
        /// The AddMessage_Entrypoint method is the asynchronous
        /// entrypoint for processing add message requests that have
        /// been enqueued to the .NET thread pool through the instance
        /// of the sequencer that is associated with the database.
        /// </summary>
        /// <param name="state">
        /// The instance of TaskDetails_Add that is associated with
        /// the asynchronous add message request being processed.
        /// </param>
        private void AddMessage_Entrypoint(object state)
        {
            TaskDetails_Add taskDetails = state as TaskDetails_Add;

            if (taskDetails != null)
            {
                FixField fldSequence = taskDetails.SessionMsg.Header.GetField(34);
                if (fldSequence != null)
                {
                    // REC: Retrieve the message's text so that its
                    // length can be assigned to its index entry:
                    string msgText = taskDetails.SessionMsg.ToString();

                    // REC: Create an entry for the message in the
                    // index file associated with the session:
                    if (_mapSessions.ContainsKey(taskDetails.SessionId))
                    {
                        SessionDetails details = _mapSessions[taskDetails.SessionId];

                        IndexEntry idxEntry = new IndexEntry();
                        idxEntry.msgOffset   = details.MsgWriter.BaseStream.Position;
                        idxEntry.msgLength   = msgText.Length;
                        idxEntry.msgSequence = int.Parse(fldSequence.Content);

                        details.Index.Add(idxEntry);

                        details.MsgWriter.Write(msgText.ToCharArray());
                        details.MsgWriter.Flush();

                        string idxLine = string.Format("{0}:{1}:{2}", idxEntry.msgSequence, idxEntry.msgOffset, idxEntry.msgLength);
                        details.IdxWriter.WriteLine(idxLine.ToCharArray());
                        details.IdxWriter.Flush();
                    }
                }
            }
        }