Exemplo n.º 1
0
        // function to assign data to object list
        private void assignInfos(dynamic SteamDetails, int numHorses)
        {
            // clear list every time to prevent dupulcation
            Horses.Clear();

            // variables to use later
            double price     = 0.0;
            String horseName = "";
            int    horseID   = 0;

            // Use JArray Class to gets child JSON tokens
            var text = SteamDetails["RawData"]["Markets"][0]["Selections"];

            // get race start time from json
            String timeStamp = SteamDetails["RawData"]["StartTime"];

            // get horse name, number and price, then assign to list object
            for (int i = 0; i < numHorses; i++)
            {
                horseID   = text[i]["Tags"]["participant"];
                horseName = text[i]["Tags"]["name"];
                price     = text[i]["Price"];
                Horses.Add(new Horse(horseID, horseName, price));
            }

            // print out list in order and output json
            CustomUtilities.DisplayAll(timeStamp, Horses, 2);
        }
Exemplo n.º 2
0
        // function to assign data to object list
        private void assignInfos(XElement root)
        {
            // clear list every time to prevent dupulcation
            Horses.Clear();

            // variables to use later
            double price     = 0.0;
            String horseName = "";
            int    horseID   = 0;

            // get race start time from xml
            String timeStamp = root.Element("races").Element("race").Element("start_time").Value;

            // get all participants details from xml
            var horseInfos = root.Element("races").Element("race").Element("horses").Elements("horse");

            // get horse name, number and price, then assign to list object
            foreach (var horseInfo in horseInfos)
            {
                horseID   = Convert.ToInt32(horseInfo.Element("number").Value);
                horseName = horseInfo.Attribute("name").Value;
                price     = getPrice(root, horseID);

                if (price == 0)
                {
                    Console.WriteLine("Price data didn't match with given horseID\n");
                    return;
                }

                Horses.Add(new Horse(horseID, horseName, price));
            }

            // print out list in order and output json
            CustomUtilities.DisplayAll(timeStamp, Horses, 1);
        }