Exemplo n.º 1
0
        public async Task <bool> LoadFromApi(ApiHashes hashes)
        {
            _remoteHashes = hashes;

            var remoteList = _remoteHashes.ToList();
            var localList  = _localHashes.ToList();
            var newHashes  = new List <string>();

            var changed = false;

            // Temporary doing in foreach loop because we load and map at the same time currently, while we intend for items to rely on eachother..
            var i = 0;

            foreach (var repo in _repositories)
            {
                var j = i++;
                // TODO: Horrible index based, needs to keep ToList and _repositories into sync!! :<
                var remoteHash = remoteList[j];
                var localHash  = localList[j];
                if (remoteHash != localHash)
                {
                    await repo.LoadFromApi(remoteHash).ConfigureAwait(false);

                    changed = true;
                }
                newHashes.Add(repo.Hash);
            }
            var newHash = newHashes.ToApiHashes();
            await _cacheManager.SetObject(RepoHelper.GetFullApiPath(HashesJson), newHash.ToJson());

            _localHashes = newHash;

            return(changed);
        }
Exemplo n.º 2
0
        public ContentApiHandler(UserSettings settings, IApiLocalObjectCacheManager cacheManager)
        {
            _rest         = new ContentRestApi();
            _settings     = settings;
            _cacheManager = cacheManager;
            var mappingEngine = GetMapper();

            _remoteHashes      = new ApiHashes();
            _localHashes       = new ApiHashes();
            _modRepository     = new ContentApiRepository <ModDto, Mod>(_rest, mappingEngine, cacheManager);
            _missionRepository = new ContentApiRepository <MissionDto, Mission>("mission", _rest, mappingEngine,
                                                                                cacheManager);
            _modSetRepository = new ContentApiRepository <ModSetDto, Collection>("mod_set", _rest, mappingEngine,
                                                                                 cacheManager);
            _repositories = new IContentApiRepository[] { _modRepository, _modSetRepository, _missionRepository };
        }
Exemplo n.º 3
0
        public async Task LoadFromDisk()
        {
            var loaded    = true;
            var newHashes = new List <string>();

            foreach (var repo in _repositories)
            {
                if (!(await repo.TryLoadFromDisk().ConfigureAwait(false)))
                {
                    loaded = false;
                }
                newHashes.Add(repo.Hash);
            }

            Loaded = loaded;

            // This might be overzealous, but at least fixes the current issue (otherwise had to restart twice to fix current issue)
            _localHashes = newHashes.ToApiHashes(); //await GetHashes().ConfigureAwait(false);
        }
Exemplo n.º 4
0
 public ApiHashesEvent(ApiHashes hashes)
 {
     Hashes = hashes;
 }
 async Task<Dictionary<Guid, ModClientApiJsonV3WithGameId>> GetContentList(Guid gameId, ApiHashes hashes) {
     var r = await _locator.GetApiContext().GetMods(gameId, hashes.Mods).ConfigureAwait(false);
     return r.ToDictionary(x => x.Id, x => x);
 }
        private async Task<Dictionary<Guid, ModClientApiJsonV3WithGameId>> GetContent(Game game, ApiHashes latestHashes) {
            var compatGameIds = game.GetCompatibleGameIds();
            var ctx = _locator.GetGameContext();
            await ctx.Load(compatGameIds).ConfigureAwait(false);

            // TODO: Only process and keep content that we actually are looking for (1. Installed content, 2. Desired content)
            var mods = new Dictionary<Guid, ModClientApiJsonV3WithGameId>();
            foreach (var c in compatGameIds) {
                var cMods = await GetContentList(c, latestHashes).ConfigureAwait(false);
                foreach (var m in cMods)
                    m.Value.GameId = c;
                mods.AddRange(cMods);
            }

            return mods;
        }
Exemplo n.º 7
0
 async Task ApiHashesReceived(ApiHashes obj) => await Cheat.PublishDomainEvent(new ApiHashesEvent(obj)).ConfigureAwait(false);
Exemplo n.º 8
0
 // TODO: Horrible implementation, need to remain in sync with _repositoreis of Api!!
 public static List <string> ToList(this ApiHashes hashes) => new List <string>
 {
     hashes.Mods,
     hashes.ModSets,
     hashes.Missions
 };
Exemplo n.º 9
0
        async Task <Dictionary <Guid, ModClientApiJsonV3WithGameId> > GetContentList(Guid gameId, ApiHashes hashes)
        {
            var r = await _infoFetcher.GetApiContext().GetMods(gameId, hashes.Mods).ConfigureAwait(false);

            return(r.ToDictionary(x => x.Id, x => x));
        }
Exemplo n.º 10
0
        private async Task <Dictionary <Guid, ModClientApiJsonV3WithGameId> > GetContent(Game game, ApiHashes latestHashes)
        {
            var compatGameIds = game.GetCompatibleGameIds();
            // TODO: Do we actually have to load these?? seems unused...
            await _infoFetcher.Load(compatGameIds).ConfigureAwait(false);

            // TODO: Only process and keep content that we actually are looking for (1. Installed content, 2. Desired content)
            var mods = new Dictionary <Guid, ModClientApiJsonV3WithGameId>();

            foreach (var c in compatGameIds)
            {
                var cMods = await GetContentList(c, latestHashes).ConfigureAwait(false);

                foreach (var m in cMods)
                {
                    m.Value.GameId = c;
                }
                mods.AddRange(cMods);
            }

            return(mods);
        }
Exemplo n.º 11
0
 Task SynchronizeContent(ICollection<Game> games, ApiHashes hashes) {
     return _networkContentSyncer.SyncContent(games.ToArray(), hashes);
 }
Exemplo n.º 12
0
 async Task<List<ModDto>> DownloadContentLists(IEnumerable<Guid> gameIds, ApiHashes hashes) {
     var mods =
         await
             Tools.Transfer.GetJson<List<ModDto>>(
                 new Uri("http://api-cdn.withsix.com/api/v2/mods.json.gz?v=" + hashes.Mods))
                 .ConfigureAwait(false);
     return mods.Where(x => gameIds.Contains(x.GameId)).ToList();
 }
Exemplo n.º 13
0
 public async Task SyncContent(IReadOnlyCollection<Game> games, ApiHashes hashes) {
     var allNetworkContent = await DownloadContentLists(games.Select(x => x.Id), hashes).ConfigureAwait(false);
     foreach (var g in games)
         ProcessGame(g, allNetworkContent);
 }