internal async Task <List <TEntity> > BatchGetItemAsync <TEntity>(BuilderNode node, CancellationToken cancellationToken = default) where TEntity : class { using var httpContent = new BatchGetItemHighLevelHttpContent(this, node); using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false); var result = await ReadAsync <BatchGetItemEntityResponse <TEntity> >(response, cancellationToken).ConfigureAwait(false); List <TEntity>?items = null; if (result.Responses?.Count > 0) { foreach (var values in result.Responses.Values) { if (items == null) { items = values; } else { items.AddRange(values); } } } var attempt = 0; while (result.UnprocessedKeys?.Count > 0) { if (!Config.RetryStrategies.ProvisionedThroughputExceededStrategy.TryGetRetryDelay(attempt++, out var delay)) { throw new DdbException($"Maximum number of {attempt} attempts exceeded while executing batch read item request."); } await Task.Delay(delay, cancellationToken).ConfigureAwait(false); using var unprocessedHttpContent = new BatchGetItemHttpContent(new BatchGetItemRequest { RequestItems = result.UnprocessedKeys }, null); using var unprocessedResponse = await Api.SendAsync(Config, unprocessedHttpContent, cancellationToken).ConfigureAwait(false); result = await ReadAsync <BatchGetItemEntityResponse <TEntity> >(unprocessedResponse, cancellationToken).ConfigureAwait(false); if (result.Responses?.Count > 0) { foreach (var values in result.Responses.Values) { if (items == null) { items = values; } else { items.AddRange(values); } } } } return(items ?? new List <TEntity>()); }
public ExecutionNode BuildNode() { if (!OptionSet) { throw new InvalidOperationException(); } ExecutionNode node; if (ActivityType != null) { throw new NotImplementedException("Projection in the graph of a reference type not supported"); } else if (ProxyActivity != null) { node = new ComponentNode(ProxyActivity); } else if (ActivityBranchBuilder != null) { node = ActivityBranchBuilder.BuildNode(); } else { node = new BuilderNode(Name, Decision != null, false, false, Metadata); } return(node); }
private static int CompareNodes( BuilderNode x, BuilderNode y, ImmutableArray <BuilderNode> nodeList) { var comp = s_totalComparer(x.Name, y.Name); if (comp == 0) { if (x.ParentIndex != y.ParentIndex) { if (x.IsRoot) { return(-1); } else if (y.IsRoot) { return(1); } else { return(CompareNodes(nodeList[x.ParentIndex], nodeList[y.ParentIndex], nodeList)); } } } return(comp); }
private void AddUnsortedNodes(ArrayBuilder <BuilderNode> unsortedNodes, MultiDictionary <string, ExtensionMethodInfo> receiverTypeNameToMethodMap, MetadataNode parentNode, int parentIndex, string fullyQualifiedContainerName) { foreach (var child in _parentToChildren[parentNode]) { var childNode = new BuilderNode(child.Name, parentIndex, _extensionMethodToParameterTypeInfo[child]); var childIndex = unsortedNodes.Count; unsortedNodes.Add(childNode); if (fullyQualifiedContainerName != null) { foreach (var parameterTypeInfo in _extensionMethodToParameterTypeInfo[child]) { // We do not differentiate array of different kinds for simplicity. // e.g. int[], int[][], int[,], etc. are all represented as int[] in the index. // similar for complex receiver types, "[]" means it's an array type, "" otherwise. var parameterTypeName = (parameterTypeInfo.IsComplexType, parameterTypeInfo.IsArray) switch { (true, true) => Extensions.ComplexArrayReceiverTypeName, // complex array type, e.g. "T[,]" (true, false) => Extensions.ComplexReceiverTypeName, // complex non-array type, e.g. "T" (false, true) => parameterTypeInfo.Name + Extensions.ArrayReceiverTypeNameSuffix, // simple array type, e.g. "int[][,]" (false, false) => parameterTypeInfo.Name // simple non-array type, e.g. "int" }; receiverTypeNameToMethodMap.Add(parameterTypeName, new ExtensionMethodInfo(fullyQualifiedContainerName, child.Name)); } } AddUnsortedNodes(unsortedNodes, receiverTypeNameToMethodMap, child, childIndex, Concat(fullyQualifiedContainerName, child.Name)); }
private void AddUnsortedNodes(ArrayBuilder <BuilderNode> unsortedNodes, MultiDictionary <string, ExtensionMethodInfo> simpleBuilder, ArrayBuilder <ExtensionMethodInfo> complexBuilder, MetadataNode parentNode, int parentIndex, string fullyQualifiedContainerName) { foreach (var child in _parentToChildren[parentNode]) { var childNode = new BuilderNode(child.Name, parentIndex, _extensionMethodToParameterTypeInfo[child]); var childIndex = unsortedNodes.Count; unsortedNodes.Add(childNode); if (fullyQualifiedContainerName != null) { foreach (var parameterTypeInfo in _extensionMethodToParameterTypeInfo[child]) { if (parameterTypeInfo.IsComplexType) { complexBuilder.Add(new ExtensionMethodInfo(fullyQualifiedContainerName, child.Name)); } else { simpleBuilder.Add(parameterTypeInfo.Name, new ExtensionMethodInfo(fullyQualifiedContainerName, child.Name)); } } } AddUnsortedNodes(unsortedNodes, simpleBuilder, complexBuilder, child, childIndex, Concat(fullyQualifiedContainerName, child.Name)); }
internal async Task BatchWriteItemAsync(BuilderNode node, CancellationToken cancellationToken = default) { using var httpContent = new BatchWriteItemHighLevelHttpContent(this, node, Config.TableNamePrefix); using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false); var documentResult = await DynamoDbLowLevelContext.ReadDocumentAsync(response, BatchWriteItemParsingOptions.Instance, cancellationToken).ConfigureAwait(false); var attempt = 0; while (documentResult != null) { var unprocessedItems = BatchWriteItemResponseParser.ParseFailedItems(documentResult); if (unprocessedItems == null || unprocessedItems.Count == 0) { break; } if (!Config.RetryStrategies.ProvisionedThroughputExceededStrategy.TryGetRetryDelay(attempt++, out var delay)) { throw new DdbException($"Maximum number of {attempt} attempts exceeded while executing batch write item request."); } await Task.Delay(delay, cancellationToken).ConfigureAwait(false); using var unprocessedHttpContent = new BatchWriteItemHttpContent(new BatchWriteItemRequest { RequestItems = unprocessedItems }, null); using var unprocessedResponse = await Api.SendAsync(Config, unprocessedHttpContent, cancellationToken).ConfigureAwait(false); documentResult = await DynamoDbLowLevelContext.ReadDocumentAsync(unprocessedResponse, BatchWriteItemParsingOptions.Instance, cancellationToken).ConfigureAwait(false); } }
internal async Task TransactWriteItemsAsync(BuilderNode node, CancellationToken cancellationToken = default) { using var httpContent = new TransactWriteItemsHighLevelHttpContent(this, node); using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false); await ReadAsync <object>(response, cancellationToken).ConfigureAwait(false); }
private void Add(TextSpan characterSpan, int insertionIndex) { if (insertionIndex == 0) { _builderNodes[insertionIndex] = new BuilderNode(characterSpan); return; } var currentNodeIndex = 0; while (true) { var currentNode = _builderNodes[currentNodeIndex]; // Determine the edit distance between these two words. Note: we do not use // a threshold here as we need the actual edit distance so we can actually // determine what edge to make or walk. var editDistance = EditDistance.GetEditDistance( _concatenatedLowerCaseWords.AsSpan( currentNode.CharacterSpan.Start, currentNode.CharacterSpan.Length ), _concatenatedLowerCaseWords.AsSpan( characterSpan.Start, characterSpan.Length ) ); if (editDistance == 0) { // This should never happen. We dedupe all items before proceeding to the 'Add' step. // So the edit distance should always be non-zero. throw new InvalidOperationException(); } if ( TryGetChildIndex( currentNode, currentNodeIndex, editDistance, out var childNodeIndex ) ) { // Edit distances collide. Move to this child and add this word to it. currentNodeIndex = childNodeIndex; continue; } // found the node we want to add the child node to. AddChildNode( characterSpan, insertionIndex, currentNode.EdgeCount, currentNodeIndex, editDistance ); return; } }
protected void AddBranch(Behavior e) { var newNode = new BuilderNode(e); newNode.Parent = currentNode; currentNode.Children.Add(newNode); if (currentNode.behavior is Filter fil) { fil.AddAction(e); } else if (currentNode.behavior is Decorator dec) { dec.SetChild(e); } else if (currentNode.behavior is Composite com) { com.AddChild(e); } else { throw new BadBuilderUseException($"Cannot add branch to node of type {currentNode.behavior.GetType()}."); } currentNode = newNode; result.AddBehavior(e); }
private void AddChildNode( TextSpan characterSpan, int insertionIndex, int currentNodeEdgeCount, int currentNodeIndex, int editDistance) { // The node as 'currentNodeIndex' doesn't have an edge with this edit distance. // Three cases to handle: // 1) there are less than 4 edges. We simply place the edge into the correct // location in compactEdges // 2) there are 4 edges. We need to make the spillover dictionary and then add // the new edge into that. // 3) there are more than 4 edges. Just put the new edge in the spillover // dictionary. if (currentNodeEdgeCount < CompactEdgeAllocationSize) { _compactEdges[currentNodeIndex * CompactEdgeAllocationSize + currentNodeEdgeCount] = new Edge(editDistance, insertionIndex); } else { // When we hit 4 elements, we need to allocate the spillover dictionary to // place the extra edges. if (currentNodeEdgeCount == CompactEdgeAllocationSize) { Debug.Assert(_builderNodes[currentNodeIndex].SpilloverEdges == null); var spilloverEdges = new Dictionary <int, int>(); _builderNodes[currentNodeIndex].SpilloverEdges = spilloverEdges; } _builderNodes[currentNodeIndex].SpilloverEdges.Add(editDistance, insertionIndex); } _builderNodes[currentNodeIndex].EdgeCount++; _builderNodes[insertionIndex] = new BuilderNode(characterSpan); return; }
private bool TryGetChildIndex(BuilderNode currentNode, int currentNodeIndex, int editDistance, out int childIndex) { // linearly scan the children we have to see if there is one with this edit distance. var start = currentNodeIndex * CompactEdgeAllocationSize; var end = start + Math.Min(currentNode.EdgeCount, CompactEdgeAllocationSize); for (var i = start; i < end; i++) { if (_compactEdges[i].EditDistance == editDistance) { childIndex = _compactEdges[i].ChildNodeIndex; return(true); } } // If we've spilled over any edges, check there as well if (currentNode.SpilloverEdges != null) { // Can't use the compact array. Have to use the spillover dictionary instead. Debug.Assert(currentNode.SpilloverEdges.Count == (currentNode.EdgeCount - CompactEdgeAllocationSize)); return(currentNode.SpilloverEdges.TryGetValue(editDistance, out childIndex)); } childIndex = -1; return(false); }
// generate nodes for symbols that share the same name, and all their descendants private static void GenerateSourceNodes( string name, int parentIndex, MultiDictionary <string, ISymbol> .ValueSet symbolsWithSameName, ArrayBuilder <BuilderNode> list, Action <ISymbol, MultiDictionary <string, ISymbol> > lookup) { var node = new BuilderNode(name, parentIndex); var nodeIndex = list.Count; list.Add(node); var symbolMap = AllocateSymbolMap(); try { // Add all child members foreach (var symbol in symbolsWithSameName) { lookup(symbol, symbolMap); } foreach (var kvp in symbolMap) { GenerateSourceNodes(kvp.Key, nodeIndex, kvp.Value, list, lookup); } } finally { FreeSymbolMap(symbolMap); } }
public CustomBlockBuilder(string blockName) { _node = new BuilderNode <TModel> { Name = blockName }; _nodes = new List <INodeBuilder <TModel> >(); }
public MapBlockBuilder() { _node = new BuilderNode <TModel> { Name = "map" }; _nodes = new List <INodeBuilder <TModel> >(); }
public AcronymBlockBuilder() { _node = new BuilderNode <TModel> { Name = "acronym" }; _nodes = new List <INodeBuilder <TModel> >(); }
public CaptionBlockBuilder() { _node = new BuilderNode <TModel> { Name = "caption" }; _nodes = new List <INodeBuilder <TModel> >(); }
public ParamBlockBuilder() { _node = new BuilderNode <TModel> { Name = "param" }; _nodes = new List <INodeBuilder <TModel> >(); }
public NavigationBlockBuilder() { _node = new BuilderNode <TModel> { Name = "nav" }; _nodes = new List <INodeBuilder <TModel> >(); }
public PlainTextBlockBuilder() { _node = new BuilderNode <TModel> { Name = "plaintext" }; _nodes = new List <INodeBuilder <TModel> >(); }
public UnorderedListBlockBuilder() { _node = new BuilderNode <TModel> { Name = "ul" }; _nodes = new List <INodeBuilder <TModel> >(); }
public ButtonBlockBuilder() { _node = new BuilderNode <TModel> { Name = "button" }; _nodes = new List <INodeBuilder <TModel> >(); }
public StrikeTextBlockBuilder() { _node = new BuilderNode <TModel> { Name = "s" }; _nodes = new List <INodeBuilder <TModel> >(); }
public LinkBlockBuilder() { _node = new BuilderNode<TModel> { Name = "a" }; _nodes = new List<INodeBuilder<TModel>>(); }
public HorizontalLineBlockBuilder() { _node = new BuilderNode <TModel> { Name = "hr" }; _nodes = new List <INodeBuilder <TModel> >(); }
public CiteTextBlockBuilder() { _node = new BuilderNode <TModel> { Name = "cite" }; _nodes = new List <INodeBuilder <TModel> >(); }
public CanvasBlockBuilder() { _node = new BuilderNode <TModel> { Name = "canvas" }; _nodes = new List <INodeBuilder <TModel> >(); }
public VariableTextBlockBuilder() { _node = new BuilderNode <TModel> { Name = "var" }; _nodes = new List <INodeBuilder <TModel> >(); }
public SummaryBlockBuilder() { _node = new BuilderNode <TModel> { Name = "summary" }; _nodes = new List <INodeBuilder <TModel> >(); }
public H1TextBlockBuilder() { _node = new BuilderNode <TModel> { Name = "h1" }; _nodes = new List <INodeBuilder <TModel> >(); }
public SmallTextBlockBuilder() { _node = new BuilderNode <TModel> { Name = "small" }; _nodes = new List <INodeBuilder <TModel> >(); }
private void AddUnsortedNodes( ArrayBuilder<BuilderNode> unsortedNodes, MetadataNode parentNode, int parentIndex) { foreach (var child in _parentToChildren[parentNode]) { var childNode = new BuilderNode(child.Name, parentIndex); var childIndex = unsortedNodes.Count; unsortedNodes.Add(childNode); AddUnsortedNodes(unsortedNodes, child, childIndex); } }
private void Add(TextSpan characterSpan, int insertionIndex) { if (insertionIndex == 0) { _builderNodes[insertionIndex] = new BuilderNode(characterSpan); return; } var currentNodeIndex = 0; while (true) { var currentNode = _builderNodes[currentNodeIndex]; // Determine the edit distance between these two words. Note: we do not use // a threshold here as we need the actual edit distance so we can actually // determine what edge to make or walk. var editDistance = EditDistance.GetEditDistance( new ArraySlice<char>(_concatenatedLowerCaseWords, currentNode.CharacterSpan), new ArraySlice<char>(_concatenatedLowerCaseWords, characterSpan)); if (editDistance == 0) { // This should never happen. We dedupe all items before proceeding to the 'Add' step. // So the edit distance should always be non-zero. throw new InvalidOperationException(); } int childNodeIndex; if (TryGetChildIndex(currentNode, currentNodeIndex, editDistance, out childNodeIndex)) { // Edit distances collide. Move to this child and add this word to it. currentNodeIndex = childNodeIndex; continue; } // found the node we want to add the child node to. AddChildNode(characterSpan, insertionIndex, currentNode.EdgeCount, currentNodeIndex, editDistance); return; } }
private void AddChildNode( TextSpan characterSpan, int insertionIndex, int currentNodeEdgeCount, int currentNodeIndex, int editDistance) { // The node as 'currentNodeIndex' doesn't have an edge with this edit distance. // Three cases to handle: // 1) there are less than 4 edges. We simply place the edge into the correct // location in compactEdges // 2) there are 4 edges. We need to make the spillover dictionary and then add // the new edge into that. // 3) there are more than 4 edges. Just put the new edge in the spillover // dictionary. if (currentNodeEdgeCount < CompactEdgeAllocationSize) { _compactEdges[currentNodeIndex * CompactEdgeAllocationSize + currentNodeEdgeCount] = new Edge(editDistance, insertionIndex); } else { // When we hit 4 elements, we need to allocate the spillover dictionary to // place the extra edges. if (currentNodeEdgeCount == CompactEdgeAllocationSize) { Debug.Assert(_builderNodes[currentNodeIndex].SpilloverEdges == null); var spilloverEdges = new Dictionary<int, int>(); _builderNodes[currentNodeIndex].SpilloverEdges = spilloverEdges; } _builderNodes[currentNodeIndex].SpilloverEdges.Add(editDistance, insertionIndex); } _builderNodes[currentNodeIndex].EdgeCount++; _builderNodes[insertionIndex] = new BuilderNode(characterSpan); return; }
// generate nodes for symbols that share the same name, and all their descendants private static void GenerateSourceNodes( string name, int parentIndex, MultiDictionary<string, ISymbol>.ValueSet symbolsWithSameName, ArrayBuilder<BuilderNode> list, Action<ISymbol, MultiDictionary<string, ISymbol>> lookup) { var node = new BuilderNode(name, parentIndex); var nodeIndex = list.Count; list.Add(node); var symbolMap = AllocateSymbolMap(); try { // Add all child members foreach (var symbol in symbolsWithSameName) { lookup(symbol, symbolMap); } foreach (var kvp in symbolMap) { GenerateSourceNodes(kvp.Key, nodeIndex, kvp.Value, list, lookup); } } finally { FreeSymbolMap(symbolMap); } }
private bool TryGetChildIndex(BuilderNode currentNode, int currentNodeIndex, int editDistance, out int childIndex) { // linearly scan the children we have to see if there is one with this edit distance. var start = currentNodeIndex * CompactEdgeAllocationSize; var end = start + Math.Min(currentNode.EdgeCount, CompactEdgeAllocationSize); for (var i = start; i < end; i++) { if (_compactEdges[i].EditDistance == editDistance) { childIndex = _compactEdges[i].ChildNodeIndex; return true; } } // If we've spilled over any edges, check there as well if (currentNode.SpilloverEdges != null) { // Can't use the compact array. Have to use the spillover dictionary instead. Debug.Assert(currentNode.SpilloverEdges.Count == (currentNode.EdgeCount - CompactEdgeAllocationSize)); return currentNode.SpilloverEdges.TryGetValue(editDistance, out childIndex); } childIndex = -1; return false; }
private static int CompareNodes( BuilderNode x, BuilderNode y, ImmutableArray<BuilderNode> nodeList) { var comp = s_totalComparer(x.Name, y.Name); if (comp == 0) { if (x.ParentIndex != y.ParentIndex) { if (x.IsRoot) { return -1; } else if (y.IsRoot) { return 1; } else { return CompareNodes(nodeList[x.ParentIndex], nodeList[y.ParentIndex], nodeList); } } } return comp; }