public void InitPartitionFromSnapshot(PartitionSnapshot partitionSnapshot) { _readerWriterLockSlim.EnterWriteLock(); try { var partition = DbPartition.Create(partitionSnapshot.PartitionKey); if (_partitions.ContainsKey(partitionSnapshot.PartitionKey)) { return; } _partitions.Add(partition.PartitionKey, partition); var partitionAsMyMemory = new MyMemoryAsByteArray(partitionSnapshot.Snapshot); foreach (var dbRowMemory in partitionAsMyMemory.SplitJsonArrayToObjects()) { var entity = dbRowMemory.ParseDynamicEntity(); var dbRow = DbRow.RestoreSnapshot(entity, dbRowMemory); partition.InsertOrReplace(dbRow); } } finally { _readerWriterLockSlim.ExitWriteLock(); } }
public void TestSingleArray() { var str = "[{A}, {B}]"; var bytes = Encoding.UTF8.GetBytes(str); var mem = new MyMemoryAsByteArray(bytes); var result = mem.SplitJsonArrayToObjects().ToArray(); Assert.Equal("{A}", Encoding.UTF8.GetString(result[0].Span)); Assert.Equal("{B}", Encoding.UTF8.GetString(result[1].Span)); }