コード例 #1
0
    /// <summary>
    /// Moves along the build chain skipping units until it finds the matching unit.
    /// If it is the target unit, returns build actions for it, if no, pass the rest of the chain to each child and returns merged actions.
    /// </summary>
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, I need it to be captured
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(SkipTillUnit)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Pattern = {UnitPattern.ToHoconString()}, Weight = {Weight.ToHoconString()}");

                for (var i = 0; i < buildChain.Length; i++)
                {
                    var unitInfo = buildChain[i];

                    var isPatternMatches = UnitPattern.Matches(unitInfo);
                    if (isPatternMatches)
                    {
                        Log.WriteLine(LogLevel.Verbose, LogConst.Matched, true);
                        hasActions = GetOwnOrChildrenBuildActions(buildChain.GetTail(i), inputWeight, out actionBag);
                        return(hasActions);
                    }
                }

                Log.WriteLine(LogLevel.Trace, LogConst.Matched, false);
            }

        actionBag = null;
        return(false);
    }
コード例 #2
0
ファイル: UnitPatternTest.cs プロジェクト: Ed-Pavlov/Armature
        public void should_not_match_if_tag_differs([Values(null, "kind")] object kind)
        {
            var unitInfo = new UnitId(kind, "tag1");
            var target   = new UnitPattern(kind, "tag2");

            // --assert
            target.Matches(unitInfo).Should().BeFalse();
        }
コード例 #3
0
ファイル: UnitPatternTest.cs プロジェクト: Ed-Pavlov/Armature
        public void should_not_match_if_kind_differs([Values(null, "tag")] object tag)
        {
            var unitInfo = new UnitId("kind1", tag);
            var target   = new UnitPattern("kind2", tag);

            // --assert
            target.Matches(unitInfo).Should().BeFalse();
        }
コード例 #4
0
ファイル: UnitPatternTest.cs プロジェクト: Ed-Pavlov/Armature
        public void should_match_if_tag_any_provided([Values(null, "tag")] object tag)
        {
            var unitInfo = new UnitId("kind", tag);
            var target   = new UnitPattern("kind", SpecialTag.Any);

            // --assert
            target.Matches(unitInfo).Should().BeTrue();
        }
コード例 #5
0
ファイル: UnitPatternTest.cs プロジェクト: Ed-Pavlov/Armature
        public void should_match([Values(null, "kind")] string?kind, [Values(null, "tag")] string?tag)
        {
            if (kind is null && tag is null)
            {
                Assert.Ignore("Impossible arguments combination");
            }

            var unitInfo = new UnitId(kind, tag);
            var target   = new UnitPattern(kind, tag);

            // --assert
            target.Matches(unitInfo).Should().BeTrue();
        }
コード例 #6
0
ファイル: UnitPatternTest.cs プロジェクト: Ed-Pavlov/Armature
        public void should_not_be_equal_if_kinds_are_not_equal([Values(null, "kind")] object?kind, [ValueSource(nameof(all_possible_tags))] object?tag)
        {
            if (kind is null && tag is null)
            {
                Assert.Ignore("Impossible arguments combination");
            }

            var target1 = new UnitPattern(kind, tag);
            var target2 = new UnitPattern("fixed kind", tag); // fix kind value

            // --assert
            target1.Equals(target2).Should().BeFalse();
            target2.Equals(target1).Should().BeFalse();
        }
コード例 #7
0
ファイル: UnitPatternTest.cs プロジェクト: Ed-Pavlov/Armature
        public void should_not_be_equal_if_tags_are_not_equal([Values(null, "kind")] object?kind, [Values(null, "tag")] string?tag)
        {
            if (kind is null && tag is null)
            {
                Assert.Ignore("Impossible arguments combination");
            }

            var target1 = new UnitPattern(kind, tag);
            var target2 = new UnitPattern(kind, SpecialTag.Any); // fix tag value

            // --assert
            target1.Equals(target2).Should().BeFalse();
            target2.Equals(target1).Should().BeFalse();
        }
コード例 #8
0
    /// <summary>
    /// Checks if the first unit in the build chain matches the specified patter.
    /// If it is the target unit, returns build actions for it, if no, pass the rest of the build chain to each child and returns all actions from children merged
    /// </summary>
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        actionBag = null;

        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, I need it to be captured
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(IfFirstUnit)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Pattern = {UnitPattern.ToHoconString()}, Weight = {Weight.ToHoconString()}");

                var isPatternMatches = UnitPattern.Matches(buildChain[0]);
                Log.WriteLine(LogLevel.Verbose, LogConst.Matched, isPatternMatches);

                hasActions = isPatternMatches && GetOwnOrChildrenBuildActions(buildChain, inputWeight, out actionBag);
                return(hasActions);
            }
    }
コード例 #9
0
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, I need it to be captured
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(SkipWhileUnit)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Pattern = {UnitPattern.ToHoconString()}, Weight = {Weight.ToHoconString()}");

                var i = 0;
                for (; i < buildChain.Length - 1; i++) // target unit is not the subject of skipping
                {
                    if (!UnitPattern.Matches(buildChain[i]))
                    {
                        break;
                    }
                }

                hasActions = GetChildrenActions(buildChain.GetTail(i), inputWeight, out actionBag);
                return(hasActions);
            }
    }