Exemplo n.º 1
0
        public async ValueTask <OperationResult> InsertAsync(DbTable table, IMyMemory myMemory,
                                                             DataSynchronizationPeriod synchronizationPeriod, DateTime now)
        {
            var entity = myMemory.ParseDynamicEntity();


            if (string.IsNullOrEmpty(entity.PartitionKey))
            {
                return(OperationResult.PartitionKeyIsNull);
            }

            if (string.IsNullOrEmpty(entity.RowKey))
            {
                return(OperationResult.RowKeyIsNull);
            }

            if (table.HasRecord(entity))
            {
                return(OperationResult.RecordExists);
            }

            var(result, dbPartition, dbRow) = table.Insert(entity, now);

            if (result != OperationResult.Ok)
            {
                return(result);
            }

            _dataSynchronizer.SynchronizeUpdate(table, new[] { dbRow });

            await _persistenceHandler.SynchronizePartitionAsync(table, dbPartition.PartitionKey, synchronizationPeriod);

            return(OperationResult.Ok);
        }
Exemplo n.º 2
0
        public async ValueTask <OperationResult> MergeAsync(DbTable table, IMyMemory myMemory,
                                                            DataSynchronizationPeriod synchronizationPeriod, DateTime now)
        {
            var entity = myMemory.ParseDynamicEntity();

            var(result, partition, dbRow) = table.Merge(entity, now);

            if (result != OperationResult.Ok)
            {
                return(result);
            }

            _dataSynchronizer.SynchronizeUpdate(table, new[] { dbRow });

            await _persistenceHandler.SynchronizePartitionAsync(table, partition.PartitionKey, synchronizationPeriod);

            return(OperationResult.Ok);
        }
Exemplo n.º 3
0
        public static DbRow ToDbRow(this IMyMemory myMemory)
        {
            var entity = myMemory.ParseDynamicEntity();

            return(DbRow.CreateNew(entity, DateTime.UtcNow));
        }