/// <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); }
/// <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); } }
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); } }