コード例 #1
0
        /// <summary>
        /// Find zodiakInfo by its id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private ZodiacSignInfo GetZodiakByID(int id)
        {
            ZodiacSignInfo zodiacInfo = null;

            foreach (ZodiacSignInfo zodiac in _zodiacList)
            {
                if (zodiac.Id == id)
                {
                    zodiacInfo = zodiac;
                    break;
                }
            }
            return(zodiacInfo);
        }
コード例 #2
0
        public void LoadHoroscope()
        {
            // load zodiac sign data
            using (StreamReader fileReader = new StreamReader(new FileStream(ZODIAC_FILE, FileMode.Open)))
            {
                string line;
                while ((line = fileReader.ReadLine()) != null)
                {
                    string[] data      = line.Split(';');
                    int      id        = int.Parse(data[0]);
                    string   name      = data[1];
                    string   imagePath = data[2];
                    DateTime startDate = DateTime.Parse(data[3]);
                    DateTime endDate   = DateTime.Parse(data[4]);

                    ZodiacSignInfo zsi = new ZodiacSignInfo(id, name, imagePath, startDate, endDate);
                    _zodiacList.Add(zsi);
                }
            }

            // load prediction data
            using (StreamReader fileReader = new StreamReader(new FileStream(PREDICTION_FILE, FileMode.Open)))
            {
                string line;
                while ((line = fileReader.ReadLine()) != null)
                {
                    string[] data       = line.Split(';');
                    int      zodiacId   = int.Parse(data[0]);
                    string   prediction = data[1];

                    // find zodiak by id and add prediction to its list
                    ZodiacSignInfo zodiacInfo = GetZodiakByID(zodiacId);
                    zodiacInfo.PredictionList.Add(prediction);
                }
            }
        }