Beispiel #1
0
        private void TestRelation(int numSongs, float ratingRelation, PlaylistBase randomSource,
                                  int firstRating, int secondRating)
        {
            var list = new List <Song>();

            float lower = ratingRelation - 0.20f;
            float upper = ratingRelation + 0.20f;

            for (int run = 0; run < 100; run++)
            {
                for (int i = 0; i < numSongs; i++)
                {
                    list.Add(randomSource.GetRandom(true));
                }

                int c1 = list.Where(s => s.Rating == firstRating).Count();
                int c2 = list.Where(s => s.Rating == secondRating).Count();

                if (!(c1 > c2 * lower && c1 < c2 * upper))
                {
                    Assert.Fail();
                }

                list.Clear();
            }
        }
Beispiel #2
0
        //private PlaylistBaseViewModel<PlaylistBase> CreatePlaylistViewModel(PlaylistBase playlistBase)
        private PlaylistBaseViewModel CreatePlaylistViewModel(PlaylistBase playlistBase, FolderPlaylistViewModel parentFolderPlaylistViewModel)
        {
            switch (playlistBase)
            {
            case SimplePlaylist simplePlaylist:
                return(new SimplePlaylistViewModel(
                           this._audioPlaybackEngine,
                           //this._readLibraryService,
                           this._writeLibraryService,
                           this._dialogService,
                           parentFolderPlaylistViewModel,
                           this.TrackViewModelsChangeSets,
                           simplePlaylist)
                       //as PlaylistBaseViewModel<PlaylistBase>
                       );

            case FolderPlaylist folderPlaylist:
                return(new FolderPlaylistViewModel(
                           this._audioPlaybackEngine,
                           //this._readLibraryService,
                           this._writeLibraryService,
                           this._dialogService,
                           parentFolderPlaylistViewModel,
                           this.TrackViewModelsChangeSets,
                           folderPlaylist,
                           this.CreatePlaylistViewModel)
                       //as PlaylistBaseViewModel<PlaylistBase>
                       );

            default:
                throw new NotSupportedException(playlistBase.GetType().FullName + " is not a supported " + nameof(PlaylistBase) + " implementation.");
            }
        }
        protected void PrepareState(NavigationContext navigationContext, bool push)
        {
            UpdateProperties();
            Guid workflowStateId = navigationContext.WorkflowState.StateId;

            if (workflowStateId == Consts.WF_STATE_ID_PLAYLISTS_OVERVIEW)
            {
                ClearData();
                UpdatePlaylists(true);
            }
            if (workflowStateId == Consts.WF_STATE_ID_PLAYLISTS_REMOVE)
            {
                UpdatePlaylists(true);
            }
            else if (workflowStateId == Consts.WF_STATE_ID_PLAYLIST_INFO)
            {
                _playlist = GetCurrentPlaylist(navigationContext);
            }
            if (!push)
            {
                return;
            }
            if (workflowStateId == Consts.WF_STATE_ID_PLAYLIST_SAVE_EDIT_NAME)
            {
                _playlist = GetCurrentPlaylist(navigationContext);
            }
            else if (workflowStateId == Consts.WF_STATE_ID_PLAYLIST_SAVE_SUCCESSFUL)
            {
                // Nothing to do
            }
            else if (workflowStateId == Consts.WF_STATE_ID_PLAYLIST_SAVE_FAILED)
            {
                _message = GetMessage(navigationContext);
            }
        }
