Inheritance: IListWriter, IDisposable
 private static void OnNewfileCreated(ExpendableListWriter expendableListWriter, Stream stream)
 {
     bool isNewFile = stream.Position == 0;
     if (isNewFile)
     {
         stream.Write(ID.ToByteArray(), 0, ID.ToByteArray().Length);
         var logDataSign = expendableListWriter.GetListWriterSignature();
         stream.Write(logDataSign, 0, logDataSign.Length);
     }
 }
        public ContinuesBinaryFileLogger(IStreamProvider streamProvider, ISubmitLogEntryFactory submitLogEntryFactory, IBufferAllocatorFactory bufferAllocatorFactory)
        {
            m_listWriter = new ExpendableListWriter(streamProvider, OnNewfileCreated);
            m_logEntry = submitLogEntryFactory.CreateSubmitLogEntry(m_listWriter);
            var stringCache = submitLogEntryFactory.CreateSubmitLogEntry(m_listWriter);
            var definition = submitLogEntryFactory.CreateSubmitLogEntry(m_listWriter);

            m_binaryLogSerilizer = new BinaryLogSerilizer(new BinaryLogSerilizer.BufferAndSubmiterTuple(m_logEntry, bufferAllocatorFactory.CreateBufferAllocator()),
                                            new BinaryLogSerilizer.BufferAndSubmiterTuple(stringCache, bufferAllocatorFactory.CreateBufferAllocator()),
                                            new BinaryLogSerilizer.BufferAndSubmiterTuple(definition, bufferAllocatorFactory.CreateBufferAllocator()));
        }
Exemplo n.º 3
0
        public void TestContinuesExpendableList()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                ms.SetLength(1024);
                ms.Position = 1024;
                ExpendableListWriter fixSizeWriter = new ExpendableListWriter(new InMemoryStreamProvider(ms),(writer, stream) => {});
                fixSizeWriter.WriteData(new CloneRawData(BitConverter.GetBytes(1)));
                fixSizeWriter.WriteData(new CloneRawData(BitConverter.GetBytes(2)));
                fixSizeWriter.WriteData(new CloneRawData(BitConverter.GetBytes(3)));

                ms.Position = 1024;
                ExpendableListReader readerSizeWriter = new ExpendableListReader(ms);
                Assert.AreEqual(1, BitConverter.ToInt32(readerSizeWriter.Read(), 0));
                Assert.AreEqual(2, BitConverter.ToInt32(readerSizeWriter.Read(), 0));
                Assert.AreEqual(3, BitConverter.ToInt32(readerSizeWriter.Read(), 0));
                Assert.IsNull(readerSizeWriter.Read());
            }
        }