Exemple #1
0
        private bool CanUseEpisode(PlaylistVM pl, AnimeEpisodeVM ep)
        {
            if (ep.Watched && pl.PlayWatchedBool && ep.HasFiles)
            {
                return(true);
            }

            if (!ep.Watched && pl.PlayUnwatchedBool && ep.HasFiles)
            {
                return(true);
            }

            return(false);
        }
Exemple #2
0
        private void CommandBinding_DeletePlaylistItem(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                PlaylistItemVM pli = e.Parameter as PlaylistItemVM;
                if (pli == null) return;

                this.Cursor = Cursors.Wait;

                // get the playlist
                JMMServerBinary.Contract_Playlist plContract = JMMServerVM.Instance.clientBinaryHTTP.GetPlaylist(pli.PlaylistID);
                if (plContract == null)
                {
                    this.Cursor = Cursors.Arrow;
                    MessageBox.Show(JMMClient.Properties.Resources.Filter_PlaylistMissing, JMMClient.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                PlaylistVM pl = new PlaylistVM(plContract);

                if (pli.ItemType == PlaylistItemType.AnimeSeries)
                {
                    AnimeSeriesVM ser = pli.PlaylistItem as AnimeSeriesVM;
                    pl.RemoveSeries(ser.AnimeSeriesID.Value);
                }
                if (pli.ItemType == PlaylistItemType.Episode)
                {
                    AnimeEpisodeVM ep = pli.PlaylistItem as AnimeEpisodeVM;
                    pl.RemoveEpisode(ep.AnimeEpisodeID);
                }

                pl.Save();
                plContract = JMMServerVM.Instance.clientBinaryHTTP.GetPlaylist(pli.PlaylistID);

                // refresh data
                if (lbPlaylists.Items.Count > 0)
                {
                    // get the current playlist
                    PlaylistVM selPL = lbPlaylists.SelectedItem as PlaylistVM;
                    if (selPL != null && plContract != null && selPL.PlaylistID == plContract.PlaylistID)
                    {
                        selPL.Populate(plContract);
                        selPL.PopulatePlaylistObjects();
                        PlaylistHelperVM.Instance.OnPlaylistModified(new PlaylistModifiedEventArgs(plContract.PlaylistID.Value));
                    }
                    else
                    {
                        PlaylistHelperVM.Instance.RefreshData();
                    }
                }

                this.Cursor = Cursors.Arrow;
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                Utils.ShowErrorMessage(ex);
            }
        }
        void playlistMenuItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MenuItem item = e.Source as MenuItem;
                MenuItem itemSender = sender as MenuItem;

                if (item == null || itemSender == null) return;
                if (!item.Header.ToString().Equals(itemSender.Header.ToString())) return;

                if (item != null && item.CommandParameter != null)
                {
                    PlaylistMenuCommand cmd = item.CommandParameter as PlaylistMenuCommand;
                    Debug.Write("Playlist Menu: " + cmd.ToString() + Environment.NewLine);

                    AnimeSeriesVM ser = this.DataContext as AnimeSeriesVM;
                    if (ser == null) return;

                    // get the playlist
                    PlaylistVM pl = null;
                    if (cmd.PlaylistID < 0)
                    {
                        pl = PlaylistHelperVM.CreatePlaylist(Window.GetWindow(this));
                        if (pl == null) return;
                    }
                    else
                    {
                        JMMServerBinary.Contract_Playlist plContract = JMMServerVM.Instance.clientBinaryHTTP.GetPlaylist(cmd.PlaylistID);
                        if (plContract == null)
                        {
                            MessageBox.Show("Could not find playlist", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        pl = new PlaylistVM(plContract);
                    }

                    this.Cursor = Cursors.Wait;

                    // get the items to add to the playlist
                    if (cmd.AddType == PlaylistItemType.Series)
                    {
                        pl.AddSeries(ser.AnimeSeriesID.Value);
                    }
                    else
                    {
                        List<AnimeEpisodeVM> eps = ser.AllEpisodes;

                        List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                        sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeType", false, JMMClient.SortType.eInteger));
                        sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, JMMClient.SortType.eInteger));
                        sortCriteria.Add(new SortPropOrFieldAndDirection("AniDB_AirDateWithDefault", false, JMMClient.SortType.eDateTime));
                        eps = Sorting.MultiSort<AnimeEpisodeVM>(eps, sortCriteria);

                        if (cmd.AddType == PlaylistItemType.AllEpisodes)
                        {

                            foreach (AnimeEpisodeVM ep in eps)
                            {
                                if (ep.EpisodeTypeEnum == EpisodeType.Episode || ep.EpisodeTypeEnum == EpisodeType.Special)
                                    pl.AddEpisode(ep.AnimeEpisodeID);
                            }
                        }

                        if (cmd.AddType == PlaylistItemType.UnwatchedEpisodes)
                        {
                            foreach (AnimeEpisodeVM ep in eps)
                            {
                                if (!ep.Watched && (ep.EpisodeTypeEnum == EpisodeType.Episode || ep.EpisodeTypeEnum == EpisodeType.Special))
                                    pl.AddEpisode(ep.AnimeEpisodeID);
                            }
                        }
                    }

                    pl.Save();

                    PlaylistHelperVM.Instance.RefreshData();

                    this.Cursor = Cursors.Arrow;

                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        public void RefreshData()
        {
            try
            {
                IsLoadingData = true;

                // clear all displayed data
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate ()
                {
                    Playlists.Clear();
                    CurrentPlaylistObjects.Clear();

                    ViewCurrentPlaylistObjects.Refresh();
                    ViewPlaylists.Refresh();
                });

                // load the playlists
                List<JMMServerBinary.Contract_Playlist> rawPlaylists = JMMServerVM.Instance.clientBinaryHTTP.GetAllPlaylists();
                foreach (JMMServerBinary.Contract_Playlist contract in rawPlaylists)
                {
                    PlaylistVM pl = new PlaylistVM(contract);
                    Playlists.Add(pl);
                }

                IsLoadingData = false;

            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
            }
        }
        public static PlaylistVM CreatePlaylist(Window owner)
        {
            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(AppSettings.Culture);

                DialogText dlg = new DialogText();
                dlg.Init(Properties.Resources.Playlist_Name + " ", "");
                dlg.Owner = owner;
                bool? res = dlg.ShowDialog();
                if (res.HasValue && res.Value)
                {
                    if (string.IsNullOrEmpty(dlg.EnteredText))
                    {
                        Utils.ShowErrorMessage(Properties.Resources.Playlist_NameBlank);
                        return null;
                    }

                    JMMServerBinary.Contract_Playlist pl = new JMMServerBinary.Contract_Playlist();
                    pl.DefaultPlayOrder = (int)PlaylistPlayOrder.Sequential;
                    pl.PlaylistItems = "";
                    pl.PlaylistName = dlg.EnteredText;
                    pl.PlayUnwatched = 1;
                    pl.PlayWatched = 0;
                    JMMServerBinary.Contract_Playlist_SaveResponse resp = JMMServerVM.Instance.clientBinaryHTTP.SavePlaylist(pl);

                    if (!string.IsNullOrEmpty(resp.ErrorMessage))
                    {
                        Utils.ShowErrorMessage(resp.ErrorMessage);
                        return null;
                    }

                    // refresh data
                    PlaylistHelperVM.Instance.RefreshData();

                    PlaylistVM plRet = new PlaylistVM(resp.Playlist);
                    return plRet;
                }

                return null;
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
                return null;
            }
        }
        void playlistMenuItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MenuItem item = e.Source as MenuItem;
                MenuItem itemSender = sender as MenuItem;

                if (item == null || itemSender == null) return;
                if (!item.Header.ToString().Equals(itemSender.Header.ToString())) return;

                if (item != null && item.CommandParameter != null)
                {
                    PlaylistMenuCommand cmd = item.CommandParameter as PlaylistMenuCommand;
                    Debug.Write(Properties.Resources.EpisodeDetail_PlaylistMenu + cmd.ToString() + Environment.NewLine);

                    AnimeEpisodeVM ep = this.DataContext as AnimeEpisodeVM;
                    if (ep == null) return;

                    // get the playlist
                    PlaylistVM pl = null;
                    if (cmd.PlaylistID < 0)
                    {
                        pl = PlaylistHelperVM.CreatePlaylist(Window.GetWindow(this));
                        if (pl == null) return;
                    }
                    else
                    {
                        JMMServerBinary.Contract_Playlist plContract = JMMServerVM.Instance.clientBinaryHTTP.GetPlaylist(cmd.PlaylistID);
                        if (plContract == null)
                        {
                            MessageBox.Show(Properties.Resources.EpisodeDetail_PlaylistMissing, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        pl = new PlaylistVM(plContract);
                    }

                    this.Cursor = Cursors.Wait;

                    pl.AddEpisode(ep.AnimeEpisodeID);
                    pl.Save();

                    PlaylistHelperVM.Instance.RefreshData();

                    this.Cursor = Cursors.Arrow;

                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        private bool CanUseEpisode(PlaylistVM pl, AnimeEpisodeVM ep)
        {
            if (ep.Watched && pl.PlayWatchedBool && ep.HasFiles)
                return true;

            if (!ep.Watched && pl.PlayUnwatchedBool && ep.HasFiles)
                return true;

            return false;
        }
Exemple #8
0
		public static PlaylistVM CreatePlaylist(Window owner)
		{
			try
			{
				DialogText dlg = new DialogText();
				dlg.Init("Enter playlist name: ", "");
				dlg.Owner = owner;
				bool? res = dlg.ShowDialog();
				if (res.HasValue && res.Value)
				{
					if (string.IsNullOrEmpty(dlg.EnteredText))
					{
						Utils.ShowErrorMessage("Please enter a playlist name");
						return null;
					}

					JMMServerBinary.Contract_Playlist pl = new JMMServerBinary.Contract_Playlist();
					pl.DefaultPlayOrder = (int)PlaylistPlayOrder.Sequential;
					pl.PlaylistItems = "";
					pl.PlaylistName = dlg.EnteredText;
					pl.PlayUnwatched = 1;
					pl.PlayWatched = 0;
					JMMServerBinary.Contract_Playlist_SaveResponse resp = JMMServerVM.Instance.clientBinaryHTTP.SavePlaylist(pl);

					if (!string.IsNullOrEmpty(resp.ErrorMessage))
					{
						Utils.ShowErrorMessage(resp.ErrorMessage);
						return null;
					}

					// refresh data
					PlaylistHelperVM.Instance.RefreshData();

					PlaylistVM plRet = new PlaylistVM(resp.Playlist);
					return plRet;
				}

				return null;
			}
			catch (Exception ex)
			{
				Utils.ShowErrorMessage(ex);
				return null;
			}
		}