コード例 #1
0
        /// <summary>
        /// Open a new output file.
        /// </summary>
        /// <remarks>Any existing file will be closed.</remarks>
        private void OpenFile()
        {
            //clear the existing file pointer to make sure if we fail, it's gone.
            //we also rely on this to distinguish adding a new file to an existing stream.
            CloseFile(false);

            //increment our session file counter since we're going to open a new file
            m_CurrentSessionFile++;

            //Calculate our candidate file name (with path) based on what we know.
            string fileNamePath = Path.Combine(m_RepositoryFolder, MakeFileName());

            //now double check that the candidate path is unique
            fileNamePath = FileSystemTools.MakeFileNamePathUnique(fileNamePath);

            //we now have a unique file name, create the file.
            FileSystemTools.EnsurePathExists(fileNamePath);
            m_CurrentFile = new FileStream(fileNamePath, FileMode.CreateNew, FileAccess.Write);

            //and open a serializer on it
            m_CurrentSerializer = new GLFWriter(m_CurrentFile, Publisher.SessionSummary, m_CurrentSessionFile, DateTimeOffset.Now);

            //write out every header packet to the stream
            ICachedMessengerPacket[] headerPackets = Publisher.HeaderPackets;
            if (headerPackets != null)
            {
                foreach (ICachedMessengerPacket packet in headerPackets)
                {
                    m_CurrentSerializer.Write(packet);
                }
            }

            //and set a time for us to do our next index update.
            m_FileExpiration = DateTime.Now.AddSeconds(m_MaxLogDurationSeconds);
        }
コード例 #2
0
        /// <summary>
        /// Inheritors must override this method to implement their custom message writing functionality.
        /// </summary>
        /// <remarks>Code in this method is protected by a Queue Lock
        /// This method is called with the Message Dispatch thread exclusively.</remarks>
        protected override void OnWrite(IMessengerPacket packet, bool writeThrough, ref MaintenanceModeRequest maintenanceRequested)
        {
            //Do we have a serializer opened?
            if (m_CurrentSerializer == null)
            {
                //we do not.  we need to open a file.
                OpenFile();
            }

            //now write to the file
            m_CurrentSerializer.Write(packet);

            if (writeThrough)
            {
                OnFlush();
            }

            //and do we need to request maintenance?
            if (m_CurrentFile.Length > m_MaxFileSizeBytes)
            {
                maintenanceRequested = MaintenanceModeRequest.Regular;
            }
            else if (DateTime.Now > m_FileExpiration)
            {
                maintenanceRequested = MaintenanceModeRequest.Regular;
            }
        }