public void ShouldMap()
        {
            var sessionFactory = new NHibernateConfiguration().Configure().BuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var createdUser = new User {
                        GooglePlusId = "some id?", Name = "user name"
                    };
                    session.Save(createdUser);

                    var playlist2 = new Playlist("users second playlist")
                    {
                        User     = createdUser,
                        Sequence = 200,
                    };

                    var video = new Video
                    {
                        Id             = "some id",
                        Author         = "video author",
                        Duration       = 90,
                        HighDefinition = true,
                        Title          = "my video",
                    };
                    session.Save(video);
                    var playlistItem = new PlaylistItem
                    {
                        Cid      = "cid",
                        Playlist = playlist2,
                        Video    = video,
                        Sequence = 300,
                        Title    = "My playlist item",
                    };

                    playlist2.AddItem(playlistItem);

                    session.Save(playlist2);

                    session.Flush();
                    session.Clear();

                    var savedPlaylistItem = session.Get <PlaylistItem>(playlistItem.Id);

                    Assert.That(savedPlaylistItem.Title, Is.EqualTo("My playlist item"));
                    Assert.That(savedPlaylistItem.Id, Is.Not.EqualTo(Guid.Empty));
                    Assert.That(savedPlaylistItem.Sequence, Is.EqualTo(300));

                    Assert.That(savedPlaylistItem.Video, Is.EqualTo(playlistItem.Video));

                    transaction.Rollback();
                }
            }
        }
