Esempio n. 1
0
            private async Task <Tuple <string, string> > LoadData()
            {
                Car     = null;
                CarSkin = null;
                Track   = null;

                string uri;

                if (EventId.Contains(@"/"))
                {
                    var splitted = EventId.Split('/');
                    uri = $"http://www.radiators-champ.com/RSRLiveTiming/index.php?page=rank&track={splitted[0]}&car={splitted[1]}";
                }
                else
                {
                    uri = $"http://www.radiators-champ.com/RSRLiveTiming/index.php?page=event_rank&eventId={EventId}";
                }

                string page;

                using (var client = new WebClient {
                    Headers =
                    {
                        [HttpRequestHeader.UserAgent] = InternalUtils.GetKunosUserAgent(),
                        [@"X-User-Agent"] = CmApiProvider.UserAgent
                    }
                }) {
                    page = await client.DownloadStringTaskAsync(uri);
                }

                var carIdMatch         = Regex.Match(page, @"\bdata-car=""([\w-]+)""");
                var trackIdMatch       = Regex.Match(page, @"\bdata-track=""([\w-]+)""");
                var trackLayoutIdMatch = Regex.Match(page, @"\bdata-track-layout=""([\w-]+)""");

                if (!carIdMatch.Success || !trackIdMatch.Success)
                {
                    return(null);
                }

                var carId         = carIdMatch.Groups[1].Value;
                var trackId       = trackIdMatch.Groups[1].Value;
                var trackLayoutId = trackLayoutIdMatch.Success ? trackLayoutIdMatch.Groups[1].Value : null;

                if (trackLayoutId == trackId)
                {
                    trackLayoutId = null; // TODO: temporary fix
                }

                Car     = CarsManager.Instance.GetById(carId);
                CarSkin = Car?.SelectedSkin;
                Track   = TracksManager.Instance.GetLayoutById(trackId, trackLayoutId);

                return(new Tuple <string, string>(carId, trackId));
            }