Beispiel #4
0
        public PlaylistBase ToFolderPlaylist(
            Func <uint> newPlaylistIdGenerator,
            uint?parentPlaylistId,
            ITracksRepository tracksRepository,
            IEnumerable <iTunesPlaylist> iTunesPlaylists,
            IReadOnlyDictionary <uint, Track> tracksMapper)
        {
            PlaylistBase playlist = null;

            try
            {
                var playlistId = newPlaylistIdGenerator.Invoke();
                var playlists  =
                    iTunesPlaylists == null
                    ? ImmutableList <PlaylistBase> .Empty
                    : iTunesPlaylists
                    .Where(x => x.Parent_Persistent_ID == this.Playlist_Persistent_ID)
                    .Select(x => x.ToPlaylist(newPlaylistIdGenerator, playlistId, tracksRepository, iTunesPlaylists, tracksMapper))
                    .RemoveNulls()
                    .ToImmutableList();

                playlist = new FolderPlaylist(
                    playlistId,
                    // library entry
                    parentPlaylistId,
                    this.Name,
                    playlists);
            }
            catch //(Exception ex)
            {
                playlist = null;
            }

            return(playlist);
        }
        protected void UpdatePlaylists(ItemsList list, List <PlaylistBase> playlistsData, bool selectFirstItem)
        {
            list.Clear();
            bool selectPlaylist = selectFirstItem;

            playlistsData.Sort((a, b) => a.Name.CompareTo(b.Name));
            foreach (PlaylistBase playlistData in playlistsData)
            {
                AVType?avType = ConvertPlaylistTypeToAVType(playlistData.PlaylistType);
                if (!avType.HasValue)
                {
                    continue;
                }
                ListItem playlistItem = new ListItem(Consts.KEY_NAME, playlistData.Name);
                playlistItem.AdditionalProperties[Consts.KEY_PLAYLIST_AV_TYPE]   = avType.Value;
                playlistItem.AdditionalProperties[Consts.KEY_PLAYLIST_NUM_ITEMS] = playlistData.NumItems;
                playlistItem.AdditionalProperties[Consts.KEY_PLAYLIST_DATA]      = playlistData;
                PlaylistBase plCopy = playlistData;
                playlistItem.Command = new MethodDelegateCommand(() => ShowPlaylistInfo(plCopy));
                if (selectPlaylist)
                {
                    selectPlaylist        = false;
                    playlistItem.Selected = true;
                }
                playlistItem.SelectedProperty.Attach(OnPlaylistItemSelectionChanged);
                lock (_syncObj)
                    list.Add(playlistItem);
            }
            list.FireChange();
        }
Beispiel #6
0
        // TODO: handle AC/DC splitting
        //private readonly Hashtable<IReadOnlyList<string>, string>

        public PlaylistBase ToSimplePlaylist(
            Func <uint> newPlaylistIdGenerator,
            uint?parentPlaylistId,
            ITracksRepository tracksRepository,
            IReadOnlyDictionary <uint, Track> tracksMapper)
        {
            PlaylistBase playlist = null;

            try
            {
                playlist = new SimplePlaylist(
                    newPlaylistIdGenerator.Invoke(),
                    // library entry
                    parentPlaylistId,
                    this.Name,
                    tracksRepository,
                    tracksMapper == null || this.Playlist_Items == null
                        ? ImmutableList <uint> .Empty
                        : this.Playlist_Items.Select(x => tracksMapper[x].Id).ToImmutableList());
            }
            catch //(Exception ex)
            {
                playlist = null;
            }

            return(playlist);
        }
Beispiel #7
0
        private void Test()
        {
            var s10 = @"D:\music\Playlists\A.Pop.wpl";
            //var s11 = @"D:\music\Playlists\A.Pop.m3u";
            //var s12 = @"..\..\music\Ajad\Reiki Music Collection - 5CD\Ajad - Reiki Music Vol.5\\Ajad - 01 - Night of Love.mp3";
            //var s13 = @"D:\music\Ajad\Reiki Music Collection - 5CD\Ajad - Reiki Music Vol.5\\Ajad - 01 - Night of Love.mp3";

            //var s21 = s11.GetAbsolutePath(s12);
            //var s22 = s11.GetAbsolutePath(s13);

            //var s31 = s11.GetRelativePath(s12);
            //var s32 = s11.GetRelativePath(s13);


            var playlist0 = PlaylistBase.Create(s10);
            //var playlist1 = Library.FirstOrDefault(item => item.Title == "A.Pop");

            ////var s0 = Path.GetPathRoot(playlist0.PlaylistPath);
            ////var s1 = Path.GetPathRoot(playlist1.PlaylistPath);

            var t0 = playlist0.Check();

            var t1 = playlist0.Check();

            playlist0.Repair(false);
            //playlist0.SavePlaylist();

            var t2 = playlist0.Check();
        }
Beispiel #8
0
        public virtual bool Delete(PlaylistBase playlist)
        {
            var removalQuery = Query.EQ("_id", playlist.PlaylistId);

            if (userService.User.Playlists.Contains(playlist.PlaylistId))
            {
                userService.User.Playlists.Remove(playlist.PlaylistId);
            }
            if (userService.User.PrivatePlaylists.Contains(playlist.PlaylistId))
            {
                userService.User.PrivatePlaylists.Remove(playlist.PlaylistId);
            }
            if (userService.User.LikedPlaylists.Contains(playlist.PlaylistId))
            {
                userService.User.LikedPlaylists.Remove(playlist.PlaylistId);
            }

            userService.Update(userService.User);
            if (playlist.GetType() == typeof(Playlist))
            {
                return(DB.GetCollection <Playlist>("Playlist").Remove(removalQuery, SafeMode.True).Ok);
            }
            else
            {
                return(DB.GetCollection <PrivatePlaylist>("PrivatePlaylist").Remove(removalQuery, SafeMode.True).Ok);
            }
        }
