Example #1
0
        public int GetHoldingWeight(string root)
        {
            ProgramModel rootProgram = _programList.Where(p => p.Name == root).FirstOrDefault();

            rootProgram.HoldingWeight = CalculateHoldingWeight(rootProgram);
            return(rootProgram.HoldingWeight);
        }
Example #2
0
        private int CalculateHoldingWeight(ProgramModel rootProgram)
        {
            if (rootProgram.ImmediatelyAbove.Count() > 0)
            {
                foreach (var program in rootProgram.ImmediatelyAbove)
                {
                    rootProgram.HoldingWeight += CalculateHoldingWeight(_programList.FirstOrDefault(p => p.Name == program));
                }
            }

            return(rootProgram.Weight + rootProgram.HoldingWeight);
        }
Example #3
0
        public List <ProgramModel> ReadFile(string fileName)
        {
            List <ProgramModel> programList = new List <ProgramModel>();

            foreach (var line in File.ReadAllLines(fileName))
            {
                string[] programInfo = line
                                       .Replace("(", "")
                                       .Replace(")", "")
                                       .Replace(",", "")
                                       .Split(null);
                if (programInfo.Count() > 2)
                {
                    ProgramModel program = new ProgramModel();
                    program.Name   = programInfo[0];
                    program.Weight = int.Parse(programInfo[1]);
                    for (int i = 3; i < programInfo.Count(); i++)
                    {
                        program.ImmediatelyAbove.Add(programInfo[i]);
                    }

                    programList.Add(program);
                }
                else
                {
                    ProgramModel program = new ProgramModel();
                    program.Name   = programInfo[0];
                    program.Weight = int.Parse(programInfo[1]);
                    programList.Add(program);
                }
            }

            foreach (var program in programList)
            {
                if (programList.Where(p => p.ImmediatelyAbove.Contains(program.Name)).FirstOrDefault() != null)
                {
                    program.ImmediatelyBelow = programList.Where(p => p.ImmediatelyAbove.Contains(program.Name)).FirstOrDefault().Name;
                }
            }

            return(programList);
        }