Inheritance: System.IO.BinaryWriter
		public TransactionalStorage(string path)
		{
			if (Directory.Exists(path) == false)
				Directory.CreateDirectory(path);

			storageFile = Path.Combine(path, "storage.raven");
			writer = new FileStream(storageFile,
									FileMode.OpenOrCreate,
									FileAccess.ReadWrite,
									FileShare.Delete | FileShare.Read,
									16 * 1024,
									FileOptions.WriteThrough | FileOptions.SequentialScan);
			try
			{
				binaryWriter = new BinaryWriterWith7BitEncoding(writer);
				isNewDatabase = writer.Length == 0;
				if (isNewDatabase)
					CreateFromScratch();
				TryReadingExistingFile();
			}
			catch (Exception)
			{
				Dispose();
				throw;
			}
		}
Beispiel #2
0
        public Tree(Stream reader, Stream writer, StartMode mode)
        {
            this.reader  = reader;
            this.writer  = writer;
            binaryReader = new BinaryReaderWith7BitEncoding(this.reader);
            binaryWriter = new BinaryWriterWith7BitEncoding(this.writer);

            root = mode == StartMode.Create
                                ? new TreeNode(null, null, null, null, ReadNode, WriteNodeLazy)
                                : ReadNode(new StreamPosition(reader.Position, null));
        }
Beispiel #3
0
		public Tree(Stream reader, Stream writer, StartMode mode)
		{
			this.reader = reader;
			this.writer = writer;
			binaryReader = new BinaryReaderWith7BitEncoding(this.reader);
			binaryWriter = new BinaryWriterWith7BitEncoding(this.writer);

			root = mode == StartMode.Create
				? new TreeNode(null, null, null, null, ReadNode, WriteNodeLazy)
				: ReadNode(new StreamPosition(reader.Position, null));
		}
		public void CanEncodeUsing7BitInt64()
		{
			var buffer = new byte[1024];

			for (long i = 0; i < 64*1024; i++)
			{
				var bw = new BinaryWriterWith7BitEncoding(new MemoryStream(buffer));
				bw.Write7BitEncodedInt64(i);
				var br = new BinaryReaderWith7BitEncoding(new MemoryStream(buffer));
				Assert.Equal(i, br.Read7BitEncodedInt64());
			}
		}
Beispiel #5
0
        public Bag(Stream reader, Stream writer, StartMode mode)
        {
            this.reader = reader;
            this.writer = writer;

            binaryReader = new BinaryReaderWith7BitEncoding(reader);
            binaryWriter = new BinaryWriterWith7BitEncoding(writer);

            if (mode != StartMode.Open)
            {
                return;
            }
            current = ReadItem(reader.Position);
        }
Beispiel #6
0
        public Queue(Stream reader, Stream writer, StartMode mode)
        {
            this.reader = reader;
            this.writer = writer;

            binaryReader = new BinaryReaderWith7BitEncoding(reader);
            binaryWriter = new BinaryWriterWith7BitEncoding(writer);

            if (mode == StartMode.Open)
            {
                currentId = binaryReader.Read7BitEncodedInt64();
                var treePos = binaryReader.Read7BitEncodedInt64();
                reader.Position = treePos;
            }
            tree = new Tree(reader, writer, mode);
        }
Beispiel #7
0
		public Queue(Stream reader, Stream writer, StartMode mode)
		{
			this.reader = reader;
			this.writer = writer;

			binaryReader = new BinaryReaderWith7BitEncoding(reader);
			binaryWriter = new BinaryWriterWith7BitEncoding(writer);

			if(mode == StartMode.Open)
			{
				currentId = binaryReader.Read7BitEncodedInt64();
				var treePos = binaryReader.Read7BitEncodedInt64();
				reader.Position = treePos;
			}
			tree = new Tree(reader, writer, mode);
		}