示例#1
0
        public bool Verify(Node node, MetadataVerificationRequest request)
        {
            var toCheckAncestry  = new HashSet <Node>();
            var toCheckRelations = new HashSet <Node>();

            var visited      = new HashSet <Node>();
            var currentBatch = new HashSet <Node>();

            currentBatch.Add(node);

            while (currentBatch.Count > 0 || toCheckRelations.Count > 0 || toCheckAncestry.Count > 0)
            {
                foreach (var n in currentBatch)
                {
                    visited.Add(n);
                    toCheckRelations.Add(n);
                    toCheckAncestry.Add(n);

                    var result = request.ResultEvaluator(n);
                    if (result.HasValue)
                    {
                        return(result.Value);
                    }
                }

                currentBatch.Clear();

                if (request.SearchMode == SearchMode.AncestryFirst)
                {
                    this.ExtractAncestry(toCheckAncestry, currentBatch, visited, request.AncestryNeighborSelector, request.AncestrySearchDirection);
                    toCheckAncestry.Clear();
                    if (currentBatch.Count == 0)
                    {
                        this.ExtractRelations(toCheckRelations, currentBatch, visited, request.RelationsToCheck, request.RelationSelector);
                        toCheckRelations.Clear();
                    }
                }
                else
                {
                    this.ExtractRelations(toCheckRelations, currentBatch, visited, request.RelationsToCheck, request.RelationSelector);
                    toCheckRelations.Clear();
                    if (currentBatch.Count == 0)
                    {
                        this.ExtractAncestry(toCheckAncestry, currentBatch, visited, request.AncestryNeighborSelector, request.AncestrySearchDirection);
                        toCheckAncestry.Clear();
                    }
                }
            }

            return(false);
        }
示例#2
0
        public bool NodeIsGeneratedBy(NodePath path, ActivityFrame activityFrame, out NodeRecord recordMatch)
        {
            NodeRecord resultRecord = null;
            var        node         = this.metadataIndexed.GetExactNode(path, true);

            if (node != null)
            {
                MetadataVerificationRequest request = new MetadataVerificationRequest(
                    SearchMode.RelationsFirst,
                    AncestrySearchDirection.ToParent,
                    (n) =>
                {
                    foreach (var record in n.Records.Where(r => r.Change == ChangeKind.Created))
                    {
                        if ((activityFrame.PluginId == null || activityFrame.PluginId == record.PluginId) &&
                            (activityFrame.StageName == null || activityFrame.StageName == record.StageName) &&
                            (activityFrame.BatchIndex == null || activityFrame.BatchIndex == record.BatchIndex) &&
                            (activityFrame.TagSelector?.TagKeys == null ||
                             (activityFrame.TagSelector.Condition == SearchCondition.And && activityFrame.TagSelector.TagKeys.All(k => record.Tags != null && record.Tags.ContainsKey(k))) ||
                             (activityFrame.TagSelector.Condition == SearchCondition.Or && activityFrame.TagSelector.TagKeys.Any(k => record.Tags != null && record.Tags.ContainsKey(k)))))
                        {
                            resultRecord = record;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    return(null);
                },
                    (r, n) => (r.ParentRecord == null || activityFrame.BatchIndex == null || r.ParentRecord.BatchIndex <= activityFrame.BatchIndex) && r.Node1 == n,
                    null,
                    new HashSet <RelationKind>()
                {
                    RelationKind.SourcingFrom
                }
                    );

                var result = this.Verify(node, request);
                recordMatch = resultRecord;
                return(result);
            }

            recordMatch = resultRecord;
            return(false);
        }