コード例 #1
0
        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>());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
            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));
                }
コード例 #5
0
            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));
                }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: BKTree.Builder.cs プロジェクト: belav/roslyn
            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;
                }
            }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: BKTree.Builder.cs プロジェクト: wyb10a10/roslyn
            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;
            }
コード例 #11
0
ファイル: BKTree.Builder.cs プロジェクト: wyb10a10/roslyn
            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);
            }
コード例 #12
0
        // 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);
            }
        }
コード例 #13
0
 public CustomBlockBuilder(string blockName)
 {
     _node = new BuilderNode <TModel>
     {
         Name = blockName
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #14
0
 public MapBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "map"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #15
0
 public AcronymBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "acronym"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #16
0
 public CaptionBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "caption"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #17
0
 public ParamBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "param"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #18
0
 public NavigationBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "nav"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #19
0
 public PlainTextBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "plaintext"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #20
0
 public UnorderedListBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "ul"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #21
0
 public ButtonBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "button"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #22
0
 public StrikeTextBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "s"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #23
0
 public LinkBlockBuilder()
 {
     _node = new BuilderNode<TModel>
     {
         Name = "a"
     };
     _nodes = new List<INodeBuilder<TModel>>();
 }
コード例 #24
0
 public HorizontalLineBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "hr"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #25
0
 public CiteTextBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "cite"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #26
0
 public CanvasBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "canvas"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #27
0
 public VariableTextBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "var"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #28
0
 public SummaryBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "summary"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #29
0
 public H1TextBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "h1"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #30
0
 public SmallTextBlockBuilder()
 {
     _node = new BuilderNode <TModel>
     {
         Name = "small"
     };
     _nodes = new List <INodeBuilder <TModel> >();
 }
コード例 #31
0
            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);
                }
            }
コード例 #32
0
ファイル: BKTree.Builder.cs プロジェクト: jkotas/roslyn
            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;
                }
            }
コード例 #33
0
ファイル: BKTree.Builder.cs プロジェクト: jkotas/roslyn
            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;
            }
コード例 #34
0
        // 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);
            }
        }
コード例 #35
0
ファイル: BKTree.Builder.cs プロジェクト: jkotas/roslyn
            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;
            }
コード例 #36
0
ファイル: SymbolTreeInfo.cs プロジェクト: natidea/roslyn
        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;
        }