Beispiel #1
0
        public async Task RemoveMediaFromCollectionAndDatabase(IMediaItem media)
        {
            if (media is TrackItem)
            {
                var trackItem = media as TrackItem;
                var trackDB   = LoadTrackById(trackItem.Id);
                if (trackDB == null)
                {
                    return;
                }
                musicDatabase.Remove(trackDB);

                var albumDB = LoadAlbum(trackItem.AlbumId);
                if (albumDB == null)
                {
                    return;
                }
                var albumTracks = LoadTracksByAlbumId(albumDB.Id);
                if (!albumTracks.Any())
                {
                    Albums.Remove(Albums.FirstOrDefault(x => x.Id == trackItem.AlbumId));
                    musicDatabase.Remove(albumDB);
                }

                var artistDB = LoadArtist(trackItem.ArtistId);
                if (artistDB == null)
                {
                    return;
                }
                var artistAlbums = LoadAlbums(artistDB.Id);
                if (!artistAlbums.Any())
                {
                    Artists.Remove(Artists.FirstOrDefault(x => x.Id == trackItem.ArtistId));
                    musicDatabase.Remove(artistDB);
                }

                await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Tracks.Remove(Tracks.FirstOrDefault(x => x.Path == trackItem.Path));

                    var playingTrack = Locator.MediaPlaybackViewModel.PlaybackService.Playlist.FirstOrDefault(x => x.Id == trackItem.Id);
                    if (playingTrack != null)
                    {
                        Locator.MediaPlaybackViewModel.PlaybackService.Playlist.Remove(playingTrack);
                    }
                });
            }
            else if (media is VideoItem)
            {
                var videoItem = media as VideoItem;
                var videoDb   = LoadVideoById(videoItem.Id);
                if (videoDb == null)
                {
                    return;
                }
                videoDatabase.Remove(videoDb);

                Videos.Remove(Videos.FirstOrDefault(x => x.Path == videoItem.Path));
            }
        }
Beispiel #2
0
 public YTrackAlbumPair GetKey()
 {
     return(new YTrackAlbumPair {
         Id = Id,
         AlbumId = Albums?.FirstOrDefault()?.Id
     });
 }
Beispiel #3
0
        private static void Task9()
        {
            // - print the name
            //and the genre
            //of the album that has most songs

            //var songsGroupedByAlbumId = from s in Songs
            //                            join a in Albums
            //                            on s.AlbumId equals a.Id
            //                            group s by s.AlbumId into result
            //                            select result;
            //var albumIdsOrderedBySongCount = from s in songsGroupedByAlbumId
            //                                 orderby s.Count() descending
            //                                 select s.Key;
            //var albumId = albumIdsOrderedBySongCount.FirstOrDefault();
            //var album = Albums.FirstOrDefault(a => a.Id == albumId);
            //$"name: {album.Name}({album.Genre})".PrintItem();

            var albumId =
                (from s in (from s in Songs
                            join a in Albums
                            on s.AlbumId equals a.Id
                            group s by s.AlbumId into result
                            select result)
                 orderby s.Count() descending
                 select s.Key).FirstOrDefault();

            var album = Albums.FirstOrDefault(a => a.Id == albumId);

            $"name: {album.Name}({album.Genre})".PrintItem();
        }
Beispiel #4
0
        private void CreateAlbum(Track track, Artist albumArtist)
        {
            var album = Albums.FirstOrDefault(p =>
                                              p.Title.EqualsIgnoreCase(track.AlbumTitle) && p.Artist == albumArtist);

            if (album == null)
            {
                album = new Album
                {
                    Title      = track.AlbumTitle,
                    Artist     = albumArtist,
                    ArtworkUri = track.ArtworkUri,
                    Year       = track.Year,
                    Copyright  = track.Copyright,
                    Publisher  = track.Publisher
                };
                Albums.Add(album);
                albumArtist.Albums.Add(album);
            }
            else if (album.ArtworkUri == null)
            {
                album.ArtworkUri = track.ArtworkUri;
            }

            var sort = album.Tracks.ToList();

            sort.Add(track);
            sort.Sort(
                (track1, track2) =>
                (int)track1.TrackNumber + (int)track1.DiscCount - (int)(track2.TrackNumber + track2.DiscCount));
            var index = sort.IndexOf(track);

            album.Tracks.Insert(index, track);
        }