Beispiel #9
0
        private async void RunPlayListItemsSaveAsync()
        {
            ToggleControls(menuItemRun);

            await PlaylistBase.SaveAllItemsAsync(AppSettings.Instance.OutputFolder, ProgressBarInit).ContinueWith((v) => ProgressBarHide());

            ToggleControls(menuItemRun);
        }
Beispiel #10
0
 public PlaylistBaseViewModel(
     IAudioPlaybackEngine audioPlaybackEngine,
     IDialogService dialogService,
     Func <Track, EditTrackTagsViewModel> editTrackViewModelFactoryMethod,
     IObservable <IChangeSet <TrackViewModel, uint> > sourceTrackViewModelsChangesFlow,
     PlaylistBase playlist)
     : base(audioPlaybackEngine, dialogService, editTrackViewModelFactoryMethod, sourceTrackViewModelsChangesFlow)
 {
     this._playlist = playlist ?? throw new ArgumentNullException(nameof(playlist));
 }
Beispiel #11
0
        public SongPropertiesWindow(MainForm mainForm, Song song, int clickedIndex, PlaylistBase currentPlaylist, Library library)
        {
            this.mainForm        = mainForm;
            this.song            = song;
            this.currentIndex    = clickedIndex;
            this.currentPlaylist = currentPlaylist;
            this.library         = library;

            InitializeComponent();
        }
Beispiel #12
0
 public PlaylistBaseViewModel(
     IAudioPlaybackEngine audioPlaybackEngine,
     IWriteLibraryService writeLibraryService,
     IDialogService dialogService,
     TracksSubsetViewModel parentTracksSubsetViewModel,
     IObservable <IChangeSet <TrackViewModel, uint> > sourceTrackViewModelsChangesFlow,
     PlaylistBase playlist)
     : base(audioPlaybackEngine, writeLibraryService, dialogService, parentTracksSubsetViewModel, sourceTrackViewModelsChangesFlow)
 {
     this._playlist = playlist ?? throw new ArgumentNullException(nameof(playlist));
 }
        public static void ShowPlaylistInfo(PlaylistBase playlistData)
        {
            IWorkflowManager workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            workflowManager.NavigatePush(Consts.WF_STATE_ID_PLAYLIST_INFO, new NavigationContextConfig
            {
                AdditionalContextVariables = new Dictionary <string, object>
                {
                    { Consts.KEY_PLAYLIST_DATA, playlistData }
                }
            });
        }
Beispiel #14
0
        private void menuItemOpenFolder_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new CommonOpenFileDialog()
            {
                IsFolderPicker   = true,
                InitialDirectory = AppSettings.Instance.MenuItemOpenFolder
            };

            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                AppSettings.Instance.MenuItemOpenFolder = dialog.FileName;
                PlaylistBase.AddItems(dialog.FileName);
            }
        }
        public MultiSongPropertiesWindow(MainForm mainForm, List <Song> songs, PlaylistBase currentPlaylist, Library library)
        {
            this.mainForm        = mainForm;
            this.songs           = songs;
            this.currentPlaylist = currentPlaylist;
            this.library         = library;
            this.saveProperties  = new Dictionary <string, bool>();
            InitializeComponent();

            save_ComboBox.SelectedIndex = 0;
            for (int i = 2; i < save_ComboBox.Items.Count; i++)
            {
                this.saveProperties.Add(save_ComboBox.Items[i].ToString(), false);
            }
        }
