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 ConvertTest() { var target = new ProtocolBufferBinaryConverter<Car>(); var car = RandomCars.AK9777; var bytes = target.Convert(car); Assert.IsNotNull(bytes); Assert.IsTrue(bytes.Length > 0); }