public void PlayListGetAll() { // Act var playLists = _repo.GetAll(); // Assert Assert.Single(playLists); }
public void AddPlaylist() { var options = new DbContextOptionsBuilder <BetterCalmContext>() .UseInMemoryDatabase(databaseName: "MSP.BetterCalmDatabase").Options; var context = new BetterCalmContext(options); context.Add(listPlaylist[0]); context.SaveChanges(); repository = new PlaylistRepository(context); var initial = repository.GetAll().Count(); repository.Add(listPlaylist[1]); var final = repository.GetAll().Count(); context.Database.EnsureDeleted(); Assert.AreEqual(initial + 1, final); }
public void DotMemoryUnitTest() { var repo = new PlaylistRepository(); repo.GetAll(); dotMemory.Check(memory => Assert.Equal(1, memory.GetObjects(where => where.Type.Is <Playlist>()).ObjectsCount)); GC.KeepAlive(repo); // prevent objects from GC if this is implied by test logic }
private void GetAll() { Console.Clear(); SongsRepository songsRepository = new SongsRepository(Properties.Settings.Default.FileSongs); UsersRepository usersRepository = new UsersRepository(Properties.Settings.Default.FileUsers); List <Playlist> playlist = _playlistRepository.GetAll(); List <Song> songs = songsRepository.GetAll(); List <User> users = usersRepository.GetAll(); foreach (Playlist playlistitem in playlist) { var owners = users.Where(x => playlistitem.UserOwnerId.Equals(x.Id)).ToList(); foreach (User ownerUser in owners) { Console.WriteLine("_______________________________________"); Console.WriteLine("\tOwner Username: "******"\tPlaylist ID : " + playlistitem.Id); Console.WriteLine("\tPlaylist Name : " + playlistitem.Name); Console.WriteLine("\tPlaylist Public : " + playlistitem.IsPublic); Console.WriteLine("_______________________________________"); var songsForThisPlayList = songs.Where(x => playlistitem.SongsIts.Contains(x.Id)).ToList(); foreach (Song songitem in songsForThisPlayList) { Console.WriteLine("---------------------------------------"); Console.WriteLine("\tSong ID : " + songitem.Id); Console.WriteLine("\tSong Name : " + songitem.ArtistName); Console.WriteLine("\tSong Title : " + songitem.Title); Console.WriteLine("\tSong Year : " + songitem.Year); } Console.WriteLine("---------------------------------------"); Console.WriteLine("\n"); } Console.ReadKey(true); }
private void ShowMy() { Console.Clear(); PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt"); List <Entity.Playlist> playlists = playlistRepository.GetAll(AuthenticationService.LoggedUser.Id); foreach (Entity.Playlist playlist in playlists) { Console.WriteLine("ID:" + playlist.Id); Console.WriteLine("Name :" + playlist.Name); Console.WriteLine("Description :" + playlist.Description); Console.WriteLine("Songs :" + playlist.Songs); Console.WriteLine("IsPublic :" + playlist.IsPublic); Console.WriteLine("------------------------------------"); } if (playlists.Count == 0) { Console.WriteLine("You don't have any playlists yet!"); } Console.ReadKey(true); }
public IEnumerable <Models.Playlist> GetAll() { return(_pr.GetAll()); }
public System.IO.Stream GetFilters(string uid) { int t = 0; int.TryParse(uid, out t); JMMUser user = t > 0 ? PlexHelper.GetJMMUser(uid) : PlexHelper.GetUser(uid); if (user == null) { return(new MemoryStream()); } int userid = user.JMMUserID; HistoryInfo info = new HistoryInfo { Key = PlexHelper.ConstructFiltersUrl(userid), Title = "Anime" }; PlexObject ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Show, info, false)); if (!ret.Init()) { return(new MemoryStream()); } List <Video> dirs = new List <Video>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { GroupFilterRepository repGF = new GroupFilterRepository(); List <GroupFilter> allGfs = repGF.GetAll(session); Dictionary <int, HashSet <int> > gstats = StatsCache.Instance.StatUserGroupFilter[userid]; foreach (GroupFilter gg in allGfs.ToArray()) { if ((!StatsCache.Instance.StatUserGroupFilter.ContainsKey(userid)) || (!StatsCache.Instance.StatUserGroupFilter[userid].ContainsKey(gg.GroupFilterID))) { allGfs.Remove(gg); } } AnimeGroupRepository repGroups = new AnimeGroupRepository(); allGfs.Insert(0, new GroupFilter() { GroupFilterName = "All", GroupFilterID = -999 }); foreach (GroupFilter gg in allGfs) { Random rnd = new Random(123456789); Directory pp = new Directory { Type = "show" }; pp.Key = PlexHelper.ConstructFilterIdUrl(userid, gg.GroupFilterID); pp.Title = gg.GroupFilterName; HashSet <int> groups; groups = gg.GroupFilterID == -999 ? new HashSet <int>(repGroups.GetAllTopLevelGroups(session).Select(a => a.AnimeGroupID)) : gstats[gg.GroupFilterID]; if (groups.Count != 0) { bool repeat; int nn = 0; pp.LeafCount = groups.Count.ToString(); pp.ViewedLeafCount = "0"; do { repeat = true; int grp = groups.ElementAt(rnd.Next(groups.Count)); AnimeGroup ag = repGroups.GetByID(grp); List <AnimeSeries> sers = ag.GetSeries(session); if (sers.Count > 0) { AnimeSeries ser = sers[rnd.Next(sers.Count)]; AniDB_Anime anim = ser.GetAnime(session); if (anim != null) { ImageDetails poster = anim.GetDefaultPosterDetailsNoBlanks(session); ImageDetails fanart = anim.GetDefaultFanartDetailsNoBlanks(session); if (poster != null) { pp.Thumb = poster.GenPoster(); } if (fanart != null) { pp.Art = fanart.GenArt(); } if (poster != null) { repeat = false; } } } nn++; if ((repeat) && (nn == 15)) { repeat = false; } } while (repeat); dirs.Add(pp, info); } } VideoLocalRepository repVids = new VideoLocalRepository(); List <VideoLocal> vids = repVids.GetVideosWithoutEpisode(); if (vids.Count > 0) { Directory pp = new Directory() { Type = "show" }; pp.Key = PlexHelper.ConstructUnsortUrl(userid); pp.Title = "Unsort"; pp.Thumb = PlexHelper.ConstructSupportImageLink("plex_unsort.png"); pp.LeafCount = vids.Count.ToString(); pp.ViewedLeafCount = "0"; dirs.Add(pp, info); } var repPlaylist = new PlaylistRepository(); var playlists = repPlaylist.GetAll(); if (playlists.Count > 0) { Directory pp = new Directory() { Type = "show" }; pp.Key = PlexHelper.ConstructPlaylistUrl(userid); pp.Title = "Playlists"; pp.Thumb = PlexHelper.ConstructSupportImageLink("plex_playlists.png"); pp.LeafCount = playlists.Count.ToString(); pp.ViewedLeafCount = "0"; dirs.Add(pp, info); } dirs = dirs.OrderBy(a => a.Title).ToList(); } ret.Childrens = dirs; return(ret.GetStream()); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return(new MemoryStream()); } }
private System.IO.Stream GetItemsFromPlaylist(int userid, string id, HistoryInfo info) { var PlaylistID = -1; int.TryParse(id, out PlaylistID); var playlistRepository = new PlaylistRepository(); var repo = new AnimeEpisodeRepository(); if (PlaylistID == 0) { using (var session = JMMService.SessionFactory.OpenSession()) { var ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Show, info, false)); if (!ret.Init()) { return(new MemoryStream()); } var retPlaylists = new List <Video>(); var playlists = playlistRepository.GetAll(); foreach (var playlist in playlists) { var dir = new Directory(); dir.Key = PlexHelper.ConstructPlaylistIdUrl(userid, playlist.PlaylistID); dir.Title = playlist.PlaylistName; var episodeID = -1; if (int.TryParse(playlist.PlaylistItems.Split('|')[0].Split(';')[1], out episodeID)) { var anime = repo.GetByID(session, episodeID).GetAnimeSeries(session).GetAnime(session); dir.Thumb = anime.GetDefaultPosterDetailsNoBlanks(session).GenPoster(); dir.Art = anime.GetDefaultFanartDetailsNoBlanks(session).GenArt(); } else { dir.Thumb = PlexHelper.ConstructSupportImageLink("plex_404V.png"); } dir.LeafCount = playlist.PlaylistItems.Split('|').Count().ToString(); dir.ViewedLeafCount = "0"; retPlaylists.Add(dir, info); } retPlaylists = retPlaylists.OrderBy(a => a.Title).ToList(); ret.Childrens = retPlaylists; return(ret.GetStream()); } } if (PlaylistID > 0) { //iOS Hack, since it uses the previous thumb, as overlay image on the episodes bool iosHack = false; if (WebOperationContext.Current != null && WebOperationContext.Current.IncomingRequest.Headers.AllKeys.Contains("X-Plex-Product")) { string kh = WebOperationContext.Current.IncomingRequest.Headers.Get("X-Plex-Product").ToUpper(); if (kh.Contains(" IOS")) { iosHack = true; } } var playlist = playlistRepository.GetByID(PlaylistID); var playlistItems = playlist.PlaylistItems.Split('|'); var vids = new List <Video>(); var ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Episode, info, true)); if (!ret.Init()) { return(new MemoryStream()); } using (var session = JMMService.SessionFactory.OpenSession()) { foreach (var item in playlistItems) { var episodeID = -1; int.TryParse(item.Split(';')[1], out episodeID); if (episodeID < 0) { return(new MemoryStream()); } var ep = repo.GetByID(session, episodeID); var v = new Video(); var locals = ep.GetVideoLocals(session); if ((locals == null) || (locals.Count == 0)) { continue; } var current = locals[0]; try { PlexHelper.PopulateVideo(v, current, JMMType.File, userid); if (!string.IsNullOrEmpty(v.Duration)) { vids.Add(v, info); if (iosHack) { v.Art = v.Thumb; v.Thumb = ret.MediaContainer.ParentThumb; } } } catch (Exception e) { //Fast fix if file do not exist, and still is in db. (Xml Serialization of video info will fail on null) } } ret.Childrens = vids; return(ret.GetStream()); } } return(new MemoryStream()); }