Exemple #1
0
 public Grade(Grade grade)
 {
     this.Name = grade.Name;
     this.MinimalExperiences = new LPExperiences(grade.MinimalExperiences);
     this.MaxExperiencesGainPerRound = new LPExperiences(grade.MaxExperiencesGainPerRound);
     this.SalaryPerRound = grade.SalaryPerRound;
     this.Level = grade.Level;
 }
        private void LoadGrads()
        {
            string filePath = DefaultValuesFilePath;
            if (File.Exists(filePath) == false)
                throw new FileNotFoundException(string.Format("Le fichier de données\r\n{0}'\r\nest introuvable!", filePath));

            IniFileReader iniFile = new IniFileReader();

            try
            {
                iniFile.Load(filePath);
            }
            catch (Exception exp)
            {
                throw new Exception(string.Format("Erreur lors du chargement du fichier de configuration\r\n{0}", filePath), exp);
            }

            if (iniFile.Sections.ContainsKey(this.name) == false)
                throw new Exception(string.Format("Il manque la section '{0}' dans le fichier de configuration\r\n{0}", this.name, filePath));

            IniSection section = iniFile.Sections[this.name];
            List<Grade> tmpGrades = new List<Grade>();

            foreach (string keyName in section.KeyValues.Keys)
            {
                string value = section.KeyValues[keyName];
                if (string.IsNullOrWhiteSpace(value))
                    throw new Exception(string.Format("Valeur incorrecte dans le fichier de configuration\r\n{0}\r\npour la clef '{1}' dans la section '{2}'.", filePath, keyName, this.name));

                string[] values = value.Split(new char[] { ',' });
                if (values.Length != 12)
                    throw new Exception(string.Format("Nombre de valeurs incorrect dans le fichier de configuration\r\n{0}\r\npour la clef '{1}' dans la section '{2}'.", filePath, keyName, this.name));

                Grade grade = new Grade()
                {
                    Name = keyName,
                    MinimalExperiences = new LPExperiences()
                    {
                        Scientific = Convert.ToInt32(values[0]),
                        PhysicalFitness = Convert.ToInt32(values[1]),
                        ManagerialSkills = Convert.ToInt32(values[2]),
                        Creativity = Convert.ToInt32(values[3]),
                        Empathy = Convert.ToInt32(values[4])
                    },
                    MaxExperiencesGainPerRound = new LPExperiences()
                    {
                        Scientific = Convert.ToInt32(values[5]),
                        PhysicalFitness = Convert.ToInt32(values[6]),
                        ManagerialSkills = Convert.ToInt32(values[7]),
                        Creativity = Convert.ToInt32(values[8]),
                        Empathy = Convert.ToInt32(values[9])
                    },
                    SalaryPerRound = Convert.ToInt32(values[10]),
                    Level = Convert.ToInt32(values[11])
                };
                tmpGrades.Add(grade);
            }

            this.grades = tmpGrades.ToArray<Grade>();
        }