Amazon.DynamoDBv2.DocumentModel.Table.MakeKey C# (CSharp) Метод

MakeKey() приватный Метод

private MakeKey ( DynamoDBEntry>.IDictionary doc ) : Key
doc DynamoDBEntry>.IDictionary
Результат Key
        internal Key MakeKey(IDictionary<string, DynamoDBEntry> doc)
        {
            Key key = new Key();
            foreach (var kvp in Keys)
            {
                string keyName = kvp.Key;
                KeyDescription description = kvp.Value;
                DynamoDBEntry value;
                if (!doc.TryGetValue(keyName, out value))
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Document does not contain value for key {0}", keyName));
                value = value.ToConvertedEntry(Conversion);

                Primitive primitive = value.AsPrimitive();
                if (primitive == null)
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Key attribute {0} must be a Primitive type", keyName));
                if (primitive.Type != description.Type)
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Key attribute {0} must be of type {1}", keyName, description.Type));

                key[keyName] = primitive.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(Conversion));
            }
            return key;
        }

Same methods

Table::MakeKey ( Primitive hashKey, Primitive rangeKey ) : Key

Usage Example

Пример #1
0
        private async Task CallUntilCompletionAsync(BatchWriteItemRequest request, Dictionary <string, Dictionary <Key, Document> > documentMap, IAmazonDynamoDB client, CancellationToken cancellationToken)
#endif
        {
            do
            {
                var result = await client.BatchWriteItemAsync(request, cancellationToken).ConfigureAwait(false);

                request.RequestItems = result.UnprocessedItems;

                Dictionary <Key, Document> unprocessedDocuments = new Dictionary <Key, Document>(keyComparer);
                foreach (var unprocessedItems in result.UnprocessedItems)
                {
                    string tableName = unprocessedItems.Key;
                    Table  table     = tableMap[tableName];
                    Dictionary <Key, Document> tableDocumentMap = documentMap[tableName];

                    foreach (var writeRequest in unprocessedItems.Value)
                    {
                        if (writeRequest.PutRequest != null)
                        {
                            var doc = table.FromAttributeMap(writeRequest.PutRequest.Item);
                            var key = table.MakeKey(doc);

                            Document document = null;
                            if (tableDocumentMap.TryGetValue(key, out document))
                            {
                                // Remove unprocessed requests from the document map
                                // and copy them to unprocessed documents.
                                unprocessedDocuments.Add(key, document);
                                tableDocumentMap.Remove(key);
                            }
                        }
                    }

                    // Commit the remaining documents in the document map
                    foreach (var document in tableDocumentMap.Values)
                    {
                        document.CommitChanges();
                    }
                    // Replace existing documents with just the unprocessed documents
                    documentMap[tableName] = unprocessedDocuments;
                }
            } while (request.RequestItems.Count > 0);

            // Commit any remaining documents in document map.
            // This would only happen if we are not able to match the items sent in the request
            // with the items returned back as unprocessed items.
            foreach (var tableDocumentMap in documentMap.Values)
            {
                foreach (var document in tableDocumentMap.Values)
                {
                    document.CommitChanges();
                }
            }
        }
All Usage Examples Of Amazon.DynamoDBv2.DocumentModel.Table::MakeKey