public IList GetRoomDrawings(int roomId)
 {
     return(_drawingRepository
            .ListByGameRoom(roomId)
            .Select(d => new
     {
         d.GameRoomId,
         d.PlayerId,
         _playerRepository.Get(d.PlayerId)?.Name,
         d.ThemeId,
         _themeRepository.Get(d.ThemeId).Text,
         d.Url
     })
            .ToList());
 }
        public async Task Synchronize(string apiKey, DateTimeOffset previousUpdateTimestamp)
        {
            _messageHub.Publish(new SetSynchronizerStart {
                ForSubtheme = false
            });

            try
            {
                var getSetsParameters = new GetSetsParameters
                {
                    UpdatedSince = previousUpdateTimestamp.UtcDateTime
                };

                var recentlyUpdatedSets = await GetAllSetsFor(apiKey, getSetsParameters);

                _messageHub.Publish(new AcquiringSetsEnd {
                    Count = recentlyUpdatedSets.Count
                });

                foreach (var themeGroup in recentlyUpdatedSets.GroupBy(bricksetSet => bricksetSet.Theme))
                {
                    var theme = _themeRepository.Get(themeGroup.Key);

                    foreach (var subthemeGroup in themeGroup.GroupBy(themeSets => themeSets.Subtheme))
                    {
                        var subtheme = _subthemeRepository.Get(theme.Name, subthemeGroup.Key);

                        foreach (var bricksetSet in subthemeGroup)
                        {
                            await AddOrUpdateSet(apiKey, theme, subtheme, bricksetSet);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _messageHub.Publish(new SetSynchronizerException {
                    Exception = ex
                });
            }

            _messageHub.Publish(new SetSynchronizerEnd {
                ForSubtheme = false
            });
        }
        public async Task Synchronize_BricksetApiServiceReturnsListOfThemes_AllThemesAreSaved()
        {
            var themesList = JsonConvert.DeserializeObject <List <Themes> >(GetResultFileFromResource(Constants.JsonFileGetThemes));
            var yearsList  = JsonConvert.DeserializeObject <List <Years> >(GetResultFileFromResource(Constants.JsonFileGetYears));

            var bricksetApiService = Substitute.For <IBricksetApiService>();

            bricksetApiService
            .GetThemes(Arg.Any <ParameterApiKey>())
            .Returns(themesList);
            bricksetApiService
            .GetYears(Arg.Is <ParameterTheme>(parameter => parameter.Theme == Constants.TestThemeArchitecture))
            .Returns(yearsList);

            var themeSynchronizer = CreateTarget(bricksetApiService);

            var themes = await themeSynchronizer.Synchronize(string.Empty).ConfigureAwait(false);

            Check.That(themes).CountIs(themesList.Count);
            Check.That(_themeRepository.All()).CountIs(themesList.Count);
            Check.That(_themeRepository.Get(Constants.TestThemeArchitecture).SetCountPerYear).Not.IsEmpty();
        }
Exemple #4
0
        public IList Drawings(int page = 0, int pageSize = 10)
        {
            if (!Request.Headers.Keys.Contains("x-drawwars-auth"))
            {
                throw new Exception("Not authenticated");
            }

            var header = Request.Headers["x-drawwars-auth"];
            var userId = CryptoUtils.GetUserIdFromHeader(header);

            return(_drawingRepository
                   .ListByUser(userId)
                   .Select(d => new
            {
                d.GameRoomId,
                d.PlayerId,
                d.ThemeId,
                _themeRepository.Get(d.ThemeId).Text,
                d.Url
            })
                   .ToList());
        }
Exemple #5
0
        public void Get_InvalidThemeName_ReturnsNull(string themeName)
        {
            var theme = _themeRepository.Get(themeName);

            Check.That(theme).IsNull();
        }
        public async Task <IEnumerable <Theme> > Synchronize(string apiKey)
        {
            _messageHub.Publish(new ThemeSynchronizerStart());

            var themeList = new List <Theme>();

            try
            {
                var getThemesParameters = new ParameterApiKey
                {
                    ApiKey = apiKey
                };

                var bricksetThemes = (await _bricksetApiService.GetThemes(getThemesParameters).ConfigureAwait(false)).ToList();

                _messageHub.Publish(new ThemesAcquired {
                    Count = bricksetThemes.Count
                });

                foreach (var bricksetTheme in bricksetThemes)
                {
                    _messageHub.Publish(new SynchronizingThemeStart {
                        Theme = bricksetTheme.Theme
                    });

                    try
                    {
                        var theme = bricksetTheme.ToTheme();

                        var getYearsParameters = new ParameterTheme
                        {
                            ApiKey = apiKey,
                            Theme  = bricksetTheme.Theme
                        };

                        theme.SetCountPerYear = (await _bricksetApiService.GetYears(getYearsParameters).ConfigureAwait(false))
                                                .ToYearSetCountEnumerable()
                                                .ToList();

                        var persistedTheme = _themeRepository.Get(theme.Name);

                        if (persistedTheme != null)
                        {
                            theme.Id = persistedTheme.Id;
                        }

                        _themeRepository.AddOrUpdate(theme);

                        themeList.Add(theme);
                    }
                    catch (Exception ex)
                    {
                        _messageHub.Publish(new SynchronizingThemeException {
                            Theme = bricksetTheme.Theme, Exception = ex
                        });
                    }

                    _messageHub.Publish(new SynchronizingThemeEnd {
                        Theme = bricksetTheme.Theme
                    });
                }
            }
            catch (Exception ex)
            {
                _messageHub.Publish(new ThemeSynchronizerException {
                    Exception = ex
                });
            }

            _messageHub.Publish(new ThemeSynchronizerEnd());

            return(themeList);
        }