Esempio n. 1
0
        public Model.Video Next()
        {
            if (Videos.Count() == 0)
            {
                return(null);
            }

            ++_CurrentIndex;
            _CurrentIndex %= Videos.Count();

            return(Videos[_CurrentIndex]);
        }
Esempio n. 2
0
        public Model.Video Prev()
        {
            if (Videos.Count() == 0)
            {
                return(null);
            }

            if (_CurrentIndex > 0)
            {
                --_CurrentIndex;
            }
            else
            {
                _CurrentIndex = Videos.Count() - 1;
            }

            return(Videos[_CurrentIndex]);
        }
        private async void UpdateDescriptions_Click(object sender, EventArgs e)
        {
            UpdateDescriptions.Enabled = false;
            var transforms = Transformations.Select(x => new TrackedTransformation
            {
                Method = x
            }).ToArray();
            int  updatedVideos = 0;
            int  softError     = 0;
            int  index         = 0;
            bool hardError     = false;
            int  updatable     = Videos.Count(x => x.DiscriptionChanged);

            foreach (var video in Videos)
            {
                index++;
                if (!video.DiscriptionChanged)
                {
                    continue;
                }

                try
                {
                    updatedVideos++;
                    await Uploads.UpdateDescription(video.Video, video.DisplayDescription);
                }
                catch (Exception ex)
                {
                    LogMessage(ex.ToString());
                    if (ex is Google.GoogleApiException gEx)
                    {
                        LogMessage($"{gEx.Error} on video: {video.Video.Snippet.Title} ({video.Video.Id})");

                        if (gEx.Error.Code == 400)
                        {
                            softError++;
                        }
                        else
                        {
                            hardError = true;
                            break;
                        }
                    }
                }

                UpdateProgress.Value = (int)(((double)index / Videos.Count) * 100);
                ProgressText.Text    = $"{index}/{Videos.Count} Videos Checked. {updatedVideos}/{updatable} Updated. {softError} Issues detected.";
            }

            UpdateProgress.Value = 100;
            if (!hardError)
            {
                ProgressText.Text = $"{Videos.Count}/{Videos.Count} Videos Checked. {updatedVideos}/{updatable} Updated. {softError} Issues detected.";
            }
            else
            {
                ProgressText.Text = $"{Videos.Count}/{Videos.Count} Videos Checked. {updatedVideos}/{updatable} Updated. {softError} Issues detected. Fatal Error Encountered.";
            }
            var response = $"Updated {updatedVideos} videos\r\n";

            foreach (var transform in transforms)
            {
                if (transform.Method.Method == AdditionalMethods.StringTransformation.TransformationMethod.Replace)
                {
                    response += $"Replaced {transform.TransformCount} occurrences of {transform.Method.PrimaryValue} with {transform.Method.SecondaryValue}\r\n";
                }
                else if (transform.Method.Method == AdditionalMethods.StringTransformation.TransformationMethod.Remove)
                {
                    response += $"Removed {transform.TransformCount} occurrences of {transform.Method.PrimaryValue}\r\n";
                }
            }

            VideoInformation.Text = NewLineFix(string.Join("\r\n----------\r\n", Videos.Select(x => $"Title: {x.Video.Snippet.Title} ({x.Video.Id})\r\n----------\r\n{x.DisplayDescription}")));
            LogMessage("Descriptions update.");
            LogMessage(response);
            UpdateDescriptions.Enabled = true;
            BackupVideos("Update");
        }
    static void Main(string[] args)
    {
        var context = new VidzyContext();

        //Action movies sorted by name
        var moviesNameSortedQuery = context.Videos
                                    .Where(v => v.Genre.Name == "Action")
                                    .OrderBy(v => v.Name)
                                    .Select(v => new { MovieName = v.Name });

        foreach (var m in moviesNameSortedQuery)
        {
            Console.WriteLine(m.MovieName);
        }

        Console.WriteLine("=======分割线=======");

        //Gold drama movies sorted by release date (newest first)
        var goldDramaQuery = context.Videos
                             .Where(v => v.Classification == Classification.Gold && v.Genre.Name == "Drama")
                             .OrderByDescending(v => v.ReleaseDate)
                             .Select(v => new { MovieName = v.Name });

        foreach (var g in goldDramaQuery)
        {
            Console.WriteLine(g.MovieName);
        }


        Console.WriteLine("=======分割线=======");

        //All movies projected into an anonymous type with two properties: MovieName and Genre
        var projectedQuery = context.Videos
                             .Select(v => new { MovieName = v.Name, Genre = v.Genre.Name });

        foreach (var p in projectedQuery)
        {
            Console.WriteLine(p.MovieName);
        }

        Console.WriteLine("=======分割线=======");

        //All movies grouped by their classification
        var groupedClassificationQuery = context.Videos
                                         .GroupBy(v => v.Classification)
                                         .Select(g => new { Classification = g.Key.ToString(), Movies = g.OrderBy(v => v.Name) });

        foreach (var g in groupedClassificationQuery)
        {
            Console.WriteLine(g.Classification);
            foreach (var v in g.Movies)
            {
                Console.WriteLine("\t" + v.Name);
            }
        }

        Console.WriteLine("=======分割线=======");

        //List of classifications sorted alphabetically and count of videos in them
        var classificationsQuery = context.Videos
                                   .GroupBy(v => v.Classification)
                                   .Select(g => new { Classification = g.Key.ToString(), Count = g.Count() })
                                   .OrderBy(g => g.Classification);

        foreach (var g in classificationsQuery)
        {
            Console.WriteLine(g.Classification + " " + g.Count);
        }
        Console.WriteLine("=======分割线=======");

        //List of genres and number of videos they include, sorted by the numberof videos
        var genresNumberQuery = context.Genres
                                .GroupJoin(context.Videos,
                                           g => g.Id,
                                           c => c.GenreId,
                                           (Genre, Videos) => new { GenresName = Genre.Name, Count = Videos.Count() })
                                .OrderByDescending(g => g.Count);

        foreach (var g in genresNumberQuery)
        {
            Console.WriteLine("{0} ({1})", g.GenresName, g.Count);
        }

        Console.ReadLine();
    }
 public void UpdateDescriptionTextChange()
 {
     UpdateDescriptions.Text    = $"Update {Videos.Count(x => x.DiscriptionChanged)} Videos";
     UpdateDescriptions.Enabled = true;
 }