Exemplo n.º 1
0
        private static TreeProgramItem FindBrokenStructure(TreeProgramItem item, TreeProgramItem parent)
        {
            var brokenParents = item.Parents.GroupBy(p => p.FullWeight).Where(g => g.Count() == 1);

            if (!brokenParents.Any())
            {
                return(parent);
            }
            return(FindBrokenStructure(brokenParents.First().First(), item));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return a tuple with the values
        /// CurrentWeight
        /// NewWeight
        /// Broken Program name
        /// </summary>
        /// <param name="broken"></param>
        /// <returns></returns>
        private static Tuple <int, int, string> CalculateNewWeightForBrokenStructure(TreeProgramItem broken)
        {
            var groupedParentWeights = broken.Parents.GroupBy(p => p.FullWeight);
            var invalidProgram       = groupedParentWeights.Where(g => g.Count() == 1).First().First();
            var invalidWeight        = invalidProgram.FullWeight;
            var correctWeight        = groupedParentWeights.Where(g => g.Count() > 1).First().First().FullWeight;

            var differ = correctWeight - invalidWeight;

            return(Tuple.Create <int, int, string>(invalidProgram.Item.Weight, (invalidProgram.Item.Weight + differ), invalidProgram.Item.Name));
        }