Exemple #1
0
        public static async Task Run([TimerTrigger("0 0 */4 * * *" /* runs every fourth hour */
#if DEBUG
                                                   , RunOnStartup = true
#endif
                                                   )] TimerInfo myTimer, ILogger log)
        {
            _tmdbApiKey         = Environment.GetEnvironmentVariable("tmdb_api_key");
            _databaseConnection = Environment.GetEnvironmentVariable("database_connection");
            _tmdbService        = new TMDBServiceImpl(_tmdbApiKey, log);

            log.LogInformation($"TMDBDataCollector function started at: {DateTime.Now}");

            List <LocalizationCodes> localizationCodes = GetLocalizationCodes(log);
            await _tmdbService.InitializeAsync();

            if (localizationCodes != null)
            {
                foreach (LocalizationCodes entry in localizationCodes)
                {
                    _tmdbService.Clear();
                    _tmdbSnapshot = await DataCollector.CollectDataAsync(_tmdbService, log, entry.LanguageCode, entry.RegionCode);

                    WriteIntoDatabase(_tmdbSnapshot, log);
                }
            }

            log.LogInformation($"TMDBDataCollector function finished at: {DateTime.Now}");
        }
Exemple #2
0
 public CreateMovieCommandHandler(IMovieRepository movieRepository, IMediator mediator, ITMDBService tmdbService, IMapper mapper)
 {
     _movieRepository = movieRepository;
     _mediator        = mediator;
     _tmdbService     = tmdbService;
     _mapper          = mapper;
     _logger          = new FileLogger().Logger;
 }
        public AuthenticationActionCreator(ITMDBService tmdbService, IAppStoreContainer storeContainer)
        {
            TMDBService = tmdbService;
            Store       = storeContainer.Store;

            LoginAction = Store.CreateAsyncActionVoid <Credentials>(async(dispatcher, getState, credentials) =>
            {
                var state = getState().DiscoverState;

                dispatcher(new LoginStarted());

                var tokenRequestResponse = await TMDBService.CreateTokenRequest();

                if (!tokenRequestResponse.IsSuccessful)
                {
                    dispatcher(new LoginFailedAction
                    {
                        StatusMessage = tokenRequestResponse.Data.StatusMessage
                    });

                    return;
                }

                var token = tokenRequestResponse.Data.RequestToken;

                var validationResponse = await TMDBService.ValidateToken(credentials.Username, credentials.Password, token);

                if (!validationResponse.IsSuccessful)
                {
                    dispatcher(new LoginFailedAction
                    {
                        StatusMessage = validationResponse.Data.StatusMessage
                    });

                    return;
                }

                token = validationResponse.Data.RequestToken;

                var sessionResponse = await TMDBService.CreateSession(token);

                if (!sessionResponse.IsSuccessful)
                {
                    dispatcher(new LoginFailedAction
                    {
                        StatusMessage = validationResponse.Data.StatusMessage
                    });

                    return;
                }

                dispatcher(new LoggedInAction
                {
                    SessionId = sessionResponse.Data.SessionId
                });
            });
        }
        public SearchActionCreator(ITMDBService tmdbService, IAppStoreContainer storeContainer)
        {
            TMDBService = tmdbService;
            Store       = storeContainer.Store;

            LoadNextPageAction = Store.CreateAsyncActionVoid <string>(async(dispatcher, getState, query) =>
            {
                var state = getState().SearchState;

                if (state.TotalPages != 0 && state.LastLoadedPage == state.TotalPages && query == state.Query)
                {
                    return;
                }

                if (state.Query != query || string.IsNullOrEmpty(query))
                {
                    dispatcher(new ResetSearchResults
                    {
                        Query = query
                    });
                }

                dispatcher(new StartLoadingPage());

                state = getState().SearchState;

                var response = await TMDBService.Search(query, ++state.LastLoadedPage);

                if (response.IsSuccessful)
                {
                    dispatcher(new PageLoaded
                    {
                        Page       = response.Data.Page,
                        TotalPages = response.Data.TotalPages,
                        NewPage    = response.Data.Results
                    });

                    return;
                }

                dispatcher(new FailedToLoadPage
                {
                    Exception = response.ErrorException
                });
            });
        }
        public DataActionCreator(ITMDBService tmdbService, IAppStoreContainer storeContainer)
        {
            TMDBService = tmdbService;
            Store       = storeContainer.Store;

            LoadGenresAction = async(dispatcher, getState) =>
            {
                var response = await TMDBService.GetGenres();

                if (!response.IsSuccessful)
                {
                    dispatcher(new GenresLoaded());
                    return;
                }

                dispatcher(new GenresLoaded
                {
                    Genres = response.Data.Genres
                });
            };

            LoadProileAction = async(dispatcher, getState) =>
            {
                var response = await TMDBService.GetProfile();

                dispatcher(new StartLoadingProfile());

                if (!response.IsSuccessful)
                {
                    dispatcher(new FailedLoadProfile
                    {
                        Exception = new Exception("Failed to load profile")
                    });

                    return;
                }

                dispatcher(new ProfileLoaded
                {
                    Profile = response.Data
                });
            };
        }
        public ReviewActionCreator(ITMDBService tmdbService, IAppStoreContainer storeContainer)
        {
            TMDBService = tmdbService;
            Store       = storeContainer.Store;

            LoadReviewsAction = Store.CreateAsyncActionVoid <int>(async(dispatcher, getState, movieId) =>
            {
                var state = getState().ReviewsState;

                if (state.TotalPages != 0 && state.LastLoadedPage == state.TotalPages && state.MovieId == movieId)
                {
                    return;
                }

                dispatcher(new StartLoadingReviews
                {
                    MovieId = movieId
                });

                var response = await TMDBService.GetReviews(movieId, ++state.LastLoadedPage);

                if (response.IsSuccessful)
                {
                    dispatcher(new ReviewsLoaded
                    {
                        Page       = response.Data.Page,
                        TotalPages = response.Data.TotalPages,
                        Result     = response.Data.Results
                    });

                    return;
                }

                dispatcher(new ReviewsLoadError
                {
                    Exception = new Exception(response.Data.StatusMessage)
                });
            });
        }
