Пример #1
0
        private BatchWriteItemRequest ConstructRequest(
            Dictionary <string, QuickList <WriteRequestDocument> > writeItems,
            Table targetTable,
            out Dictionary <string, Dictionary <Key, Document> > documentMap,
            bool isAsync)
        {
            documentMap = new Dictionary <string, Dictionary <Key, Document> >(StringComparer.Ordinal);
            BatchWriteItemRequest request = new BatchWriteItemRequest();

            foreach (var writeItem in writeItems)
            {
                string tableName = writeItem.Key;
                List <WriteRequestDocument> requestItems = writeItem.Value.GetItems();
                if (requestItems != null && requestItems.Count > 0)
                {
                    var table            = tableMap[tableName];
                    var requestList      = new List <WriteRequest>();
                    var tableDocumentMap = new Dictionary <Key, Document>(keyComparer);
                    documentMap.Add(tableName, tableDocumentMap);

                    foreach (var item in requestItems)
                    {
                        requestList.Add(item.WriteRequest);
                        // Add document corresponding to the Put request to document map
                        if (item.WriteRequest.PutRequest != null)
                        {
                            var key = table.MakeKey(item.Document);
                            tableDocumentMap.Add(key, item.Document);
                        }
                    }
                    request.RequestItems[tableName] = requestList;
                }
            }

            targetTable.AddRequestHandler(request, isAsync);
            return(request);
        }