Пример #1
0
        /// <summary>
        ///   Matches any <see cref="UnitInfo" />, so it pass the building unit info into its children and returns merged result
        /// </summary>
        public override MatchedBuildActions GetBuildActions(ArrayTail <UnitInfo> buildingUnitsSequence, int inputWeight)
        {
            var unitsToSkip = buildingUnitsSequence.Length;
            // decrease matching weight depending on how many unit in the sequence were skipped by this matcher
            var matchingWeight = inputWeight + Weight * unitsToSkip;

            var lastItemAsTail = buildingUnitsSequence.GetTail(buildingUnitsSequence.Length - 1);
            var ownActions     = GetOwnActions(matchingWeight);
            MatchedBuildActions childrenActions;

            if (ownActions == null)
            {
                Log.WriteLine(LogLevel.Verbose, this.ToString, unitsToSkip); // pass group method, do not call ToString
                using (Log.AddIndent())
                    childrenActions = GetChildrenActions(matchingWeight, lastItemAsTail);
            }
            else
            {
                using (Log.Block(LogLevel.Verbose, this.ToString, unitsToSkip)) // pass group method, do not call ToString
                {
                    // ReSharper disable once RedundantArgumentDefaultValue
                    ownActions.ToLog(LogLevel.Verbose);
                    childrenActions = GetChildrenActions(matchingWeight, lastItemAsTail);
                }
            }

            return(childrenActions.Merge(ownActions));
        }
Пример #2
0
        /// <summary>
        ///   Returns build actions which should be performed to build a unit represented by the last item of <paramref name="buildingUnitsSequence" />
        /// </summary>
        /// <param name="buildingUnitsSequence">
        ///   The sequence of units representing a build session, the last one is the unit to be built,
        ///   the previous are the context of the build session. Each next unit info is the dependency of the previous one.
        /// </param>
        /// <param name="inputWeight">
        ///   The weight of matching which used by children matchers to calculate a final weight of matching
        ///   Not applicable to BuildPlansCollection in common case
        /// </param>
        /// <remarks>
        ///   If there is type A which depends on class B, during building A, B should be built and build sequence will be
        ///   [A, B] in this case.
        /// </remarks>
        /// <returns>
        ///   Returns all matched build actions for the <paramref name="buildingUnitsSequence" />. All actions are grouped by a building stage
        ///   and coupled with a "weight of matching". See <see cref="MatchedBuildActions" /> type declaration for details.
        /// </returns>
        public MatchedBuildActions GetBuildActions(ArrayTail <UnitInfo> buildingUnitsSequence, int inputWeight = 0)
        {
            if (buildingUnitsSequence.Length == 0)
            {
                throw new ArgumentException(nameof(buildingUnitsSequence));
            }

            return(_root.GetBuildActions(buildingUnitsSequence, 0));
        }
Пример #3
0
 public override MatchedBuildActions GetBuildActions(ArrayTail <UnitInfo> buildingUnitsSequence, int inputWeight) =>
 GetChildrenActions(inputWeight, buildingUnitsSequence);