public static Task <UserInfo> GetAsync(string userId) { // TODO: error handling if (_cache.TryGetValue(userId, out var ret)) { return(Task.FromResult(ret)); } return(_tasks.Get(async() => { var r = await WorkshopHolder.Client.GetAsync <UserInfo>($"/users/{Uri.EscapeDataString(userId)}"); _cache[userId] = r; return r; }, userId)); }
public Task <string> GetUpdateUrlAsync(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null || information._updateUrl != null) { return(Task.FromResult(information?._updateUrl)); } return(_installationUrlTaskCache.Get(async() => { try { var url = $"{information.SourceRegistry}/{type.ToString().ToLowerInvariant()}/{id}/get"; using (var client = new CookieAwareWebClient()) { var updateUrl = await client.GetFinalRedirectAsync(url); if (updateUrl != null) { information._updateUrl = updateUrl; } return updateUrl; } } catch (Exception e) { NonfatalError.NotifyBackground("Can’t download an update", e); return null; } }, type, id)); }
public Task LoadRegistries(bool clearCache = false) { if (clearCache) { _cache.Clear(); } return(_loadCache.Get(CheckRegistriesAsync)); }
public Task <bool> InstallUpdateAsync(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null) { return(Task.FromResult(false)); } return(_installTaskCache.Get(async() => { var updateUrl = await GetUpdateUrlAsync(type, id); Logging.Debug(updateUrl); if (information.IsToUpdateManually) { WindowsHelper.ViewInBrowser(updateUrl ?? information.InformationUrl); return false; } var idsToUpdate = new[] { id }.Append(information.AlternativeIds ?? new string[0]).ToArray(); return updateUrl != null && await ContentInstallationManager.Instance.InstallAsync(updateUrl, new ContentInstallationParams { // Actual installation params PreferCleanInstallation = information.PreferCleanInstallation, // For displaying stuff DisplayName = information.Name, IdsToUpdate = idsToUpdate, // For updating content CupType = type, Author = information.Author, Version = information.Version, InformationUrl = information.InformationUrl, SyncDetails = true /*PostInstallation = { * async (progress, token) => { * var manager = GetAssociatedManager(type); * if (manager == null) return; * * progress.Report(new AsyncProgressEntry("Syncing versions…", 0.9999)); * await Task.Delay(1000); * foreach (var cupSupportedObject in idsToUpdate.Select(x => manager.GetObjectById(x) as ICupSupportedObject).NonNull()) { * Logging.Debug($"Set values: {cupSupportedObject}={information.Version}"); * cupSupportedObject.SetValues(information.Author, information.InformationUrl, information.Version); * } * } * }*/ }); }, type, id)); }
public static Task <GenericModsEnabler> GetInstanceAsync(string rootDirectory, string modsDirectory, bool useHardLinks = true) { if (_instance != null) { if (GetParameters(rootDirectory, modsDirectory, useHardLinks) == _instanceParameters) { return(Task.FromResult(_instance)); } DisposeHelper.Dispose(ref _instance); } return(InstanceTaskCache.Get(() => GetInstanceAsyncInner(rootDirectory, modsDirectory, useHardLinks))); }
public static Task <string> GetAsync(string badgeName) { // TODO: error handling if (_carBrands != null) { return(Task.FromResult(_carBrands.FirstOrDefault(x => x.Name == badgeName)?.Icon)); } return(_tasks.Get(async() => { _carBrands = await WorkshopHolder.Client.GetAsync <List <WorkshopContentCategory> >("/car-brands"); return _carBrands; }).ContinueWith(r => { return r.Result.FirstOrDefault(x => x.Name == badgeName)?.Icon; })); }
public Task <bool> InstallUpdateAsync(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null) { Logging.Warning($"Failed to update: information == null (type={type}, ID={id})"); return(Task.FromResult(false)); } return(_installTaskCache.Get(async() => { var updateUrl = await GetUpdateUrlAsync(type, id); Logging.Debug(updateUrl); if (information.IsToUpdateManually) { WindowsHelper.ViewInBrowser(updateUrl ?? information.InformationUrl); return false; } var idsToUpdate = new[] { id }.Append(information.AlternativeIds ?? new string[0]).ToArray(); return updateUrl != null && await ContentInstallationManager.Instance.InstallAsync(updateUrl, new ContentInstallationParams(true) { // Actual installation params PreferCleanInstallation = information.PreferCleanInstallation, // For displaying stuff DisplayName = information.Name, IdsToUpdate = idsToUpdate, // For updating content CupType = type, Author = information.Author, Version = information.Version, InformationUrl = information.InformationUrl, SyncDetails = true }); }, type, id)); }
public Task <bool> ReportUpdateAsync(CupContentType type, [NotNull] string id) { var information = GetInformation(type, id); if (information == null) { return(Task.FromResult(false)); } return(_reportTaskCache.Get(async() => { try { var url = $"{information.SourceRegistry}/{type.ToString().ToLowerInvariant()}/{id}/complain"; using (var client = new CookieAwareWebClient()) { await client.UploadStringTaskAsync(url, ""); IgnoreUpdate(type, id); Toast.Show("Update reported", "Update reported and will be ignored. Thank you for your participation"); return true; } } catch (Exception e) { NonfatalError.NotifyBackground("Can’t report an update", e); return false; } }, type, id)); }
public static Task <ChangeableObservableCollection <TyresMachineInfo> > LoadMachinesAsync() { return(_list != null?Task.FromResult(_list) : ListTaskCache.Get(LoadMachinesAsyncInner)); }
public static Task <List <RemoteSetupInformation> > GetAvailableSetups(string carId, CancellationToken cancellation = default) { return(TaskCache.Get(() => GetAvailableSetupsInner(carId, cancellation), nameof(GetAvailableSetupsInner), carId)); }