Beispiel #5
0
        public async Task DeleteSongAsync(Song song)
        {
            // remove it from artist and albums songs
            var artist = Artists.FirstOrDefault(p => p.Songs.Contains(song));
            var album  = Albums.FirstOrDefault(p => p.Songs.Contains(song));

            if (album != null)
            {
                album.Songs.Remove(song);
                if (album.Songs.Count == 0)
                {
                    await _sqlService.DeleteItemAsync(album);

                    Albums.Remove(album);
                }
            }

            if (artist != null)
            {
                artist.Songs.Remove(song);
                if (artist.Songs.Count == 0)
                {
                    await _sqlService.DeleteItemAsync(artist);

                    Artists.Remove(artist);
                }
            }

            //good, now lets delete it from the db
            await _sqlService.DeleteItemAsync(song);

            Songs.Remove(song);
        }
        private void DeleteAlbumMessageRecieved(DeleteAlbumMessage message)
        {
            var deletedAlbum = Albums.FirstOrDefault(r => r.Id == message.ObjectId);

            if (deletedAlbum != null)
            {
                Albums.Remove(deletedAlbum);
            }
        }
Beispiel #7
0
        public void LoadAlbums()
        {
            if (SelectedBand != null)
            {
                Albums = DAL.Data.Albums.Where(x => x.BandID == SelectedBand.Id).ToList();
            }

            if (Albums.Count > 0)
            {
                SelectedAlbum = Albums.FirstOrDefault();
            }
        }
Beispiel #8
0
        private void DeleteAlbum(Track track, Artist albumArtist)
        {
            var album = Albums.FirstOrDefault(p =>
                                              p.Title.EqualsIgnoreCase(track.AlbumTitle) && p.Artist == albumArtist);

            if (album == null)
            {
                return;
            }
            album.Tracks.Remove(track);
            if (album.Tracks.Count == 0)
            {
                Albums.Remove(album);
                albumArtist.Albums.Remove(album);
            }
        }
