Exemple #1
0
        private void OnSeriesSaved(Series series)
        {
            if (mainForm.IsDisposed)
            {
                return;
            }

            if (mainForm.InvokeRequired)
            {
                mainForm.Invoke(new OnSeriesSavedResponseDelegate(OnSeriesSaved), series);
            }
            else
            {
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
                folderBrowserDialog.Description = "Please select series folder.";
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    string rootFolder = folderBrowserDialog.SelectedPath;

                    Console.WriteLine(rootFolder);

                    FilmographyToUser seriesToUser = series.ToUser;
                    seriesToUser.Path = rootFolder;

                    DbManager.Connection.Update(seriesToUser);

                    Console.WriteLine("path: " + series.ToUser.Path);
                }
                mainForm.UpdatePanel(PanelId.SavedShows, DbManager.GetSavedShows(), true);
                MessageBox.Show("Series saved: " + series.Title);
            }
        }
        internal override void UpdateView()
        {
            Series            series        = (Series)mainForm.GetPanelData(this);
            Episode           nextEpisode   = App.Instance.DbManager.GetNextEpisode(series);
            FilmographyToUser episodeToUser = nextEpisode.ToUser;

            headerPanel.UpdateView(series);

            overviewLabel.Text = series.Overview;

            nextEpisodeNumberLabel.Text =
                "S" + nextEpisode.Season.SeasonNumber + " E" + nextEpisode.EpisodeNumber
                + (!string.IsNullOrEmpty(nextEpisode.Title) ? ": " + nextEpisode.Title : "");

            watchEpisodeButton.Tag  = nextEpisode;
            watchEpisodeButton.Text = episodeToUser.SecondsWatched == 0 ?
                                      "Watch now" : "Continue from " + SystemUtils.GetTime(new TimeSpan(episodeToUser.SecondsWatched));

            Invalidate();
        }
        internal bool SaveFilmography <T>(T entity, bool newFilmographyToUser) where T : Filmography, new()
        {
            Filmography existing = null;

            FilmographyType.Value type;

            TableQuery <T> query = Connection.Table <T>().Where(f => f.TmdbId == entity.TmdbId);

            existing = query.Count() > 0 ? query.First() : null;

            if (entity is Series)
            {
                type = FilmographyType.Value.SERIES;
            }
            else if (entity is Season)
            {
                type = FilmographyType.Value.SEASON;
            }
            else if (entity is Episode)
            {
                type = FilmographyType.Value.EPISODE;
            }
            else
            {
                throw new NotSupportedException();
            }

            if (existing == null)
            {
                if (Connection.Insert(entity) == 0)
                {
                    return(false);
                }
            }
            else
            {
                entity.Id = existing.Id;
                if (Connection.Update(entity) == 0)
                {
                    return(false);
                }
            }

            if (newFilmographyToUser)
            {
                FilmographyToUser ftu = new FilmographyToUser();
                ftu.FilmographyId     = entity.GetId();
                ftu.FilmographyTypeId = (int)type;
                ftu.UserId            = App.Instance.User.GetId();
                ftu.Finished          = false;
                ftu.SecondsWatched    = 0;
                ftu.SetLastActivityDate(DateTime.Now);

                ftu.PrintValues();

                TableQuery <FilmographyToUser> ftuQuery = Connection.Table <FilmographyToUser>().Where(
                    f => f.UserId == ftu.UserId &&
                    f.FilmographyId == ftu.FilmographyId &&
                    f.FilmographyTypeId == ftu.FilmographyTypeId);

                FilmographyToUser existingFtu = ftuQuery.Count() > 0 ? ftuQuery.First() : null;

                if (existingFtu == null)
                {
                    if (Connection.Insert(ftu) == 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    ftu.Id = existingFtu.Id;
                    if (Connection.Update(ftu) == 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #4
0
        internal void WatchEpisode(Episode episode)
        {
            if (Settings.Default.OpenMediaInApp)
            {
                MediaPlayerForm mediaPLayerForm = new MediaPlayerForm();
                mediaPLayerForm.Show();
                mediaPLayerForm.UpdateView(episode);
            }
            else
            {
                string mediaPlayer = Settings.Default.ExternalMediaPlayerPath;

                if (mediaPlayer != null)
                {
                    Process.Start(mediaPlayer, "\"" + Files.GetEpisodeFile(episode) + "\"");

                    Thread.Sleep(1000);

                    switch (MessageBox.Show("Have you finished the episode?", "", MessageBoxButtons.YesNo))
                    {
                    case DialogResult.Yes:

                        // marks episode finished and sets seconds watched (not punctual)
                        FilmographyToUser toUser = episode.ToUser;
                        toUser.Finished       = true;
                        toUser.SecondsWatched = episode.Season.Series.EpisodeRunTime * 60;                                      // in seconds
                        DbManager.Connection.Update(toUser);

                        // if episode is last ine is season, marks season finished
                        if (DbManager.IsLastEpisodeInSeason(episode))
                        {
                            FilmographyToUser sToUser = episode.Season.ToUser;
                            sToUser.Finished = true;
                            DbManager.Connection.Update(sToUser);
                        }

                        // updates user statistics
                        string date = DateTime.Today.ToShortDateString();
                        TableQuery <UserStatistics> query = DbManager.Connection.Table <UserStatistics>()
                                                            .Where(us => us.UserId == User.Id && us.Date == date);
                        UserStatistics stat = query != null && query.Count() > 0 ? query.First() : null;

                        if (stat == null)
                        {
                            stat        = new UserStatistics();
                            stat.UserId = User.GetId();
                            stat.SetDate(DateTime.Today);
                            stat.TimeWatching = 0;
                        }

                        stat.TimeWatching += toUser.SecondsWatched;
                        DbManager.Connection.InsertOrReplace(stat);

                        // udpates series panel (new next episode)
                        mainForm.UpdatePanel(PanelId.Series, episode.Season.Series, true);
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Please select external media player in Settings page.");
                }
            }
        }