Exemplo n.º 2
0
        internal void AddFiles(IEnumerable <string> files)
        {
            if (_abortLoad)
            {
                return;
            }

            if (files != null)
            {
                foreach (string file in files)
                {
                    if (_abortLoad)
                    {
                        break;
                    }

                    if (DvdMedia.FromPath(file) != null)
                    {
                        playlist.AddItem(file);
                    }
                    else if (File.Exists(file))
                    {
                        if (IsPlaylist(file))
                        {
                            LoadPlaylist(file, true);
                        }
                        else
                        {
                            playlist.AddItem(file);
                        }
                    }
                    else if (Directory.Exists(file))
                    {
                        AddFiles(PathUtils.EnumDirectories(file));
                        AddFiles(PathUtils.EnumFiles(file));
                    }
                    else
                    {
                        playlist.AddItem(file);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Creates a new Video and PlaylistItem, puts item in the database and then returns
        ///     the item. Just a nice utility method to keep things DRY.
        /// </summary>
        public PlaylistItem CreateItemInPlaylist(Playlist playlist)
        {
            //  Create a new PlaylistItem and write it to the database.
            var playlistItem = CreateUnsavedPlaylistItem();

            playlist.AddItem(playlistItem);

            PlaylistItemManager.Save(playlistItem);

            return(playlistItem);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Creates a new Video and PlaylistItem, puts item in the database and then returns
        ///     the item. Just a nice utility method to keep things DRY.
        /// </summary>
        public static PlaylistItem CreateItemInPlaylist(Playlist playlist)
        {
            Video videoNotInDatabase = CreateUnsavedVideoWithId();

            //  Create a new PlaylistItem and write it to the database.
            string title        = videoNotInDatabase.Title;
            var    playlistItem = new PlaylistItem(title, videoNotInDatabase);

            playlist.AddItem(playlistItem);
            PlaylistItemManager.Save(playlistItem);

            return(playlistItem);
        }
Exemplo n.º 5
0
        public IEnumerable <PlaylistItemDto> CreateMultiple(List <PlaylistItemDto> playlistItemDtos)
        {
            List <PlaylistItemDto> savedPlaylistItemDtos;

            int count = playlistItemDtos.Count;

            if (count > 1000)
            {
                Session.SetBatchSize(count / 10);
            }
            else if (count > 500)
            {
                Session.SetBatchSize(count / 5);
            }
            else if (count > 2)
            {
                Session.SetBatchSize(count / 2);
            }

            using (ITransaction transaction = Session.BeginTransaction())
            {
                List <PlaylistItem> savedPlaylistItems = new List <PlaylistItem>();

                //  Split items into their respective playlists and then save on each.
                foreach (var playlistGrouping in playlistItemDtos.GroupBy(pid => pid.PlaylistId))
                {
                    List <PlaylistItemDto> groupedPlaylistItemDtos = playlistGrouping.ToList();
                    Playlist playlist = PlaylistManager.Get(playlistGrouping.Key);

                    foreach (var playlistItemDto in groupedPlaylistItemDtos)
                    {
                        SongDto songDto = playlistItemDto.Song;

                        PlaylistItem playlistItem = new PlaylistItem(playlistItemDto.Id, playlistItemDto.Title, playlistItemDto.Cid, songDto.Id, songDto.Type, songDto.Title, songDto.Duration, songDto.Author);
                        playlistItemDto.SetPatchableProperties(playlistItem);

                        playlist.AddItem(playlistItem);

                        savedPlaylistItems.Add(playlistItem);
                    }
                }

                PlaylistItemManager.Save(savedPlaylistItems);

                savedPlaylistItemDtos = PlaylistItemDto.Create(savedPlaylistItems);

                transaction.Commit();
            }

            return(savedPlaylistItemDtos);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Creates a new Video and PlaylistItem, puts item in the database and then returns
        ///     the item. Just a nice utility method to keep things DRY.
        /// </summary>
        public static PlaylistItem CreateItemInPlaylist(Playlist playlist)
        {
            Video videoNotInDatabase = CreateUnsavedVideoWithId();

            //  Create a new PlaylistItem and write it to the database.
            string title        = videoNotInDatabase.Title;
            var    playlistItem = new PlaylistItem(title, videoNotInDatabase);

            playlist.AddItem(playlistItem);

            NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction();
            PlaylistItemManager.Save(playlistItem);
            NHibernateSessionManager.Instance.CommitTransactionAndCloseSession();

            return(playlistItem);
        }
        public void ShouldMap()
        {
            var sessionFactory = new NHibernateConfiguration().Configure().BuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var createdUser = new User {
                        GooglePlusId = "some id?", Name = "user name"
                    };

                    session.Save(createdUser);

                    var playlist2 = new Playlist("users second playlist")
                    {
                        User     = createdUser,
                        Sequence = 200,
                    };

                    var playlistItem = new PlaylistItem
                    {
                        Cid      = "cid",
                        Playlist = playlist2,
                        Video    = new Video(),
                        Sequence = 200,
                    };

                    playlist2.AddItem(playlistItem);

                    var playlistId = session.Save(playlist2);

                    session.Flush();
                    session.Clear();

                    var savedPlaylist = session.Get <Playlist>(playlistId);

                    Assert.That(savedPlaylist.Title, Is.EqualTo("users second playlist"));
                    Assert.That(savedPlaylist.Id, Is.Not.EqualTo(Guid.Empty));
                    Assert.That(savedPlaylist.Sequence, Is.EqualTo(200));

                    Assert.That(savedPlaylist.Items, Has.Exactly(1).EqualTo(playlistItem));

                    transaction.Rollback();
                }
            }
        }
        public void ShouldMap()
        {
            using (var transaction = Session.BeginTransaction())
            {
                var createdUser = new User
                {
                    GooglePlusId = "some id?"
                };
                Session.Save(createdUser);

                var playlist2 = new Playlist("users second playlist")
                {
                    User     = createdUser,
                    Sequence = 200,
                };

                var playlistItem = new PlaylistItem
                {
                    Playlist = playlist2,
                    SongId   = "some id",
                    Author   = "author",
                    Duration = 90,
                    Sequence = 300,
                    Title    = "My playlist item",
                };

                playlist2.AddItem(playlistItem);

                Session.Save(playlist2);

                Session.Flush();
                Session.Clear();

                var savedPlaylistItem = Session.Get <PlaylistItem>(playlistItem.Id);

                Assert.That(savedPlaylistItem.Title, Is.EqualTo("My playlist item"));
                Assert.That(savedPlaylistItem.Id, Is.Not.EqualTo(Guid.Empty));
                Assert.That(savedPlaylistItem.Sequence, Is.EqualTo(300));

                transaction.Rollback();
            }
        }
Exemplo n.º 9
0
        public void ShouldMap()
        {
            using (var transaction = Session.BeginTransaction())
            {
                var createdUser = new User
                {
                    GooglePlusId = "some id?"
                };

                Session.Save(createdUser);

                var playlist2 = new Playlist("users second playlist")
                {
                    User     = createdUser,
                    Sequence = 200,
                };

                var playlistItem = new PlaylistItem
                {
                    Playlist = playlist2,
                    Sequence = 200,
                };

                playlist2.AddItem(playlistItem);

                var playlistId = Session.Save(playlist2);

                Session.Flush();
                Session.Clear();

                var savedPlaylist = Session.Get <Playlist>(playlistId);

                Assert.That(savedPlaylist.Title, Is.EqualTo("users second playlist"));
                Assert.That(savedPlaylist.Id, Is.Not.EqualTo(Guid.Empty));
                Assert.That(savedPlaylist.Sequence, Is.EqualTo(200));

                Assert.That(savedPlaylist.Items, Has.Exactly(1).EqualTo(playlistItem));

                transaction.Rollback();
            }
        }
Exemplo n.º 10
0
        public R <Playlist> GetPlaylist(string url)
        {
            var    uri = new Uri($"https://api.soundcloud.com/resolve.json?url={Uri.EscapeUriString(url)}&client_id={soundcloudClientId}");
            string jsonResponse;

            if (!WebWrapper.DownloadString(out jsonResponse, uri))
            {
                return(RResultCode.ScInvalidLink.ToString());
            }

            var parsedDict = ParseJson(jsonResponse);

            if (parsedDict == null)
            {
                return("Empty or missing response parts (parsedDict)");
            }

            string name  = PlaylistManager.CleanseName(parsedDict["title"] as string);
            var    plist = new Playlist(name);

            var tracks = parsedDict["tracks"] as object[];

            if (tracks == null)
            {
                return("Empty or missing response parts (tracks)");
            }

            foreach (var track in tracks.OfType <Dictionary <string, object> >())
            {
                var resource = ParseDictToResource(track);
                if (resource == null)
                {
                    continue;
                }

                plist.AddItem(new PlaylistItem(resource));
            }

            return(plist);
        }
Exemplo n.º 11
0
        public R <Playlist, LocalStr> GetPlaylist(string url)
        {
            var uri = new Uri($"https://api.soundcloud.com/resolve.json?url={Uri.EscapeUriString(url)}&client_id={SoundcloudClientId}");

            if (!WebWrapper.DownloadString(out string jsonResponse, uri))             // todo: a bit janky (no response <-> error response)
            {
                return(new LocalStr(strings.error_net_no_connection));
            }

            var parsedDict = ParseJson(jsonResponse);

            if (parsedDict == null)
            {
                return(new LocalStr(strings.error_media_internal_missing + " (parsedDict)"));
            }

            string name  = PlaylistManager.CleanseName(parsedDict.TryCast <string>("title").OkOr(null));
            var    plist = new Playlist(name);

            var tracksJobj = parsedDict["tracks"];

            if (tracksJobj == null)
            {
                return(new LocalStr(strings.error_media_internal_missing + "(tracks)"));
            }

            foreach (var track in tracksJobj)
            {
                var resource = ParseJObjectToResource(track);
                if (resource == null)
                {
                    continue;
                }

                plist.AddItem(new PlaylistItem(resource));
            }

            return(plist);
        }
Exemplo n.º 12
0
 private void BoutonValider_Click(object sender, RoutedEventArgs e)
 {
     this.LabelWarningPlaylist.Visibility  = System.Windows.Visibility.Hidden;
     this.LabelWarningIncorrect.Visibility = System.Windows.Visibility.Hidden;
     this.LabelWarningEmpty.Visibility     = System.Windows.Visibility.Hidden;
     this.LabelWarningUsed.Visibility      = System.Windows.Visibility.Hidden;
     if (this.ParentWindow.PlaylistBox.Items.Count <= 0)
     {
         this.LabelWarningPlaylist.Visibility = System.Windows.Visibility.Visible;
     }
     else if (TextBoxAdd.Text == "")
     {
         this.LabelWarningEmpty.Visibility = System.Windows.Visibility.Visible;
     }
     else if (ParentWindow.lib_.Playlists.Find(x => x.Name == TextBoxAdd.Text) != null)
     {
         this.LabelWarningUsed.Visibility = System.Windows.Visibility.Visible;
     }
     else if (TextBoxAdd.Text.Where(c => System.IO.Path.GetInvalidFileNameChars().Contains(c)).Count() > 0)
     {
         this.LabelWarningIncorrect.Visibility = System.Windows.Visibility.Visible;
     }
     else
     {
         Playlist actual = new Playlist();
         foreach (var item in this.ParentWindow.PlaylistBox.Items)
         {
             actual.AddItem((MediaItem)((MediaItem)item).Clone());
         }
         actual.Name = TextBoxAdd.Text;
         actual.SaveToFile();
         lock (ParentWindow.lib_.Playlists)
         {
             ParentWindow.lib_.Playlists.Add(actual);
             ParentWindow.MainBox.ItemsSource = new PlaylistIterator(ParentWindow.lib_);
         }
         this.Close();
     }
 }
Exemplo n.º 13
0
        public PlaylistItemDto Create(PlaylistItemDto playlistItemDto)
        {
            PlaylistItemDto savedPlaylistItemDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                Playlist playlist = PlaylistManager.Get(playlistItemDto.PlaylistId);

                SongDto songDto = playlistItemDto.Song;

                PlaylistItem playlistItem = new PlaylistItem(playlistItemDto.Id, playlistItemDto.Title, playlistItemDto.Cid, songDto.Id, songDto.Type, songDto.Title, songDto.Duration, songDto.Author);
                playlistItemDto.SetPatchableProperties(playlistItem);

                playlist.AddItem(playlistItem);

                PlaylistItemManager.Save(playlistItem);

                savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

                transaction.Commit();
            }

            return(savedPlaylistItemDto);
        }
        public void NextItem_ShouldReturnItemsInOrderWhenRandomIsOff()
        {
            _playlist.AddItem(new FileInfo(GetFilePath("short")), -1);
            _playlist.AddItem(new FileInfo(GetFilePath("dragonborn")), -1);
            _playlist.AddItem(new FileInfo(GetFilePath("gamesofthrone")), -1);

            Assert.IsTrue(_playlist.NextItem.AudioFile.Name.Contains("short.mp3"));
            Assert.IsTrue(_playlist.NextItem.AudioFile.Name.Contains("dragonborn.mp3"));
            Assert.IsTrue(_playlist.NextItem.AudioFile.Name.Contains("gamesofthrone.mp3"));
            Assert.AreSame(null, _playlist.NextItem);
            Assert.IsTrue(_playlist.Ended);
        }