Beispiel #1
0
        public Task <TResult> ExecuteUpdateAsync <TEntity, TResult>(MemberInfo memberInfo,
                                                                    IAzureStorageTableEntity <TEntity> updatedEntity,
                                                                    IAzureStorageTableEntity <TEntity> existingEntity,
                                                                    AzureTableDriverDynamic repository,
                                                                    Func <Func <Task>, TResult> onSuccessWithRollback,
                                                                    Func <TResult> onFailure)
        {
            var rowKey            = updatedEntity.RowKey;
            var valueUpdated      = updatedEntity.Entity;
            var dictionaryUpdated = updatedEntity.WriteEntity(null);
            var to                 = (IModifyAzureStorageTablePartitionKey)Activator.CreateInstance(this.To);
            var toPartitionKey     = to.GeneratePartitionKey(rowKey, valueUpdated, memberInfo);
            var typeWrapper        = new TypeWrapper(rowKey, toPartitionKey, dictionaryUpdated);
            var dictionaryExisting = existingEntity.WriteEntity(null);

            return(repository.InsertOrReplaceAsync <TEntity, TResult>(typeWrapper,
                                                                      (created, newEntity) => onSuccessWithRollback(
                                                                          () =>
            {
                if (created)
                {
                    return repository.DeleteAsync <TEntity, bool>(newEntity,
                                                                  () => true,
                                                                  () => true,
                                                                  () => false,
                                                                  (codes, why) => false);
                }
                var typeWrapperExisting = new TypeWrapper(rowKey, toPartitionKey, dictionaryExisting);
                return repository.ReplaceAsync <TEntity, bool>(typeWrapperExisting,
                                                               () => true);
            })));
        }
Beispiel #2
0
        public Task <TResult> ExecuteUpdateAsync <TEntity, TResult>(MemberInfo memberInfo,
                                                                    string rowKey, string partitionKey,
                                                                    TEntity valueExisting, IDictionary <string, EntityProperty> dictionaryExisting,
                                                                    TEntity valueUpdated, IDictionary <string, EntityProperty> dictionaryUpdated,
                                                                    AzureTableDriverDynamic repository,
                                                                    Func <Func <Task>, TResult> onSuccessWithRollback,
                                                                    Func <TResult> onFailure)
        {
            var to             = (IModifyAzureStorageTablePartitionKey)Activator.CreateInstance(this.To);
            var toPartitionKey = to.GeneratePartitionKey(rowKey, valueUpdated, memberInfo);
            var typeWrapper    = new TypeWrapper(rowKey, toPartitionKey, dictionaryUpdated);

            return(repository.InsertOrReplaceAsync <TEntity, TResult>(typeWrapper,
                                                                      (created, newEntity) => onSuccessWithRollback(
                                                                          () =>
            {
                if (created)
                {
                    return repository.DeleteAsync <TEntity, bool>(newEntity,
                                                                  () => true,
                                                                  () => true);
                }
                var typeWrapperExisting = new TypeWrapper(rowKey, toPartitionKey, dictionaryExisting);
                return repository.ReplaceAsync <TEntity, bool>(typeWrapperExisting,
                                                               () => true);
            })));
        }
        public async Task <TResult> ExecuteUpdateAsync <TEntity, TResult>(MemberInfo memberInfo,
                                                                          IAzureStorageTableEntity <TEntity> updatedEntity, IAzureStorageTableEntity <TEntity> existingEntity,
                                                                          AzureTableDriverDynamic repository,
                                                                          Func <Func <Task>, TResult> onSuccessWithRollback,
                                                                          Func <TResult> onFailure)
        {
            var newValue      = memberInfo.GetValue(updatedEntity.Entity);
            var existingValue = memberInfo.GetValue(updatedEntity.Entity);

            if (newValue.GetType().IsAssignableTo(typeof(System.Delegate)))
            {
                var dele     = (Delegate)newValue;
                var deleType = dele.Target.GetType();
                if (deleType.DeclaringType.GUID == typeof(StorageSubtableAttribute).GUID)
                {
                    return(onSuccessWithRollback(() => true.AsTask()));
                }
            }

            var rowKeyRef       = updatedEntity.RowKey;
            var partitionKeyRef = updatedEntity.PartitionKey;

            var memberType  = typeof(TEntity);
            var taskValue   = newValue.ExecuteFunction(out Type taskType);
            var resultValue = await taskValue.CastAsTaskObjectAsync(out Type typeToSave);

            var rawValues = Serialize(resultValue, typeToSave);

            ITableEntity subtableEntity = new SubtableEntity(rowKeyRef, partitionKeyRef, rawValues);
            var          tableName      = StorageLookupAttribute.GetMemberTableName(memberInfo);
            var          tableRef       = repository.TableClient.GetTableReference(tableName);

            return(await repository.InsertOrReplaceAsync(subtableEntity, new E5CloudTable(tableRef),
                                                         (created, tr) => onSuccessWithRollback(() => 1.AsTask())));
        }