Exemple #7
0
        public DiscoverActionCreator(ITMDBService tmdbService, IAppStoreContainer storeContainer)
        {
            TMDBService = tmdbService;
            Store       = storeContainer.Store;

            LoadNextPageAction = async(dispatcher, getState) =>
            {
                var state = getState().DiscoverState;

                if (state.TotalPages != 0 && state.LastLoadedPage == state.TotalPages)
                {
                    return;
                }

                dispatcher(new StartLoadingDiscoverPage());

                var response = await TMDBService.Discover(++state.LastLoadedPage);

                if (response.IsSuccessful)
                {
                    dispatcher(new DiscoverPageLoaded
                    {
                        Page       = response.Data.Page,
                        TotalPages = response.Data.TotalPages,
                        NewPage    = response.Data.Results
                    });

                    return;
                }

                dispatcher(new FailedToLoadDiscoverPage
                {
                    Exception = response.ErrorException
                });
            };
        }
Exemple #8
0
        public FavoriteActionCreator(ITMDBService tmdbService, IAppStoreContainer storeContainer)
        {
            TMDBService = tmdbService;
            Store       = storeContainer.Store;

            LoadNextPageAction = async(dispatcher, getState) =>
            {
                var state = getState().FavoriteState;

                if (state.TotalPages != 0 && state.LastLoadedPage == state.TotalPages)
                {
                    return;
                }

                dispatcher(new StartLoadingFavouritePage());

                var response = await TMDBService.GetFavoriteMovies(++state.LastLoadedPage);

                if (response.IsSuccessful)
                {
                    dispatcher(new FavouritePageLoaded
                    {
                        Page       = response.Data.Page,
                        TotalPages = response.Data.TotalPages,
                        NewPage    = response.Data.Results
                    });

                    return;
                }

                dispatcher(new FailedToLoadFavouritePage
                {
                    Exception = new System.Exception(response.Data.StatusMessage)
                });
            };
        }
