コード例 #1
0
        //--- Methods ---
        public IDynamoTableTransactWriteItemsConditionCheck <TRecord> BeginConditionCheck <TRecord>(DynamoPrimaryKey <TRecord> primaryKey) where TRecord : class
        {
            var transactWriteItem = new TransactWriteItem {
                ConditionCheck = new ConditionCheck {
                    TableName = _table.TableName,
                    Key       = new Dictionary <string, AttributeValue> {
                        [primaryKey.PKName] = new AttributeValue(primaryKey.PKValue),
                        [primaryKey.SKName] = new AttributeValue(primaryKey.SKValue)
                    }
                }
            };

            _request.TransactItems.Add(transactWriteItem);
            var converter = new DynamoRequestConverter(transactWriteItem.ConditionCheck.ExpressionAttributeNames, transactWriteItem.ConditionCheck.ExpressionAttributeValues, _table.SerializerOptions);

            return(new DynamoTableTransactWriteItemsConditionCheck <TRecord>(this, transactWriteItem.ConditionCheck, converter));
        }
コード例 #2
0
        private TransactWriteItem GetInsertOrderFlow(Order order)
        {
            var item = new Dictionary <string, AttributeValue>
            {
                { "ContractId", new AttributeValue()
                  {
                      S = order.ContractId
                  } },
                { "InstrumentId", new AttributeValue()
                  {
                      N = order.InstrumentId.ToString()
                  } },
                { "InstrumentName", new AttributeValue()
                  {
                      S = order.InstrumentName
                  } },
                { "Quantity", new AttributeValue()
                  {
                      N = order.Quantity.ToString()
                  } },
                { "Price", new AttributeValue()
                  {
                      N = order.Price.ToString()
                  } },
                { "Side", new AttributeValue()
                  {
                      S = order.Side
                  } },
                { "Status", new AttributeValue()
                  {
                      S = order.Status
                  } }
            };

            var writeItem = new TransactWriteItem()
            {
                Put = new Put()
                {
                    TableName = "OrderFlow",
                    Item      = item
                }
            };

            return(writeItem);
        }
コード例 #3
0
        public void Execute(AmazonDynamoDBRequest dynamoRequest)
        {
            var item = new TransactWriteItem();

            if (dynamoRequest is UpdateItemRequest)
            {
                item.Update = ((UpdateItemRequest)dynamoRequest).Convert();
            }
            if (dynamoRequest is PutItemRequest)
            {
                item.Put = ((PutItemRequest)dynamoRequest).Convert();
            }
            if (dynamoRequest is DeleteItemRequest)
            {
                item.Delete = ((DeleteItemRequest)dynamoRequest).Convert();
            }

            _transactionItems.Add(item);
        }
コード例 #4
0
        TransactWriteItem CreateDeleteTransactWriteItem <T>(T item)
        {
            var tableName  = GetDynamoDBTableName <T>();
            var properties = typeof(T).GetProperties();
            var deleteItem = new Dictionary <string, AttributeValue>();

            var partitionKeyProperty = properties.FirstOrDefault(p => p.CustomAttributes.Any(a => a.AttributeType == typeof(DynamoDBHashKeyAttribute)));

            if (partitionKeyProperty == null)
            {
                throw new Exception();
            }
            var pkPropertyName   = GetDynamoDBPropertyName(partitionKeyProperty);
            var pkAttributeValue = CreateAttributeValue(partitionKeyProperty, item);

            deleteItem.Add(pkPropertyName, pkAttributeValue);

            var sortKeyProperty = properties.FirstOrDefault(p => p.CustomAttributes.Any(a => a.AttributeType == typeof(DynamoDBRangeKeyAttribute)));

            if (sortKeyProperty != null)
            {
                var skPropertyName   = GetDynamoDBPropertyName(sortKeyProperty);
                var skAttributeValue = CreateAttributeValue(sortKeyProperty, item);
                deleteItem.Add(skPropertyName, skAttributeValue);
            }

            var transactItem = new TransactWriteItem
            {
                Delete = new Delete
                {
                    TableName = tableName,
                    Key       = deleteItem
                }
            };

            return(transactItem);
        }