/// <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); }