Ejemplo n.º 1
0
        /// <summary>
        /// Gets the participant horses.
        /// </summary>
        /// <param name="path">The XML file path.</param>
        /// <returns>List of participant horses</returns>
        public override List <ParticipantHorse> GetParticipantHorses(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(new List <ParticipantHorse>());
            }
            XmlSerializer xs = new XmlSerializer(typeof(CaulfieldRaceModel));

            using (StreamReader reader = new StreamReader(path))
            {
                var deserialize = (CaulfieldRaceModel)xs.Deserialize(reader);
                RaceName = GetRaceName(deserialize);

                var participatingHorses = new List <ParticipantHorse>();
                //Get list of all the horses in the race.
                foreach (var horse in GetHorseList(deserialize))
                {
                    var h = new ParticipantHorse
                    {
                        Id   = horse.Number,
                        Name = horse.Name,
                    };
                    participatingHorses.Add(h);
                }
                //Get price of each horse in the race.
                foreach (var horse in GetHorseListWithPrice(deserialize))
                {
                    var horseWithPrice = participatingHorses.Find(h => h.Id == horse?.Number);
                    horseWithPrice.Price = Convert.ToDouble(horse?.Price);
                }

                return(participatingHorses);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the participant horses.
        /// </summary>
        /// <param name="path">The JSON file path.</param>
        /// <returns>List of participant horses</returns>
        public override List <ParticipantHorse> GetParticipantHorses(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(new List <ParticipantHorse>());
            }
            using (StreamReader file = File.OpenText(path))
            {
                var jsonSerializer = new JsonSerializer();
                var raceResult     = (WolferhamptonRaceModel)jsonSerializer.Deserialize(file, typeof(WolferhamptonRaceModel));

                RaceName = GetRaceName(raceResult);

                var horses = new List <ParticipantHorse>();
                //Get all the participating horses.
                foreach (var participants in GetHorseRaceParticipants(raceResult))
                {
                    var horse = new ParticipantHorse
                    {
                        Id   = participants.Id.ToString(),
                        Name = participants.Name
                    };

                    horses.Add(horse);
                }
                //Get price of the participating horse.
                foreach (var market in MarketList(raceResult))
                {
                    foreach (var selection in market.Selections)
                    {
                        var horse = horses.Find(h => h.Id == selection.Tags.participant);
                        horse.Price = selection.Price;
                    }
                }
                return(horses);
            }
        }