Exemplo n.º 1
0
        public void Load(FileStream stream)
        {
            using (var reader = new PrimitiveReader(stream, false))
            {
                foreach (var provider in providers)
                {
                    var tempFile = TemporaryFilesManager.Instance.GetTemporaryFile();
                    if (ConfigurationManager.Instance.Get("file-system", "use-cow", false))
                    {
                        FileCopier.Copy(stream.Name, tempFile, true);

                        var size          = reader.ReadInt64();
                        var localPosition = stream.Position;
                        reader.ReadBytes((int)size);
                        provider.BlobIsReady(tempFile, localPosition, size);
                    }
                    else
                    {
                        var size = reader.ReadInt64();
                        using (var fileStream = new FileStream(tempFile, FileMode.OpenOrCreate))
                        {
                            reader.CopyTo(fileStream, size);
                        }
                        provider.BlobIsReady(tempFile, 0, size);
                    }
                }
            }
        }
        public void Load(PrimitiveReader reader)
        {
            var fileName = TemporaryFilesManager.Instance.GetTemporaryFile();

            underlyingStream       = new FileStream(fileName, FileMode.OpenOrCreate);
            underlyingStreamOffset = 0;

            length      = reader.ReadInt64();
            PaddingByte = reader.ReadByte();
            var numberOfBytes = reader.ReadInt64();

            reader.CopyTo(underlyingStream, numberOfBytes);
            Position = reader.ReadInt64();
        }
Exemplo n.º 3
0
        public void Load(PrimitiveReader reader)
        {
            // checking magic
            var magic = reader.ReadUInt32();

            if (magic != Magic)
            {
                throw new InvalidOperationException("Memory: Cannot resume state from stream: Invalid magic.");
            }
            SegmentSize = reader.ReadInt32();
            size        = reader.ReadInt64();
            if (emptyCtorUsed)
            {
                Init();
            }
            var realSegmentsCount = 0;

            for (var i = 0; i < segments.Length; i++)
            {
                var isTouched = reader.ReadBoolean();
                if (!isTouched)
                {
                    continue;
                }
                var compressedSegmentSize = reader.ReadInt32();
                var compressedBuffer      = reader.ReadBytes(compressedSegmentSize);
                TouchSegment(i);
                realSegmentsCount++;
                var decodedBuffer = LZ4Codec.Decode(compressedBuffer, 0, compressedBuffer.Length, SegmentSize);
                Marshal.Copy(decodedBuffer, 0, segments[i], decodedBuffer.Length);
            }
            this.NoisyLog(string.Format("{0} segments loaded from stream, of which {1} had content.", segments.Length, realSegmentsCount));
        }
Exemplo n.º 4
0
        public void ShouldWriteAndReadLongs(
            [Values(1, 10, 100, 10000, 1000 * 1000)]
            int numberOfLongs)
        {
            var randomLongs = Helpers.GetRandomLongs(numberOfLongs);
            var stream      = new MemoryStream();

            using (var writer = new PrimitiveWriter(stream))
            {
                for (var i = 0; i < randomLongs.Length; i++)
                {
                    writer.Write(randomLongs[i]);
                }
            }
            var position = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);

            using (var reader = new PrimitiveReader(stream))
            {
                for (var i = 0; i < randomLongs.Length; i++)
                {
                    var read = reader.ReadInt64();
                    Assert.AreEqual(randomLongs[i], read);
                }
            }
            Assert.AreEqual(position, stream.Position, StreamCorruptedMessage);
        }
Exemplo n.º 5
0
        public async ValueTask Read(PrimitiveReader primitiveReader, CancellationToken cancellationToken)
        {
            BoolValue = await primitiveReader.ReadBool(cancellationToken);

            ByteValue = await primitiveReader.ReadByte(cancellationToken);

            SByteValue = await primitiveReader.ReadSByte(cancellationToken);

            ShortValue = await primitiveReader.ReadInt16(cancellationToken);

            UShortValue = await primitiveReader.ReadUInt16(cancellationToken);

            IntValue = await primitiveReader.ReadInt32(cancellationToken);

            UIntValue = await primitiveReader.ReadUInt32(cancellationToken);

            LongValue = await primitiveReader.ReadInt64(cancellationToken);

            ULongValue = await primitiveReader.ReadUInt64(cancellationToken);

            FloatValue = await primitiveReader.ReadSingle(cancellationToken);

            DoubleValue = await primitiveReader.ReadDouble(cancellationToken);

            StringValue = await primitiveReader.ReadString(cancellationToken);

            deserializationCounter++;
        }