Exemple #9
0
        public static async Task <TMDBSnapshot> CollectDataAsync(ITMDBService tmdbService, ILogger logger, string languageCode, string regionCode)
        {
            logger.LogInformation($"DataCollector collecting data for language \"{languageCode}\" started at: {DateTime.Now}");

            var tmdbSnapshot = new TMDBSnapshot
            {
                LanguageCode = languageCode,
                RegionCode   = regionCode
            };

            tmdbSnapshot.Configuration         = tmdbService.Configuration;
            tmdbSnapshot.ShowGenres            = (await tmdbService.GetShowGenresAsync(languageCode)).Values.ToList();
            tmdbSnapshot.MovieGenres           = (await tmdbService.GetMovieGenresAsync(languageCode)).Values.ToList();
            tmdbSnapshot.PopularShowsAndMovies = await tmdbService.GetPopularShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.ComedyShowsAndMovies = await tmdbService.GetComedyShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.DramaShowsAndMovies = await tmdbService.GetDramaShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.ActionAdventureShowsAndMovies = await tmdbService.GetActionAndAdventureShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.AnimationShowsAndMovies = await tmdbService.GetAnimationShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.ScifiShowsAndMovies = await tmdbService.GetScifiShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.CrimeShowsAndMovies = await tmdbService.GetCrimeShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.MysteryShowsAndMovies = await tmdbService.GetMysteryShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.ThrillerShowsAndMovies = await tmdbService.GetThrillerShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.HorrorShowsAndMovies = await tmdbService.GetHorrorShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.FamilyShowsAndMovies = await tmdbService.GetFamilyShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.KidsShowsAndMovies = await tmdbService.GetKidsShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.WesternShowsAndMovies = await tmdbService.GetWesternShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.FantasyMovies = await tmdbService.GetFantasyMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.HistoryShowsAndMovies = await tmdbService.GetHistoryShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.RomanceShowsAndMovies = await tmdbService.GetHistoryShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.WarShowsAndMovies = await tmdbService.GetWarShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.DocumentaryShowsAndMovies = await tmdbService.GetDocumentaryShowsAndMovies(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.SitcomShows = await tmdbService.GetSitcomShowsAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.AnthologyShows = await tmdbService.GetAnthologyShowsAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.AnimeShowsAndMovies = await tmdbService.GetAnimeShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.TeenDramaShowsAndMovies = await tmdbService.GetTeenDramaShowsAndMoviesAsync(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.HistoricalDramaShowsAndMovies = await tmdbService.GetHistoricalDramaShowsAndMovies(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.WorkplaceComedyShowsAndMovies = await tmdbService.GetWorkplaceComedyShowsAndMovies(languageCode, regionCode, NUMBER_OF_PAGES);

            tmdbSnapshot.MedicalDramaShowsAndMovies = await tmdbService.GetMedicalDramaShowsAndMovies(languageCode, regionCode, NUMBER_OF_PAGES);

            CollectionFilter.FilterCollections(tmdbSnapshot, logger);
            CreateRandomizedJSONCollection(tmdbSnapshot, logger);

            logger.LogInformation($"DataCollector collecting data for language \"{languageCode}\" finished at: {DateTime.Now}");
            return(tmdbSnapshot);
        }
        public MovieDetailActionCreator(ITMDBService tmdbService, IAppStoreContainer storeContainer)
        {
            TMDBService = tmdbService;
            Store       = storeContainer.Store;

            FavoriteMovieAction = Store.CreateAsyncActionVoid <FavoriteMovieArgs>(async(dispatcher, getState, args) =>
            {
                dispatcher(new UpdateAccountState
                {
                    IsFavorite = args.IsFavorite
                });

                var response = await TMDBService.FavoriteMovie(args.IsFavorite, args.MovieId);

                if (!response.IsSuccessful)
                {
                    return;
                }

                dispatcher(new ReloadFavoritesAction());
            });

            RateMovieAction = Store.CreateAsyncActionVoid <RateMovieArgs>(async(dispatcher, getState, args) =>
            {
                dispatcher(new UpdateAccountState
                {
                    Rate = args.Rate
                });

                var response = await TMDBService.RateMovie(args.Rate, args.MovieId);
            });

            LoadMovieDetailsAction = Store.CreateAsyncActionVoid <int>(async(dispatcher, getState, movieId) =>
            {
                if (string.IsNullOrEmpty(getState().AuthenticationState.SessionId))
                {
                    return;
                }

                var cancellationToken = new CancellationTokenSource();

                dispatcher(new StartLoadingMovieDetailts
                {
                    MovieId           = movieId,
                    CancellationToken = cancellationToken
                });


                // null in case of failure, don't really care about excec errors handling here

                var loadTask = Task.Factory.StartNew(async() =>
                {
                    var response = await TMDBService.AccountStateForMovie(movieId);

                    dispatcher(new MovieAccountStateLoaded
                    {
                        AccountState = response.Data
                    });
                }, cancellationToken.Token);

                try
                {
                    await loadTask;
                }
                catch (TaskCanceledException)
                {
                    // nothing to do here, user has chonsen another movie
                }
            });
        }
 public MovieController(UserManager <ApplicationUser> userManager, IMovieService service, ITMDBService tmdbService, IWishService wishService) : base(userManager)
 {
     _service     = service;
     _tmdbService = tmdbService;
     _wishService = wishService;
 }