Exemplo n.º 1
0
        private async Task SyncAddons(WowClientType clientType, IEnumerable <Addon> addons)
        {
            var addonIds = addons.Select(addon => addon.ExternalId);

            try
            {
                var addonTasks   = _providers.Select(p => p.GetAll(clientType, addonIds));
                var addonResults = await Task.WhenAll(addonTasks);

                var addonResultsConcat = addonResults.SelectMany(res => res);

                foreach (var addon in addons)
                {
                    var match = addonResultsConcat.FirstOrDefault(a => a.ExternalId == addon.ExternalId);
                    if (match == null || match.Version == addon.LatestVersion)
                    {
                        continue;
                    }

                    addon.LatestVersion = match.Version;
                    addon.Name          = match.Name;
                    addon.Author        = match.Author;
                    addon.DownloadUrl   = match.DownloadUrl;
                    addon.GameVersion   = match.GameVersion;
                    addon.ThumbnailUrl  = match.ThumbnailUrl;
                    addon.ExternalUrl   = match.ExternalUrl;

                    _addonRepository.UpdateItem(addon);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to sync addons");
            }
        }
Exemplo n.º 2
0
        private async Task SyncAddons(
            WowClientType clientType,
            IEnumerable <Addon> addons,
            IAddonProvider provider)
        {
            var providerAddonIds = GetExternalIdsForProvider(provider, addons);

            if (!providerAddonIds.Any())
            {
                return;
            }

            var searchResults = await provider.GetAll(clientType, providerAddonIds);

            foreach (var result in searchResults)
            {
                var addon      = addons.FirstOrDefault(addon => addon.ExternalId == result.ExternalId);
                var latestFile = GetLatestFile(result, addon.ChannelType);

                if (result == null || latestFile == null || latestFile.Version == addon.LatestVersion)
                {
                    if (addon.ThumbnailUrl != result.ThumbnailUrl)
                    {
                        addon.ThumbnailUrl = result.ThumbnailUrl;
                        _addonRepository.UpdateItem(addon);
                        await SyncThumbnail(addon, true);
                    }
                    else
                    {
                        await SyncThumbnail(addon);
                    }

                    continue;
                }

                addon.LatestVersion = latestFile.Version;
                addon.Name          = result.Name;
                addon.Author        = result.Author;
                addon.DownloadUrl   = latestFile.DownloadUrl;

                if (!string.IsNullOrEmpty(latestFile.GameVersion))
                {
                    addon.GameVersion = latestFile.GameVersion;
                }

                addon.ThumbnailUrl = result.ThumbnailUrl;
                addon.ExternalUrl  = result.ExternalUrl;

                await SyncThumbnail(addon);

                _addonRepository.UpdateItem(addon);
            }
        }
Exemplo n.º 3
0
        private async Task SyncAddons(WowClientType clientType, IEnumerable <Addon> addons)
        {
            try
            {
                foreach (var provider in _providers)
                {
                    var providerAddonIds = addons
                                           .Where(addon => addon.ProviderName == provider.Name)
                                           .Select(addon => addon.ExternalId);

                    var addonResults = await provider.GetAll(clientType, providerAddonIds);

                    foreach (var result in addonResults)
                    {
                        var addon      = addons.FirstOrDefault(addon => addon.ExternalId == result.ExternalId);
                        var latestFile = GetLatestFile(result, addon.ChannelType);

                        if (result == null || latestFile == null || latestFile.Version == addon.LatestVersion)
                        {
                            await SyncThumbnail(addon);

                            continue;
                        }

                        addon.LatestVersion = latestFile.Version;
                        addon.Name          = result.Name;
                        addon.Author        = result.Author;
                        addon.DownloadUrl   = latestFile.DownloadUrl;

                        if (!string.IsNullOrEmpty(latestFile.GameVersion))
                        {
                            addon.GameVersion = latestFile.GameVersion;
                        }

                        addon.ThumbnailUrl = result.ThumbnailUrl;
                        addon.ExternalUrl  = result.ExternalUrl;

                        await SyncThumbnail(addon);

                        _addonRepository.UpdateItem(addon);
                    }
                }
            }
            catch (Exception ex)
            {
                _analyticsService.Track(ex, "Failed to sync addons");
            }
        }