Beispiel #16
0
        public virtual bool Add(PlaylistBase playlist)
        {
            if (playlist.GetType() == typeof(Playlist))
            {
                try
                {
                    MongoCollection <Playlist> playlists = DB.GetCollection <Playlist>("Playlist");
                    var realPlaylist = playlist as Playlist;
                    realPlaylist.NumberOfLikes = 0;
                    playlists.Insert <Playlist>((Playlist)realPlaylist);
                    var user = userService.User;
                    user.Playlists.Add(playlist.PlaylistId);
                    return(userService.Update(user)); // treba da se proveri dal je uspesno updajtovao usera // proverava :D
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            if (playlist.GetType() == typeof(PrivatePlaylist))
            {
                try
                {
                    MongoCollection <PrivatePlaylist> privatePlaylists = DB.GetCollection <PrivatePlaylist>("PrivatePlaylist");
                    privatePlaylists.Insert <PrivatePlaylist>((PrivatePlaylist)playlist);
                    var user = userService.User;
                    user.PrivatePlaylists.Add(playlist.PlaylistId);
                    return(userService.Update(user));
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            throw new NotImplementedException();
        }
Beispiel #17
0
        public virtual bool Update(PlaylistBase playlist)
        {
            if (playlist.GetType() == typeof(Playlist))
            {
                try
                {
                    MongoCollection playlists = DB.GetCollection <Playlist>("Playlist");
                    var             query     = Query.EQ("_id", playlist.PlaylistId);
                    var             update    = MongoDB.Driver.Builders.Update.Replace <Playlist>(playlist as Playlist);
                    return(playlists.Update(query, update, UpdateFlags.None, SafeMode.True).Ok);
                }

                catch (Exception)
                {
                    return(false);
                }
            }

            if (playlist.GetType() == typeof(PrivatePlaylist))
            {
                try
                {
                    MongoCollection playlists = DB.GetCollection <PrivatePlaylist>("PrivatePlaylist");
                    var             query     = Query.EQ("_id", playlist.PlaylistId);
                    var             update    = MongoDB.Driver.Builders.Update.Replace <PrivatePlaylist>(playlist as PrivatePlaylist);
                    return(playlists.Update(query, update, UpdateFlags.None, SafeMode.True).Ok);
                }

                catch (Exception)
                {
                    return(false);
                }
            }

            throw new NotImplementedException();
        }
        public override PlaylistBase GetById(ObjectId id)
        {
            cache.As <Playlist>(); //proba najde obicnu
            Playlist pl = cache.Get <Playlist>("Playlist" + id.ToString());

            if (pl != null) //ako naso super
            {
                cache.Set <Playlist>("Playlist" + pl.PlaylistId.ToString(), pl, new TimeSpan(0, 2, 0, 0));
                return(pl); //ce obnovi i vrati
            }
            else
            {
                cache.As <PrivatePlaylist>(); //ako nije onda proba privatnu
                PrivatePlaylist pp = cache.Get <PrivatePlaylist>("PrivatePlaylist" + id.ToString());
                if (pp != null)               //ako nadje obnovi i vrati
                {
                    cache.Set <PrivatePlaylist>("PrivatePlaylist" + pp.PlaylistId.ToString(), pp, new TimeSpan(0, 2, 0, 0));
                    return(pp);
                }
            }//sad ako nijedna nije u kes
            PlaylistBase b = base.GetById(id);

            if (b.GetType() == typeof(Playlist)) //ako mongo naso obicnu
            {
                pl = (Playlist)b;
                cache.Set <Playlist>("Playlist" + pl.PlaylistId.ToString(), pl, new TimeSpan(0, 2, 0, 0));
                return(pl);                             //kesira obicnu i vrati je
            }
            if (b.GetType() == typeof(PrivatePlaylist)) //ili privatnu isto to
            {
                PrivatePlaylist pp = (PrivatePlaylist)b;
                cache.Set <PrivatePlaylist>("PrivatePlaylist" + pp.PlaylistId.ToString(), pp, new TimeSpan(0, 2, 0, 0));
                return(pp);
            }
            return(null); //ako nije naso base, tj nema takva pl. lista
        }
 public Task <PlaylistBase> AddAsync(PlaylistBase entity)
 {
     throw new NotSupportedException();
 }
Beispiel #20
0
 private void RefreshPlaylists()
 {
     PlaylistBase.Refresh();
     Binding();
 }
 public Task <PlaylistBase> AddAsync(PlaylistBase playlistBase)
 {
     return(this._serializer.AddAsync(playlistBase));
 }
Beispiel #22
0
 private void menuItemReparePreview_Click(object sender, RoutedEventArgs e)
 {
     PlaylistBase.RepairAll(true);
 }
Beispiel #23
0
 private void Cancel()
 {
     PlaylistBase.Cancel();
 }
 public Task <PlaylistBase> AddAsync(PlaylistBase entity)
 {
     throw new NotImplementedException();
 }