Ejemplo n.º 1
0
        public static async Task <Tuple <RemoteSetupInformation, string> > GetSetupFullInformation(string setupId,
                                                                                                   CancellationToken cancellation = default)
        {
            try {
                var ini = await Cache.GetStringAsync($"http://thesetupmarket.com/api/get-setup-file-details/{setupId}", $"{setupId}.ini",
                                                     SettingsHolder.Integrated.TheSetupMarketCacheDataPeriod.TimeSpan).ConfigureAwait(false);

                if (cancellation.IsCancellationRequested)
                {
                    return(null);
                }

                var data = await Cache.GetStringAsync($"http://thesetupmarket.com/api/get-setup/{setupId}", $"{setupId}.json",
                                                      SettingsHolder.Integrated.TheSetupMarketCacheDataPeriod.TimeSpan).ConfigureAwait(false);

                if (cancellation.IsCancellationRequested)
                {
                    return(null);
                }

                return(Tuple.Create(RemoteSetupInformation.FromTheSetupMarketJToken(JObject.Parse(data)), ini));
            } catch (Exception e) {
                if (!cancellation.IsCancellationRequested)
                {
                    Logging.Warning(e);
                }

                return(null);
            }
        }
        public static async Task <List <RemoteSetupInformation> > GetAvailableSetups(string carId, CancellationToken cancellation = default(CancellationToken))
        {
            if (_parsed != null && DateTime.Now < _parsedLifeSpan)
            {
                // A little bit of extra caching to avoid going to a different thread to reparse already loaded data
                // for each new car.
                return(_parsed.Where(x => x.CarId == carId).ToList());
            }

            try {
                var data = await Cache.GetAsync("http://thesetupmarket.com/api/get-setups/Assetto%20Corsa", "List.json", TimeSpan.FromHours(3))
                           .ConfigureAwait(false);

                if (cancellation.IsCancellationRequested || data == null)
                {
                    return(null);
                }

                _parsed = await Task.Run(() => JArray.Parse(data).Select(x => RemoteSetupInformation.FromTheSetupMarketJToken(x)).NonNull().ToList());

                _parsedLifeSpan = DateTime.Now + TimeSpan.FromHours(3);
                return(_parsed.Where(x => x.CarId == carId).ToList());
            } catch (Exception e) {
                if (!cancellation.IsCancellationRequested)
                {
                    Logging.Warning(e);
                }

                return(null);
            }
        }
Ejemplo n.º 3
0
        public static async Task <List <RemoteSetupInformation> > GetAvailableSetupsInner(string carId, CancellationToken cancellation = default(CancellationToken))
        {
            if (_parsed != null && DateTime.Now < _parsedLifeSpan)
            {
                // A little bit of extra caching to avoid going to a different thread to reparse already loaded data
                // for each new car.
                return(_parsed.Where(x => x.CarId == carId).ToList());
            }

            try {
                foreach (var url in SettingsHolder.Integrated.TheSetupMarketCacheServer ? ListUrls : new[] { ListUrls.Last() })
                {
                    Logging.Write(url);

                    try {
                        var data = await Cache.GetStringAsync(url, "List.json",
                                                              SettingsHolder.Integrated.TheSetupMarketCacheListPeriod.TimeSpan).ConfigureAwait(false);

                        _parsed = await Task.Run(() => JArray.Parse(data).Select(x =>
                                                                                 RemoteSetupInformation.FromTheSetupMarketJToken(x)).NonNull().ToList());

                        if (cancellation.IsCancellationRequested || data == null)
                        {
                            return(null);
                        }
                        break;
                    } catch (Exception e) {
                        Logging.Warning($"Error while loading {url}: {e}");
                        if (url == ListUrls.Last())
                        {
                            throw;
                        }
                    }
                }

                if (_parsed == null)
                {
                    throw new Exception("Failed to load any data");
                }

                _parsedLifeSpan = DateTime.Now + TimeSpan.FromHours(3);
                return(_parsed.Where(x => x.CarId == carId).ToList());
            } catch (Exception e) {
                if (!cancellation.IsCancellationRequested)
                {
                    Logging.Warning(e);
                }

                return(null);
            }
        }
Ejemplo n.º 4
0
 public RemoteCarSetupObject(RemoteSetupsManager manager, RemoteSetupInformation information) : base(manager, information.Id, true)
 {
     _information    = information;
     Source          = manager.Source;
     CarId           = _information.CarId;
     TrackId         = _information.TrackKunosId;
     Author          = _information.Author;
     Version         = _information.Version;
     Downloads       = _information.Downloads;
     CommunityRating = _information.CommunityRating;
     Trim            = _information.Trim;
     BestTime        = _information.BestTime;
     _track          = new Lazy <TrackObject>(() => TrackId == null ? null : TracksManager.Instance.GetLayoutByKunosId(TrackId)?.MainTrackObject);
 }
        public static async Task <RemoteSetupInformation> GetSetupInformation(string setupId, CancellationToken cancellation = default(CancellationToken))
        {
            try {
                var data = await Cache.GetAsync($"http://thesetupmarket.com/api/get-setup/{setupId}", $"{setupId}.json")
                           .ConfigureAwait(false);

                if (cancellation.IsCancellationRequested)
                {
                    return(null);
                }
                return(RemoteSetupInformation.FromTheSetupMarketJToken(JObject.Parse(data)));
            } catch (Exception e) {
                if (!cancellation.IsCancellationRequested)
                {
                    Logging.Warning(e);
                }

                return(null);
            }
        }