Beispiel #9
0
        private async void RemoveAlbum(VkAudioAlbum album)
        {
            try
            {
                var result = await ViewModelLocator.Vkontakte.Audio.DeleteAlbum(album.Id);

                if (result)
                {
                    Albums.Remove(Albums.FirstOrDefault(a => a.Id == album.Id));

                    SelectedAlbum = Albums.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
            }
        }
Beispiel #10
0
        private static void Task7()
        {// - print the name of the album
         //that has highest Average duration of a song
         //group songs by albumId
            var songGroups = from s in Songs
                             join a in Albums
                             on s.AlbumId equals a.Id
                             group s by s.AlbumId into result
                             select result;
            //albumIds ordered (ascending) by SongsDuration
            var albumIds = from s in songGroups
                           orderby s.Average(song => song.Duration)
                           select s.Key;

            //Id of album that has longest song average duration
            var albumId = albumIds.LastOrDefault();
            //finding album who's id is equal to albumId
            var album = Albums.FirstOrDefault(a => a.Id == albumId);

            album.Name.PrintItem();
        }
        public IAlbum GetAlbum(Guid id)
        {
            var album = Albums.FirstOrDefault(a => a.Id.Equals(id));

            return(album);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data

            // - print the mass of the earth on July 1895 XD

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            // QUERIES!

            // - how many Songs start with the letter 'a' (case insensitive)
            // - how many artists end with letter 'a' (case insensitive)
            // - whats the name of the song with longest duration
            // - whats the total Duration of all Songs
            // - how many albums have Songs longer than 300 seconds
            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre
            // - print the name of the album that has highest Average duration of a song
            // - how many characters has the song that has the shortest Duration
            // - print the name and the genre of the album that has most songs
            // - print the name of the artist that has most songs
            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            // - print the average song duration, of the album that has most songs

            // Bonus:
            // - print the longest song duration of the album that has least songs
            // - print the name of the album that has most songs that contain letter 'a' in the name
            // - print the name of the artist that has most songs that end with letter 'd'



            // ************ Don't mind the structure, focus on the lists declared on the beginning of Program.cs ****************

            // 3, 2, 1.... GO! :)

            //How many Songs start with the letter 'a'(case insensitive)  ?????????????????????????
            Console.WriteLine("1.How many Songs start with the letter 'a'(case insensitive)");
            List <Song> songsStartWithA = Songs
                                          .Where(song => song.Name.ToLower()
                                                 .StartsWith("a"))
                                          .ToList();

            Console.WriteLine(songsStartWithA.Count);

            //How many artists end with letter 'a'(case insensitive)
            Console.WriteLine("2.How many artists end with letter 'a'(case insensitive)");
            List <Artist> songsEndWithA = Artists
                                          .Where(song => song.FullName.ToLower()
                                                 .EndsWith("a"))
                                          .ToList();

            Console.WriteLine(songsEndWithA.Count);

            //Whats the name of the song with longest duration
            Console.WriteLine("3.Whats the name of the song with longest duration");
            Song longestSong = Songs
                               .FirstOrDefault(song => song.Duration == Songs
                                               .Select(s => s.Duration)
                                               .Max());

            Console.WriteLine($"{longestSong.Name}");

            // whats the total Duration of all Songs
            Console.WriteLine("4.Whats the total Duration of all Songs");
            int totalDurationSong = Songs
                                    .Select(s => s.Duration)
                                    .Sum();

            Console.WriteLine(totalDurationSong);

            // how many albums have Songs longer than 300 seconds
            Console.WriteLine("5.how many albums have Songs longer than 300 seconds");
            int songsLonger = Albums
                              .Where(a => a.Songs
                                     .Any(s => s.Duration > 300))
                              .Count();

            Console.WriteLine(songsLonger);


            // Print the names of the artists separated with --, that have more than one album of PopRock genre
            Console.WriteLine("6.Print the names of the artists separated with --, that have more than one album of PopRock genre");
            List <string> namesPopRockArtists = Artists
                                                .Where(x => x.Albums.Count > 1)
                                                .Where(artist => artist.Albums
                                                       .Any(album => album.Genre == Genre.PopRock))
                                                .Select(n => n.FullName)
                                                .ToList();

            namesPopRockArtists.ForEach(artist => Console.Write($"{artist} -- "));
            Console.WriteLine("\n");

            //Print the name of the album that has highest Average duration of a song
            Console.WriteLine("7.Print the name of the album that has highest Average duration of a song");
            Album higestAverage = Albums
                                  .FirstOrDefault(album => album.Songs
                                                  .Select(song => song.Duration).Average() == Albums
                                                  .Select(a => a.Songs
                                                          .Select(s => s.Duration).Average())
                                                  .Max());

            Console.WriteLine(higestAverage.Name);

            //how many characters has the song that has the shortest Duration
            Console.WriteLine("8.how many characters has the song that has the shortest Duration");
            Song songChar = Songs
                            .FirstOrDefault(song => song.Duration == Songs
                                            .Select(s => s.Duration)
                                            .Min());

            Console.WriteLine(songChar.Name.Count());

            //print the name and the genre of the album that has most songs
            Console.WriteLine("9.Print the name and the genre of the album that has most songs");
            Album genreMostSongsAlbum = Albums
                                        .FirstOrDefault(album => album.Songs.Count == Albums
                                                        .Select(a => a.Songs.Count)
                                                        .Max());

            Console.WriteLine($"{genreMostSongsAlbum.Name} - Genre:{genreMostSongsAlbum.Genre}");

            //print the name of the artist that has most songs
            Console.WriteLine("10.Print the name of the artist that has most songs");
            Artist mostSongs = Artists
                               .FirstOrDefault(artist => artist.Albums
                                               .Select(album => album.Songs.Count).Sum() == Artists
                                               .Select(a => a.Albums
                                                       .Select(al => al.Songs.Count).Sum())
                                               .Max());

            Console.WriteLine($"{mostSongs.FullName}");

            // Print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            Console.WriteLine("11.Print the type of the artist(SoloArtist / Band) that has most albums published before year 2000");
            Artist mostOldAlbums = Artists
                                   .FirstOrDefault(artist => artist.Albums.Count(al => al.Year < 2000) == Artists
                                                   .Select(a => a.Albums.Count(alb => alb.Year < 2000))
                                                   .Max());

            Console.WriteLine($"Name: {mostOldAlbums.FullName} - type: {mostOldAlbums.ArtistType}");

            //Print the average song duration, of the album that has most songs
            Console.WriteLine("12. Print the average song duration, of the album that has most songs");
            double songAverageDuration = Albums
                                         .FirstOrDefault(album => album.Songs.Count == Albums
                                                         .Select(a => a.Songs.Count)
                                                         .Max())
                                         .Songs
                                         .Select(song => song.Duration)
                                         .Average();

            Console.WriteLine(songAverageDuration);

            //Print the longest song duration of the album that has least songs
            Console.WriteLine("13.Print the longest song duration of the album that has least songs");
            Song longestSongDuration = Albums
                                       .FirstOrDefault(album => album.Songs.Count == Albums.Select(alb => alb.Songs.Count)
                                                       .Min())
                                       .Songs.FirstOrDefault(song => song.Duration == Albums
                                                             .Where(al => al.Songs.Count() == Albums
                                                                    .Select(s => s.Songs.Count())
                                                                    .Min())
                                                             .FirstOrDefault().Songs.Select(sg => sg.Duration)
                                                             .Max());

            Console.WriteLine($"Name: {longestSongDuration.Name}, Duration: {longestSongDuration.Duration}");

            //Print the name of the album that has most songs that contain letter 'a' in the name
            Console.WriteLine("14.Print the name of the album that has most songs that contain letter 'a' in the name");
            Album songsMostA = Albums
                               .FirstOrDefault(album => album.Songs
                                               .Where(song => song.Name.ToLower().Contains('a')).Count() == Albums
                                               .Select(al => al.Songs
                                                       .Where(s => s.Name.ToLower().Contains('a')).Count())
                                               .Max());

            Console.WriteLine($"Album name: {songsMostA.Name}");

            //Print the name of the artist that has most songs that end with letter 'd'
            Console.WriteLine("15.Print the name of the artist that has most songs that end with letter 'd'");
            Artist songsEndsD = Artists
                                .FirstOrDefault(artist => artist.Albums
                                                .Select(album => album.Songs
                                                        .Where(song => song.Name.ToLower().EndsWith('d')).Count()).Sum() == Artists
                                                .Select(ar => ar.Albums
                                                        .Select(al => al.Songs
                                                                .Where(s => s.Name.ToLower().EndsWith('d')).Count())
                                                        .Sum())
                                                .Max());

            Console.WriteLine($"Name of the artist: {songsEndsD.FullName}'");

            Console.ReadLine();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data

            // - print the mass of the earth on July 1895 XD

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            // QUERIES!



            VisualSeparator();


            #region Task 01

            // - how many Songs start with the letter 'a' (case insensitive)

            List <Song> songsStartingWithA = Songs
                                             .Where(x => x.Name.ToLower().StartsWith("a"))
                                             .ToList();

            Console.WriteLine("A list of all songs starting with an A:");
            songsStartingWithA.ForEach(x => Console.WriteLine(x.Name));

            VisualSeparator();

            #endregion


            #region Task 02

            // - how many artists end with letter 'a' (case insensitive)

            List <Artist> artistNamesEndingWithA = Artists
                                                   .Where(x => x.FullName.ToLower().EndsWith("a"))
                                                   .ToList();


            Console.WriteLine("A list of all artists names ending with an A:");
            artistNamesEndingWithA.ForEach(x => Console.WriteLine(x.FullName));

            VisualSeparator();

            #endregion


            #region Task 03

            // - whats the name of the song with longest duration

            int longestDurationOfASong = Songs
                                         .Select(x => x.Duration)
                                         .Max();

            Song songWithLongestDuration = Songs
                                           .FirstOrDefault(x => x.Duration == longestDurationOfASong);


            Console.WriteLine($"The song with the longest duration is \"{songWithLongestDuration.Name}\".");

            VisualSeparator();

            #endregion


            #region Task 04

            // - whats the total Duration of all Songs

            int totalDurationOfAllSongs = Songs
                                          .Select(x => x.Duration)
                                          .Sum();


            Console.WriteLine($"The total duration of all songs is {totalDurationOfAllSongs} seconds (approximately {totalDurationOfAllSongs / 60} minutes).");

            VisualSeparator();

            #endregion


            #region Task 05

            // - how many albums have Songs longer than 300 seconds


            int albumsWithSongsLongerThan300 = Albums
                                               .Where(album => album.Songs.FirstOrDefault(song => song.Duration > 300) != null)
                                               .ToList()
                                               .Count;

            Console.WriteLine($"The number of albums with songs longer than 300 seconds is {albumsWithSongsLongerThan300}.");

            VisualSeparator();

            #endregion


            #region Task 06

            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre

            List <Artist> artistsWithMoreThan1PopRockAlbum = Artists
                                                             .Where(artist => artist.Albums.Select(listOfAlbums => listOfAlbums.Genre == Genre.PopRock).Count() > 1)
                                                             .ToList();

            Console.WriteLine("Names of the artists that have more than one album of the pop-rock genre:");

            for (int i = 0; i < artistsWithMoreThan1PopRockAlbum.Count; i++)
            {
                if (i == artistsWithMoreThan1PopRockAlbum.Count - 1)
                {
                    Console.Write($"{artistsWithMoreThan1PopRockAlbum[i].FullName}\n");
                }
                else
                {
                    Console.Write($"{artistsWithMoreThan1PopRockAlbum[i].FullName} -- ");
                }
            }

            VisualSeparator();

            #endregion


            #region Task 07

            // - print the name of the album that has highest Average duration of a song

            double highestAverageSongDuration = Albums
                                                .Select(album => album.Songs.Select(song => song.Duration).ToList())
                                                .Select(list => list.Average()).Max();

            var nameOfAlbWithMaxAvgSongDuration = Albums
                                                  .FirstOrDefault(album => album.Songs.Select(song => song.Duration).Average() == highestAverageSongDuration);

            Console.WriteLine($"The album with the highest song duration average is:");
            Console.WriteLine(nameOfAlbWithMaxAvgSongDuration.Name);

            VisualSeparator();

            #endregion


            #region task 08

            // - how many characters has the song that has the shortest Duration



            var shortestSong = Songs
                               .FirstOrDefault(x => x.Duration == Songs.Select(song => song.Duration).Min());

            string noSpacesName = shortestSong.Name.Replace(" ", "");

            Console.WriteLine($"The shortest song is {shortestSong.Name}, it lasts {shortestSong.Duration} seconds, and its name is {noSpacesName.Length} characters long (without the empty spaces).");


            VisualSeparator();

            #endregion


            #region Task 09

            // - print the name and the genre of the album that has most songs

            Album albumWithMostSongs = Albums
                                       .FirstOrDefault(album => album.Songs.Count == Albums.Select(a => a.Songs.Count).Max());


            Console.WriteLine($"The album with most songs is {albumWithMostSongs.Name} and its genre is {albumWithMostSongs.Genre}.");


            VisualSeparator();

            #endregion

            #region Task 10 - NE E RESENA

            // - print the name of the artist that has most songs


            #endregion


            #region Task 11 - NE E RESENA
            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000



            //artistWithMostAlbumsPre200.ForEach(x => Console.WriteLine(x.FullName));

            #endregion

            #region Task 12

            // - print the average song duration, of the album that has most songs

            double avgSongDurationOfAlbumWithMostSongs = albumWithMostSongs.Songs
                                                         .Select(song => song.Duration)
                                                         .Average();


            Console.WriteLine($"The average song duration of the album with most songs is {avgSongDurationOfAlbumWithMostSongs} seconds.");

            VisualSeparator();

            #endregion


            // Bonus:

            #region Task 13

            // - print the longest song duration of the album that has least songs

            Album albumWithLeastSongs = Albums
                                        .FirstOrDefault(album => album.Songs.Count == Albums.Select(a => a.Songs.Count).Min());

            Song longestSongFromAlbumWithLeastSongs = albumWithLeastSongs.Songs
                                                      .FirstOrDefault(song => song.Duration == albumWithLeastSongs.Songs.Select(sng => sng.Duration).Max());



            Console.WriteLine($"The longest song from the album with least songs is {longestSongFromAlbumWithLeastSongs.Name}, and its durations is {longestSongFromAlbumWithLeastSongs.Duration} seconds (approximately {longestSongFromAlbumWithLeastSongs.Duration / 60} minutes).");

            VisualSeparator();


            #endregion


            #region Task 14 NE E RESENA

            // - print the name of the album that has most songs that contain letter 'a' in the name



            VisualSeparator();

            #endregion

            #region Task 15 NE E RESENA

            // - print the name of the artist that has most songs that end with letter 'd'



            VisualSeparator();

            #endregion

            // ************ Don't mind the structure, focus on the lists declared on the beginning of Program.cs ****************

            // 3, 2, 1.... GO! :)



            Console.ReadLine();
        }
 public string GetKey()
 {
     return($"{Id}:{Albums.FirstOrDefault().Id}");
 }
Beispiel #15
0
        public async Task AddSongAsync(Song song, string artworkUrl)
        {
            if (Songs.Count(p => p.ProviderId == song.ProviderId) > 0)
            {
                throw new Exception("AlreadySavedToast".FromLanguageResource());
            }

            #region create artist

            if (song.Artist.ProviderId == "lastid.")
            {
                song.Artist.ProviderId = "autc.single." + song.ProviderId;
            }

            var artist = Artists.FirstOrDefault(entry => entry.ProviderId == song.Artist.ProviderId);

            if (artist == null)
            {
                await _sqlService.InsertAsync(song.Artist);

                if (song.Album != null)
                {
                    song.Album.PrimaryArtistId = song.Artist.Id;
                }
                Artists.Insert(0, song.Artist);
            }

            else
            {
                song.Artist = artist;

                if (song.Album != null)
                {
                    song.Album.PrimaryArtistId = artist.Id;
                }
            }
            song.ArtistId = song.Artist.Id;

            #endregion

            #region create album

            if (song.Album == null)
            {
                song.Album = new Album
                {
                    PrimaryArtistId = song.ArtistId,
                    Name            = song.Name + " (Single)",
                    PrimaryArtist   = song.Artist,
                    ProviderId      = "autc.single." + song.ProviderId
                };
                await _sqlService.InsertAsync(song.Album);

                Albums.Insert(0, song.Album);
                song.Artist.Albums.Insert(0, song.Album);
            }
            else
            {
                var album = Albums.FirstOrDefault(p => p.ProviderId == song.Album.ProviderId);

                if (album != null)
                {
                    song.Album = album;
                }
                else
                {
                    await _sqlService.InsertAsync(song.Album);

                    Albums.Insert(0, song.Album);
                    song.Artist.Albums.Insert(0, song.Album);
                }
            }

            song.AlbumId = song.Album.Id;

            #endregion

            #region Download artwork

            if (artworkUrl != null)
            {
//Use the album if one is available
                var filePath = string.Format(CollectionConstant.ArtworkPath, song.Album.Id);

                //Check if the album artwork has already been downloaded
                var artworkExists = await StorageHelper.FileExistsAsync(filePath);

                if (!artworkExists)
                {
                    try
                    {
                        using (var client = new HttpClient())
                        {
                            using (var stream = await client.GetStreamAsync(artworkUrl))
                            {
                                using (
                                    var fileStream =
                                        await
                                            (await StorageHelper.CreateFileAsync(filePath)).OpenStreamForWriteAsync()
                                    )
                                {
                                    await stream.CopyToAsync(fileStream);

                                    //now set it
                                    song.Album.Artwork =
                                        new BitmapImage(new Uri(CollectionConstant.LocalStorageAppPath + filePath));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine("Some shit happened saving the artwork, here: " + e);
                    }
                }
            }

            if (song.Album.Artwork == null)
            {
                song.Album.Artwork = CollectionConstant.MissingArtworkImage;
            }

            #endregion

            //Insert to db
            await _sqlService.InsertAsync(song);

            song.Artist.Songs.Insert(0, song);
            song.Album.Songs.Insert(0, song);
            Songs.Insert(0, song);
        }
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data

            // - print the mass of the earth on July 1895 XD

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            // QUERIES!

            // - how many Songs start with the letter 'a' (case insensitive)

            List <Song> songStartA = Songs
                                     .Where(song => song.Name.ToLower()
                                            .StartsWith("a"))
                                     .ToList();

            Console.WriteLine($"1) Number od songs that start with the letter 'a' is: {songStartA.Count}");
            Console.WriteLine("");

            // - how many artists end with letter 'a' (case insensitive)

            List <Artist> artistEndA = Artists
                                       .Where(artist => artist.FullName.ToLower()
                                              .EndsWith("a"))
                                       .ToList();

            Console.WriteLine($"2) Number of artist that end with letter 'a' is: {artistEndA.Count}");
            Console.WriteLine("");

            // - whats the name of the song with longest duration

            Song longestSong = Songs
                               .FirstOrDefault(song => song.Duration == Songs
                                               .Select(sg => sg.Duration)
                                               .Max());

            Console.WriteLine($"3) The name of the song with the largest duration is: {longestSong.Name}");
            Console.WriteLine("");

            // - whats the total Duration of all Songs

            int totalDuration = Songs
                                .Select(song => song.Duration)
                                .Sum();

            Console.WriteLine($"4) The total duration of all songs is: {totalDuration} seconds");
            Console.WriteLine("");

            // - how many albums have Songs longer than 300 seconds

            int longSongAlbums = Albums
                                 .Where(album => album.Songs
                                        .Any(song => song.Duration > 300))
                                 .Count();

            Console.WriteLine($"5) Number of albums that have Songs longer than 300 seconds is {longSongAlbums}");
            Console.WriteLine("");

            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre

            List <string> popRockArtists = Artists
                                           .Where(artist => artist.Albums
                                                  .Any(album => album.Genre == Genre.PopRock))
                                           .Where(x => x.Albums.Count() > 1)
                                           .Select(name => name.FullName)
                                           .ToList();

            Console.WriteLine("6) Names of artists with more than one PopRock album:");
            popRockArtists.ForEach(artist => Console.Write($"{artist} -- "));
            Console.WriteLine("");
            Console.WriteLine("");


            // - print the name of the album that has highest Average duration of a song

            Album albumHigestAverage = Albums
                                       .FirstOrDefault(album => album.Songs
                                                       .Select(song => song.Duration).Average() == Albums
                                                       .Select(alb => alb.Songs
                                                               .Select(sg => sg.Duration).Average())
                                                       .Max());

            Console.WriteLine($"7) Name of the album that has highest Average duration of a song is: {albumHigestAverage.Name}");
            Console.WriteLine("");

            // - how many characters has the song that has the shortest Duration


            Song shortSongChar = Songs
                                 .FirstOrDefault(song => song.Duration == Songs
                                                 .Select(sg => sg.Duration)
                                                 .Min());

            Console.WriteLine($"8) The song that has the shortest Duration is called '{shortSongChar.Name}' and has {shortSongChar.Name.Count()} characters");
            Console.WriteLine("");

            // - print the name and the genre of the album that has most songs

            Album mostSongsAlbun = Albums
                                   .FirstOrDefault(album => album.Songs.Count == Albums
                                                   .Select(alb => alb.Songs.Count)
                                                   .Max());

            Console.WriteLine($"9) Name of album that has most songs {mostSongsAlbun.Name} - Genre: {mostSongsAlbun.Genre}");
            Console.WriteLine("");

            // - print the name of the artist that has most songs

            Artist mostSongsArtist = Artists
                                     .FirstOrDefault(artist => artist.Albums
                                                     .Select(album => album.Songs.Count).Sum() == Artists
                                                     .Select(ar => ar.Albums
                                                             .Select(al => al.Songs.Count).Sum())
                                                     .Max());

            Console.WriteLine($"10) Name of artist with most songs: {mostSongsArtist.FullName}");
            Console.WriteLine("");

            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000

            Artist mostOldAlbums = Artists
                                   .FirstOrDefault(artist => artist.Albums.Count(alb => alb.Year < 2000) == Artists
                                                   .Select(ar => ar.Albums.Count(al => al.Year < 2000))
                                                   .Max());

            Console.WriteLine($"11) Type of the artist(SoloArtist/Band) that has most albums published before year 2000: {mostOldAlbums.ArtistType}");
            Console.WriteLine($"Name of artist(SoloArtist/Band): {mostOldAlbums.FullName}");
            Console.WriteLine("");

            // - print the average song duration, of the album that has most songs

            double mostSongAlbAverDur = Albums
                                        .FirstOrDefault(album => album.Songs.Count == Albums
                                                        .Select(alb => alb.Songs.Count).Max())
                                        .Songs
                                        .Select(song => song.Duration)
                                        .Average();

            Console.WriteLine($"12) Average song duration, of the album that has most songs: {mostSongAlbAverDur}");
            Console.WriteLine("");

            // Bonus:
            // - print the longest song duration of the album that has least songs

            Song longSongShortAlbum = Albums
                                      .FirstOrDefault(album => album.Songs.Count == Albums.Select(alb => alb.Songs.Count).Min())
                                      .Songs.FirstOrDefault(song => song.Duration == Albums
                                                            .Where(al => al.Songs.Count() == Albums
                                                                   .Select(x => x.Songs.Count())
                                                                   .Min())
                                                            .FirstOrDefault().Songs.Select(sg => sg.Duration).Max());


            Console.WriteLine($"13) The longest song duration of the album that has least songs is {longSongShortAlbum.Duration}");
            Console.WriteLine($"The name of the song is: '{longSongShortAlbum.Name}'");
            Console.WriteLine("");

            // - print the name of the album that has most songs that contain letter 'a' in the name

            Album albumSongsMostA = Albums
                                    .FirstOrDefault(album => album.Songs
                                                    .Where(song => song.Name.ToLower().Contains('a')).Count() == Albums
                                                    .Select(alb => alb.Songs
                                                            .Where(sg => sg.Name.ToLower().Contains('a')).Count())
                                                    .Max());

            Console.WriteLine($"14) Name of the album that has most songs that contain letter 'a' in the name is '{albumSongsMostA.Name}'");
            Console.WriteLine("");


            // - print the name of the artist that has most songs that end with letter 'd'

            Artist artistSongsEndsD = Artists
                                      .FirstOrDefault(artist => artist.Albums
                                                      .Select(album => album.Songs
                                                              .Where(song => song.Name.ToLower().EndsWith('d')).Count()).Sum() == Artists
                                                      .Select(art => art.Albums
                                                              .Select(alb => alb.Songs
                                                                      .Where(sg => sg.Name.ToLower().EndsWith('d')).Count()).Sum())
                                                      .Max());

            Console.WriteLine($"15) Name of the artist that has most songs that end with letter 'd' is '{artistSongsEndsD.FullName}'");

            // ************ Don't mind the structure, focus on the lists declared on the beginning of Program.cs ****************

            // 3, 2, 1.... GO! :)



            Console.ReadLine();
        }