Example #1
0
        public async System.Threading.Tasks.Task <RaceEvent> get_event(RaceEvent ref_eve, string eve_id)
        {
            try
            {
                RaceEvent eve      = new RaceEvent();
                string    endpoint = $"{ep}GetData.asp?SessionID={session_id}&Method=GetEvent&EventID={eve_id}&Runners=true";
                string    res      = await WRequest.get_response(endpoint);

                XDocument doc = XDocument.Parse(res);
                if (check_session(doc) == false)
                {
                    if (res.Contains("Request Limit Exceeded"))
                    {
                        await Task.Delay(1000);

                        return(await get_event(ref_eve, eve_id));
                    }
                    MainApp.g_working = false;
                    return(null);
                }

                MainApp.g_working = true;
                XElement elem = null;
                try
                {
                    elem = doc.Element("Data").Element("GetEvent").Element("Event");
                }
                catch (Exception e)
                {
                    return(null);
                }
                if (elem == null)
                {
                    return(null);
                }
                eve.ID           = elem.Attribute("ID").Value;
                eve.EventNo      = elem.Element("EventNo").Value;
                eve.Name         = elem.Element("Name").Value;
                eve.Distance     = elem.Element("Distance").Value;
                eve.Track        = elem.Element("Track").Value;
                eve.TrackRtg     = elem.Element("TrackRtg").Value;
                eve.Starters     = elem.Element("Starters").Value;
                eve.StartTime_Au = elem.Element("StartTime").Value;
                eve.Class        = elem.Element("Class").Value;
                eve.Prizemoney   = elem.Element("Prizemoney").Value;
                eve.Status       = elem.Element("Status").Value;
                if (eve.Status.ToUpper() == "FINAL")
                {
                    eve.Status = "PAYING";
                }
                eve.WeatherTC = elem.Element("WeatherTC").Value;
                WeatherConditions con = new WeatherConditions();
                con.TempC      = elem.Element("WeatherCondtions").Element("TempC").Value;
                con.Humidity   = elem.Element("WeatherCondtions").Element("Humidity").Value;
                con.WindSpeed  = elem.Element("WeatherCondtions").Element("WindSpeed").Value;
                con.WindDir    = elem.Element("WeatherCondtions").Element("WindDir").Value;
                eve.WeatherCon = con;
                eve.Rail       = elem.Element("Rail").Value;
                eve.CodeAAP    = elem.Element("CodeAAP").Value;
                eve.CodeBF     = elem.Element("CodeBF").Value;
                eve.Runners    = new List <Runner>();
                foreach (var node in elem.Elements("Runner"))
                {
                    Runner runner = new Runner();
                    runner.Name      = node.Element("Name").Value;
                    runner.Jockey    = node.Element("Jockey").Value;
                    runner.Trainer   = node.Element("Trainer").Value;
                    runner.Bar       = node.Element("Bar").Value;
                    runner.Hcp       = node.Element("Hcp").Value;
                    runner.Scr       = node.Element("Scr").Value;
                    runner.Emergency = node.Element("Emergency").Value;
                    eve.Runners.Add(runner);
                }

                eve.Venue         = ref_eve.Venue;
                eve.EventCode     = ref_eve.EventCode;
                eve.Type          = ref_eve.Type;
                eve.State         = ref_eve.State;
                eve.StartTime     = ref_eve.StartTime;
                eve.Date          = ref_eve.Date;
                MainApp.g_working = true;
                return(eve);
            }
            catch (Exception ex)
            {
                MainApp.log_error("DynHelperError: " + ex.Message + "\n" + ex.StackTrace);
                MainApp.g_working = false;
                return(null);
            }
        }
Example #2
0
        public async System.Threading.Tasks.Task <List <RaceEvent> > get_event_schedule(DateTime date)
        {
            try
            {
                DateTime         au_now   = date.Subtract(MainApp.g_time_diff);
                List <RaceEvent> schedule = new List <RaceEvent>();
                string           date_str = date.ToString("yyyy-MM-dd");
                string           endpoint = $"{ep}GetData.asp?SessionID={session_id}&Method=GetEventSchedule&Date={date_str}&Types=R,H,G&Limit=999";
                string           res      = await WRequest.get_response(endpoint);

                XDocument doc = XDocument.Parse(res);
                if (check_session(doc) == false)
                {
                    if (res.Contains("Request Limit Exceeded"))
                    {
                        await Task.Delay(1000);

                        return(await get_event_schedule(date));
                    }
                    MainApp.log_error("Error getting event schedule");
                    MainApp.log_error(res);
                    MainApp.g_working = false;
                    return(null);
                }

                var all_events = doc.Descendants("Event");
                foreach (var node in all_events)
                {
                    RaceEvent eve = new RaceEvent();
                    eve.ID           = node.Attribute("ID").Value;
                    eve.Date         = date;
                    eve.EventCode    = node.Attribute("EventCode").Value;
                    eve.StartTime_Au = node.Attribute("StartTime").Value;
                    eve.Type         = node.Attribute("Type").Value;
                    if (eve.Type == "T")
                    {
                        eve.Type = "H";
                    }
                    eve.Venue   = node.Attribute("Venue").Value;
                    eve.EventNo = node.Attribute("EventNo").Value;
                    eve.Status  = node.Attribute("EventStatus").Value;
                    if (eve.Status.ToUpper() == "FINAL")
                    {
                        eve.Status = "PAYING";
                    }
                    eve.State = node.Attribute("State").Value;

                    if (au_states.Contains(eve.State) == false ||
                        eve.Status.ToUpper() != "OPEN" ||
                        eve.Type != "R")
                    {
                        continue;
                    }

                    if (!MainApp.DEBUG && eve.StartTime_Au.CompareTo(au_now.ToString("HH:mm:ss")) < 0)
                    {
                        continue;
                    }

                    string[] fields = eve.StartTime_Au.Split(':');
                    eve.StartTime = new DateTime(au_now.Year, au_now.Month, au_now.Day, int.Parse(fields[0]), int.Parse(fields[1]), int.Parse(fields[2]));

                    //MainApp.log_info(eve.ToString());
                    schedule.Add(eve);
                }
                MainApp.g_working = true;
                return(schedule);
            }
            catch (Exception ex)
            {
                MainApp.log_error("DynHelperError: " + ex.Message + "\n" + ex.StackTrace);
                MainApp.g_working = false;
                return(null);
            }
        }