private void SaveLibraryMovies(IEnumerable <MediaLibraryMovie> libraryMovies) { string libraryMoviesPath = Path.Combine(_mediaPortalServices.GetTraktUserHomePath(), FileName.MediaLibraryMovies.Value); string libraryMoviesJson = JsonConvert.SerializeObject(libraryMovies); _fileOperations.FileWriteAllText(libraryMoviesPath, libraryMoviesJson, Encoding.UTF8); }
private void SaveLibraryMovies(string path, IList <MediaLibraryMovie> watchedMovies) { string libraryMoviesPath = Path.Combine(path, FileName.WatchedMovies.Value); string libraryMoviesJson = JsonConvert.SerializeObject(watchedMovies); _fileOperations.FileWriteAllText(libraryMoviesPath, libraryMoviesJson, Encoding.UTF8); }
private void SaveTraktAuthorization(ITraktAuthorization authorization, string path) { string serializedAuthorization = TraktSerializationService.SerializeAsync(authorization).Result; string authorizationFilePath = Path.Combine(path, FileName.Authorization.Value); _fileOperations.FileWriteAllText(authorizationFilePath, serializedAuthorization, Encoding.UTF8); }
private IList <EpisodeWatched> GetWatchedEpisodesFromOnlineAndSaveItToCache() { IEnumerable <ITraktWatchedShow> watchedShows = _traktClient.GetWatchedShows(); string watchedEpisodesFilePath = Path.Combine(_mediaPortalServices.GetTraktUserHomePath(), FileName.WatchedEpisodes.Value); IList <ITraktWatchedShow> traktWatchedShows = watchedShows.ToList(); string watchedEpisodesJson = TraktSerializationService.SerializeCollectionAsync(traktWatchedShows).Result; _fileOperations.FileWriteAllText(watchedEpisodesFilePath, watchedEpisodesJson, Encoding.UTF8); return(ConvertWatchedShowsToWatchedEpisodes(traktWatchedShows)); }
private void ValidateAuthorization(ITraktClient _traktClient, IFileOperations _fileOperations) { if (!_traktClient.TraktAuthorization.IsValid) { string authFilePath = Path.Combine(HomeUserPath, FileName.Authorization.Value); string savedAuthorization = _fileOperations.FileReadAllText(authFilePath); ITraktAuthorization savedAuth = TraktSerializationService.DeserializeAsync <ITraktAuthorization>(savedAuthorization).Result; if (!savedAuth.IsRefreshPossible) { throw new Exception("Saved authorization is not valid."); } ITraktAuthorization refreshedAuth = _traktClient.RefreshAuthorization(savedAuth.RefreshToken); string serializedAuth = TraktSerializationService.SerializeAsync(refreshedAuth).Result; _fileOperations.FileWriteAllText(authFilePath, serializedAuth, Encoding.UTF8); } }