public static void Run()
        {
            var directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SingeStorage");
            if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);

            var storagePath = Path.Combine(directory, "MyEntity.dat");
            if (File.Exists(storagePath)) File.Delete(storagePath);

            using (var store = new DualBinaryStore(new FileSystemStreamProvider(storagePath), 0, 5 * 1024 * 1024))
            {
                var converter = new ProtocolBufferBinaryConverter<MyEntity>();
                var storage = new StorageFragment(store);

                var content = converter.Convert(new MyEntity { Id = 1, Message = "Hello World", Value = 42.5, Category = new Category { Id = 1, Name = "First scenario" } });
                var added = storage.TryAdd(new Int32Key(1), content);

                Console.WriteLine("Value was {0} added", added ? "successfully" : "unsuccessfully");

                if (storage.TryGet(new Int32Key(1), out content))
                {
                    var entity = converter.Convert(content);
                    Console.WriteLine("Retrieve success, valdiation {0}", entity.IsValid() ? "successful" : "unsuccessful");
                }
                else
                {
                    Console.WriteLine("Error, could not get the content");
                }
            }
        }
        public void ReadWriteTest()
        {
            var leftTestData = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
            var rightTestData = new byte[] {1, 3, 3, 7};

            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data.dat");
            if (File.Exists(path)) File.Delete(path);

            long leftOffset;
            long rightOffset;
            using (var store = new DualBinaryStore(new FileSystemStreamProvider(path), 0, 1024 * 1024))
            {
                Assert.IsTrue(store.Left.TryWrite(leftTestData, out leftOffset));
                Assert.IsTrue(store.Right.TryWrite(rightTestData, out rightOffset));

                var leftData = store.ReadLeft(leftOffset, leftTestData.Length);
                Assert.IsTrue(leftTestData.SequenceEqual(leftData));

                var rightData = store.ReadRight(rightOffset, rightTestData.Length);
                Assert.IsTrue(rightTestData.SequenceEqual(rightData));
            }

            using (var store = new DualBinaryStore(new FileSystemStreamProvider(path), 0, 1024 * 1024))
            {
                var leftData = store.ReadLeft(leftOffset, leftTestData.Length);
                Assert.IsTrue(leftTestData.SequenceEqual(leftData));

                var rightData = store.ReadRight(rightOffset, rightTestData.Length);
                Assert.IsTrue(rightTestData.SequenceEqual(rightData));
            }
        }
 public IStorageFragment CreateFragment()
 {
     var fileInfo = new FileInfo(_path);
     var start = fileInfo.Exists ? fileInfo.Length : 0;
     var store = new DualBinaryStore(new FileSystemStreamProvider(_path), start, _configuration.FragmentSize.Value);
     return new StorageFragment(store);
 }
        public IEnumerable<IStorageFragment> GetFragments()
        {
            var fragments = new List<IStorageFragment>();

            var fileInfo = new FileInfo(_path);
            if (!fileInfo.Exists) return fragments;

            var fragmentCount = fileInfo.Length / _configuration.FragmentSize.Value;

            for (var i = 0; i < fragmentCount; i++)
            {
                var start = i * _configuration.FragmentSize.Value;
                var store = new DualBinaryStore(new FileSystemStreamProvider(_path), start, _configuration.FragmentSize.Value);
                fragments.Add(new StorageFragment(store));
            }
            return fragments;
        }
 public IStorageFragment CreateFragment()
 {
     var streamProvider = new MemoryStreamProvider((int)_configuration.FragmentSize.Value);
     var binaryStore = new DualBinaryStore(streamProvider, 0, _configuration.FragmentSize.Value);
     return new StorageFragment(binaryStore);
 }