Exemplo n.º 6
0
        public void ShouldReadAndWriteLimits()
        {
            var stream = new MemoryStream();

            using (var writer = new PrimitiveWriter(stream))
            {
                writer.Write(byte.MinValue);
                writer.Write(byte.MaxValue);
                writer.Write(sbyte.MinValue);
                writer.Write(sbyte.MaxValue);
                writer.Write(short.MinValue);
                writer.Write(short.MaxValue);
                writer.Write(ushort.MinValue);
                writer.Write(ushort.MaxValue);
                writer.Write(int.MinValue);
                writer.Write(int.MaxValue);
                writer.Write(uint.MinValue);
                writer.Write(uint.MaxValue);
                writer.Write(long.MinValue);
                writer.Write(long.MaxValue);
                writer.Write(ulong.MinValue);
                writer.Write(ulong.MaxValue);
            }
            var position = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);
            using (var reader = new PrimitiveReader(stream))
            {
                Assert.AreEqual(byte.MinValue, reader.ReadByte());
                Assert.AreEqual(byte.MaxValue, reader.ReadByte());
                Assert.AreEqual(sbyte.MinValue, reader.ReadSByte());
                Assert.AreEqual(sbyte.MaxValue, reader.ReadSByte());
                Assert.AreEqual(short.MinValue, reader.ReadInt16());
                Assert.AreEqual(short.MaxValue, reader.ReadInt16());
                Assert.AreEqual(ushort.MinValue, reader.ReadUInt16());
                Assert.AreEqual(ushort.MaxValue, reader.ReadUInt16());
                Assert.AreEqual(int.MinValue, reader.ReadInt32());
                Assert.AreEqual(int.MaxValue, reader.ReadInt32());
                Assert.AreEqual(uint.MinValue, reader.ReadUInt32());
                Assert.AreEqual(uint.MaxValue, reader.ReadUInt32());
                Assert.AreEqual(long.MinValue, reader.ReadInt64());
                Assert.AreEqual(long.MaxValue, reader.ReadInt64());
                Assert.AreEqual(ulong.MinValue, reader.ReadUInt64());
                Assert.AreEqual(ulong.MaxValue, reader.ReadUInt64());
            }
            Assert.AreEqual(position, stream.Position, StreamCorruptedMessage);
        }
Exemplo n.º 7
0
        public void Load(PrimitiveReader reader)
        {
            Id = reader.ReadUInt64();
            Message = reader.ReadString();
            SourceId = reader.ReadInt32();
            ThreadId = reader.ReadInt32();
            Time = new DateTime(reader.ReadInt64());
            numericLogLevel = reader.ReadInt32();

            if(ThreadId == -1)
            {
                ThreadId = null;
            }
        }
 public void ShouldReadAndWriteLimits()
 {
     var stream = new MemoryStream();
     using(var writer = new PrimitiveWriter(stream))
     {
         writer.Write(byte.MinValue);
         writer.Write(byte.MaxValue);
         writer.Write(sbyte.MinValue);
         writer.Write(sbyte.MaxValue);
         writer.Write(short.MinValue);
         writer.Write(short.MaxValue);
         writer.Write(ushort.MinValue);
         writer.Write(ushort.MaxValue);
         writer.Write(int.MinValue);
         writer.Write(int.MaxValue);
         writer.Write(uint.MinValue);
         writer.Write(uint.MaxValue);
         writer.Write(long.MinValue);
         writer.Write(long.MaxValue);
         writer.Write(ulong.MinValue);
         writer.Write(ulong.MaxValue);
     }
     var position = stream.Position;
     stream.Seek(0, SeekOrigin.Begin);
     using(var reader = new PrimitiveReader(stream))
     {
         Assert.AreEqual(byte.MinValue, reader.ReadByte());
         Assert.AreEqual(byte.MaxValue, reader.ReadByte());
         Assert.AreEqual(sbyte.MinValue, reader.ReadSByte());
         Assert.AreEqual(sbyte.MaxValue, reader.ReadSByte());
         Assert.AreEqual(short.MinValue, reader.ReadInt16());
         Assert.AreEqual(short.MaxValue, reader.ReadInt16());
         Assert.AreEqual(ushort.MinValue, reader.ReadUInt16());
         Assert.AreEqual(ushort.MaxValue, reader.ReadUInt16());
         Assert.AreEqual(int.MinValue, reader.ReadInt32());
         Assert.AreEqual(int.MaxValue, reader.ReadInt32());
         Assert.AreEqual(uint.MinValue, reader.ReadUInt32());
         Assert.AreEqual(uint.MaxValue, reader.ReadUInt32());
         Assert.AreEqual(long.MinValue, reader.ReadInt64());
         Assert.AreEqual(long.MaxValue, reader.ReadInt64());
         Assert.AreEqual(ulong.MinValue, reader.ReadUInt64());
         Assert.AreEqual(ulong.MaxValue, reader.ReadUInt64());
     }
     Assert.AreEqual(position, stream.Position, StreamCorruptedMessage);
 }
        public void ShouldWriteAndReadLongs(
			[Values(1, 10, 100, 10000, 1000*1000)]
			int numberOfLongs)
        {
            var randomLongs = Helpers.GetRandomLongs(numberOfLongs);
            var stream = new MemoryStream();
            using(var writer = new PrimitiveWriter(stream))
            {
                for(var i = 0; i < randomLongs.Length; i++)
                {
                    writer.Write(randomLongs[i]);
                }
            }
            var position = stream.Position;
            stream.Seek(0, SeekOrigin.Begin);

            using(var reader = new PrimitiveReader(stream))
            {
                for(var i = 0; i < randomLongs.Length; i++)
                {
                    var read = reader.ReadInt64();
                    Assert.AreEqual(randomLongs[i], read);
                }
            }
            Assert.AreEqual(position, stream.Position, StreamCorruptedMessage);
        }