Exemplo n.º 1
0
        public DbPartition InitPartitionFromSnapshot(IMyMemory data)
        {
            DbPartition partition = null;

            ReaderWriterLockSlim.EnterWriteLock();
            try
            {
                var initData = new ReadOnlyMemory <byte>(data.AsArray());
                foreach (var dbRowMemory in new[] { initData }.SplitJsonArrayToObjects())
                {
                    var jsonFields = dbRowMemory.ParseFirstLevelOfJson();

                    var entityInfo = jsonFields.GetEntityInfo();

                    if (!_partitions.ContainsKey(entityInfo.PartitionKey))
                    {
                        partition = DbPartition.Create(entityInfo.PartitionKey);
                        _partitions.Add(entityInfo.PartitionKey, partition);
                    }

                    if (partition == null)
                    {
                        partition = _partitions[entityInfo.PartitionKey];
                    }

                    var dbRow = DbRow.RestoreSnapshot(entityInfo, dbRowMemory);

                    partition.InsertOrReplace(dbRow);
                }
            }
            finally
            {
                ReaderWriterLockSlim.ExitWriteLock();
            }

            return(partition);
        }
Exemplo n.º 2
0
 public static DbRow RestoreSnapshot(IMyNoSqlDbEntity techData, IMyMemory data)
 {
     return(new DbRow(techData.PartitionKey, techData.RowKey, techData.TimeStamp, techData.Expires, data.AsArray()));
 }