예제 #1
0
        public async Task HandleResponseMultiple()
        {
            var command = new GetRecentTracksCommand(MAuth.Object, "rj")
            {
                Count = 1
            };

            var expectedTrack = new LastTrack
            {
                ArtistName = "The Who",
                TimePlayed = new DateTime(2014, 12, 19, 16, 13, 55, DateTimeKind.Utc),
                Mbid       = "79f3dc97-2297-47ee-8556-9a1bb4b48d53",
                Name       = "Pinball Wizard",
                ArtistMbid = "9fdaa16b-a6c4-4831-b87c-bc9ca8ce7eaa",
                AlbumName  = "Tommy (Remastered)",
                Url        = new Uri("http://www.last.fm/music/The+Who/_/Pinball+Wizard", UriKind.Absolute),
                Images     = new LastImageSet(
                    "http://userserve-ak.last.fm/serve/34s/35234991.jpg",
                    "http://userserve-ak.last.fm/serve/64s/35234991.jpg",
                    "http://userserve-ak.last.fm/serve/126/35234991.jpg",
                    "http://userserve-ak.last.fm/serve/300x300/35234991.jpg")
            };

            var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetRecentTracksMultiple));
            var actual   = await command.HandleResponse(response);

            Assert.IsTrue(actual.Success);
            TestHelper.AssertSerialiseEqual(expectedTrack, actual.Content[2]);
        }
예제 #2
0
 public static string TrackToOneLinedString(LastTrack track)
 {
     return($"{track.Name} By **{track.ArtistName}**" +
            (string.IsNullOrWhiteSpace(track.AlbumName)
                ? ""
                : $" | *{track.AlbumName}*"));
 }
예제 #3
0
        public async Task HandleResponseMultiple()
        {
            var command = new GetLovedTracksCommand(MAuth.Object, "rj")
            {
                Count = 3
            };

            var expectedTrack = new LastTrack
            {
                ArtistName = "The Rolling Stones",
                TimePlayed = new DateTime(2014, 12, 19, 16, 16, 56, DateTimeKind.Utc),
                Mbid       = "3dde65c8-22c3-4637-b67e-b234177c847b",
                Name       = "Love in Vain",
                ArtistMbid = "b071f9fa-14b0-4217-8e97-eb41da73f598",
                AlbumName  = "Let It Bleed",
                Url        = new Uri("http://www.last.fm/music/The+Rolling+Stones/_/Love+in+Vain"),
                Images     = new LastImageSet(
                    "http://userserve-ak.last.fm/serve/34s/101739037.png",
                    "http://userserve-ak.last.fm/serve/64s/101739037.png",
                    "http://userserve-ak.last.fm/serve/126/101739037.png",
                    "http://userserve-ak.last.fm/serve/300x300/101739037.png")
            };

            var file     = GetFileContents("UserApi.UserGetLovedTracksMultiple.json");
            var response = CreateResponseMessage(file);
            //var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetLovedTracksMultiple));
            var actual = await command.HandleResponse(response);

            Assert.IsTrue(actual.Success);
            TestHelper.AssertSerialiseEqual(expectedTrack, actual.Content[1]);
        }
예제 #4
0
        public async Task HandleResponseSingle()
        {
            var expectedTrack = new LastTrack
            {
                ArtistName     = "Dire Straits",
                Duration       = new TimeSpan(0, 5, 47),
                TotalPlayCount = 81,
                Mbid           = "0317e524-7f70-4910-bc12-95dd468a29fc",
                Name           = "Sultans of Swing",
                ArtistMbid     = "614e3804-7d34-41ba-857f-811bad7c2b7a",
                AlbumName      = "Dire Straits (Remastered)",
                Url            = new Uri("http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", UriKind.Absolute),
                Images         = new LastImageSet(
                    "http://userserve-ak.last.fm/serve/34s/56827829.jpg",
                    "http://userserve-ak.last.fm/serve/64s/56827829.jpg",
                    "http://userserve-ak.last.fm/serve/126/56827829.jpg",
                    "http://userserve-ak.last.fm/serve/300x300/56827829.jpg")
            };

            var expected = new List <LastTrack> {
                expectedTrack
            };

            await CompareResultsSingle(_command, expected, LibraryApiResponses.LibraryGetTracksSingle);
        }
        public async Task HandleResponseMultiple()
        {
            var command = new GetTracksCommand(MAuth.Object, "rj", "", "", DateTimeOffset.MinValue)
            {
                Count = 1
            };

            var expectedTrack = new LastTrack
            {
                ArtistName = "Stevie Wonder",
                Duration   = new TimeSpan(0, 4, 8),
                PlayCount  = 56,
                Mbid       = "0161855d-0b98-4f2d-b2ab-446dbd8d6759",
                Name       = "Superstition",
                ArtistMbid = "1ee18fb3-18a6-4c7f-8ba0-bc41cdd0462e",
                AlbumName  = "Number Ones",
                Url        = new Uri("http://www.last.fm/music/Stevie+Wonder/_/Superstition", UriKind.Absolute),
                Images     = new LastImageSet(
                    "http://userserve-ak.last.fm/serve/34s/99695819.jpg",
                    "http://userserve-ak.last.fm/serve/64s/99695819.jpg",
                    "http://userserve-ak.last.fm/serve/126/99695819.jpg",
                    "http://userserve-ak.last.fm/serve/300x300/99695819.jpg")
            };

            var file     = GetFileContents("LibraryApi.LibraryGetTracksMultiple.json");
            var response = CreateResponseMessage(file);
            //var response = CreateResponseMessage(Encoding.UTF8.GetString(LibraryApiResponses.LibraryGetTracksMultiple));
            var actual = await command.HandleResponse(response);

            Assert.IsTrue(actual.Success);
            TestHelper.AssertSerialiseEqual(expectedTrack, actual.Content[1]); // Testing the second track returned
        }
예제 #6
0
        public static async Task SaveTrackAsync(LastTrack track)
        {
            var url = await Mp3MatchEngine.FindMp3For(track);

            if (string.IsNullOrEmpty(url))
            {
                CurtainToast.ShowError("NoMatchFoundToast".FromLanguageResource());
            }

            else
            {
                var preparedSong = await PrepareTrackForDownloadAsync(track);

                preparedSong.Song.AudioUrl = url;

                try
                {
                    await App.Locator.CollectionService.AddSongAsync(preparedSong.Song, preparedSong.ArtworkUrl);

                    CurtainToast.Show("SongSavedToast".FromLanguageResource());
                }
                catch (Exception e)
                {
                    CurtainToast.ShowError(e.Message);
                }
            }
        }
        public async Task HandleResponseSingle()
        {
            var command = new GetTracksCommand(MAuth.Object, "rj", "", "", DateTimeOffset.MinValue)
            {
                Count = 1
            };

            var expectedTrack = new LastTrack
            {
                ArtistName = "Dire Straits",
                Duration   = new TimeSpan(0, 5, 47),
                PlayCount  = 81,
                Mbid       = "0317e524-7f70-4910-bc12-95dd468a29fc",
                Name       = "Sultans of Swing",
                ArtistMbid = "614e3804-7d34-41ba-857f-811bad7c2b7a",
                AlbumName  = "Dire Straits (Remastered)",
                Url        = new Uri("http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", UriKind.Absolute),
                Images     = new LastImageSet(
                    "http://userserve-ak.last.fm/serve/34s/56827829.jpg",
                    "http://userserve-ak.last.fm/serve/64s/56827829.jpg",
                    "http://userserve-ak.last.fm/serve/126/56827829.jpg",
                    "http://userserve-ak.last.fm/serve/300x300/56827829.jpg")
            };

            var file     = GetFileContents("LibraryApi.LibraryGetTracksSingle.json");
            var response = CreateResponseMessage(file);
            //var response = CreateResponseMessage(Encoding.UTF8.GetString(LibraryApiResponses.LibraryGetTracksSingle));
            var actual = await command.HandleResponse(response);

            Assert.IsTrue(actual.Success);
            TestHelper.AssertSerialiseEqual(expectedTrack, actual.Single());
        }
예제 #8
0
        private static async Task <SaveResults> SaveLastTrackLevel3(LastTrack track)
        {
            try
            {
                //await SaveLastTrackLevel4(track);
                var preparedSong = track.ToSong();
                preparedSong.Album  = track.ToAlbum();
                preparedSong.Artist = track.ToArtist();
                preparedSong.Album.PrimaryArtist = preparedSong.Artist;

                if (App.Locator.CollectionService.SongAlreadyExists(track.Name, track.AlbumName, track.ArtistName))
                {
                    return(new SaveResults()
                    {
                        Error = SavingError.AlreadyExists
                    });
                }

                await App.Locator.CollectionService.AddSongAsync(preparedSong, isLastTrack : true).ConfigureAwait(false);

                CollectionHelper.MatchSong(preparedSong);
                return(new SaveResults {
                    Error = SavingError.None, Song = preparedSong
                });
            }
            catch
            {
                return(new SaveResults {
                    Error = SavingError.Unknown
                });
            }
        }
예제 #9
0
 private static async Task SaveLastTrackFindAlbum(LastTrack song)
 {
     try
     {
         var track = await App.Locator.ScrobblerService.GetDetailTrack(song.Name, song.ArtistName).ConfigureAwait(false);;
         if (track == null)
         {
             song.AlbumName = "Unknown Album";
         }
         else
         {
             if (track.AlbumName != null)
             {
                 song.AlbumName = track.AlbumName;
             }
             else
             {
                 song.AlbumName = "Unknown Album";
             }
         }
     }
     catch (Exception)
     {
         song.AlbumName = "Unknown Album";
     }
 }
예제 #10
0
 private static string CustomFormat(LastTrack lastTrack)
 {
     if (ProgramSettings.CustomExportEnabled)
     {
         return(ProgramSettings.CustomExportFormat
                .Replace(TOKEN_ID, lastTrack.ID, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_FOLDER_PATH, lastTrack.FolderPath, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_ARTIST, lastTrack.Artist, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_TITLE, lastTrack.Title, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_IMAGE_PATH, lastTrack.ImagePath, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_BPM, lastTrack.BPM, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_RATING, lastTrack.Rating.ToString(CultureInfo.InvariantCulture), StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_RELEASE_YEAR, lastTrack.ReleaseYear.ToString(), StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_LENGTH, lastTrack.Length, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_COLOR_ID, lastTrack.ColorID.ToString(), StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_COLOR_NAME, lastTrack.ColorName, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_COMMENT, lastTrack.TrackComment, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_ALBUM, lastTrack.AlbumName, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_LABEL, lastTrack.LabelName, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_GENRE, lastTrack.GenreName, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_KEY, lastTrack.KeyName, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_REMIXER, lastTrack.RemixerName, StringComparison.InvariantCultureIgnoreCase)
                .Replace(TOKEN_MESSAGE, lastTrack.Message, StringComparison.InvariantCultureIgnoreCase));
     }
     else
     {
         return(null);
     }
 }
예제 #11
0
        public async Task TestMethod1()
        {
            // var json = await response.Content.ReadAsStringAsync();
            var response = CreateResponseMessage(Encoding.UTF8.GetString(LibraryApiResponses.LibraryGetTracksMultiple));

            var json = await response.Content.ReadAsStringAsync();

            JToken jtoken = JsonConvert.DeserializeObject <JToken>(json).SelectToken("tracks");



            var tracksToken = jtoken.SelectToken("track");


            var tracks = new List <LastTrack>();

            foreach (var track in tracksToken.Children())
            {
                var t = LastTrack.ParseJToken(track);

                tracks.Add(t);
            }

            Assert.AreEqual(tracks.Count, 20);

            //   var actual = parsed.Content;
            //var token = JsonConvert.DeserializeObject<JToken>(json);//.SelectToken("shouts"); ;
            //LastTrack.ParseJToken(jtoken);
        }
예제 #12
0
        public static async Task <string> FindMp3For(LastTrack track)
        {
            //match engines get better results using ft instead of feat
            //so rename if it contains that
            var title  = track.Name.Replace("feat.", "ft.");
            var artist = track.ArtistName;


            var currentProvider = 0;

            while (currentProvider < Providers.Length)
            {
                var mp3Provider = Providers[currentProvider];
                var url         = await mp3Provider.GetMatch(title, artist);

                if (url != null)
                {
                    return(url);
                }

                currentProvider++;
            }

            return(null);
        }
        public async Task HandleResponseSingle()
        {
            var expectedTrack = new LastTrack
            {
                ArtistName = "Rick James",
                Mbid       = "",
                Name       = "Super Freak (Part 1) - 1981 Single Version",
                ArtistMbid = "cba9cec2-be8d-41bd-91b4-a1cd7de39b0c",

                TimePlayed = new DateTime(2014, 12, 20, 10, 16, 52, DateTimeKind.Utc),
                AlbumName  = "The Definitive Collection",
                Url        = new Uri("http://www.last.fm/music/Rick+James/_/Super+Freak+(Part+1)+-+1981+Single+Version", UriKind.Absolute),
                Images     = new LastImageSet(
                    "http://userserve-ak.last.fm/serve/34s/90462319.jpg",
                    "http://userserve-ak.last.fm/serve/64s/90462319.jpg",
                    "http://userserve-ak.last.fm/serve/126/90462319.jpg",
                    "http://userserve-ak.last.fm/serve/300x300/90462319.jpg")
            };

            var expected = new List <LastTrack> {
                expectedTrack
            };

            await CompareResultsSingle(_command, expected, UserApiResponses.UserGetRecentTracksSingle);
        }
        public async Task UpdatesNowPlaying()
        {
            var trackPlayed  = DateTime.UtcNow.AddMinutes(-1);
            var testScrobble = new Scrobble(ARTIST_NAME, ALBUM_NAME, TRACK_NAME, trackPlayed)
            {
                Duration    = new TimeSpan(0, 0, 3, 49, 200),
                AlbumArtist = ARTIST_NAME
            };

            var response = await Lastfm.Track.UpdateNowPlayingAsync(testScrobble);

            Assert.IsTrue(response.Success);

            var tracks = await Lastfm.User.GetRecentScrobbles(Lastfm.Auth.UserSession.Username, null, 1, 1);

            var expectedTrack = new LastTrack
            {
                Name       = TRACK_NAME,
                ArtistName = ARTIST_NAME,
                AlbumName  = ALBUM_NAME,
                Mbid       = "1b9ee1d8-c5a7-44d9-813e-85beb0d59f1b",
                ArtistMbid = "b1570544-93ab-4b2b-8398-131735394202",
                Url        = new Uri("http://www.last.fm/music/Crystal+Castles/_/Not+in+Love"),
                Images     = new LastImageSet("http://userserve-ak.last.fm/serve/34s/61473043.png",
                                              "http://userserve-ak.last.fm/serve/64s/61473043.png",
                                              "http://userserve-ak.last.fm/serve/126/61473043.png",
                                              "http://userserve-ak.last.fm/serve/300x300/61473043.png"),
                IsNowPlaying = true
            };

            var expectedJson = expectedTrack.TestSerialise();
            var actualJson   = tracks.Content.FirstOrDefault().TestSerialise();

            Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson));
        }
예제 #15
0
        public async Task HandleResponseSingle()
        {
            var command = new GetRecentTracksCommand(MAuth.Object, "rj")
            {
                Count = 1
            };

            var expectedTrack = new LastTrack
            {
                ArtistName = "Rick James",
                Mbid       = "",
                Name       = "Super Freak (Part 1) - 1981 Single Version",
                ArtistMbid = "cba9cec2-be8d-41bd-91b4-a1cd7de39b0c",

                TimePlayed = new DateTime(2014, 12, 20, 10, 16, 52, DateTimeKind.Utc),
                AlbumName  = "The Definitive Collection",
                Url        = new Uri("http://www.last.fm/music/Rick+James/_/Super+Freak+(Part+1)+-+1981+Single+Version", UriKind.Absolute),
                Images     = new LastImageSet(
                    "http://userserve-ak.last.fm/serve/34s/90462319.jpg",
                    "http://userserve-ak.last.fm/serve/64s/90462319.jpg",
                    "http://userserve-ak.last.fm/serve/126/90462319.jpg",
                    "http://userserve-ak.last.fm/serve/300x300/90462319.jpg")
            };

            var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetRecentTracksSingle));
            var actual   = await command.HandleResponse(response);

            Assert.IsTrue(actual.Success);
            TestHelper.AssertSerialiseEqual(expectedTrack, actual.Single());
        }
예제 #16
0
 private static LastfmTrack ToLastfmTrack(LastTrack track)
 {
     return(new LastfmTrack(
                track.Name,
                track.ArtistName,
                track.Url,
                track.UserPlayCount));
 }
예제 #17
0
        private static string JSONFormat(LastTrack lastTrack)
        {
            JsonSerializerOptions options = new JsonSerializerOptions();

            options.WriteIndented = true;

            return(JsonSerializer.Serialize(lastTrack, options));
        }
예제 #18
0
 public static string TrackToString(LastTrack track)
 {
     return($"{track.Name}\n" +
            $"By **{track.ArtistName}**" +
            (string.IsNullOrWhiteSpace(track.AlbumName)
                ? "\n"
                : $" | *{track.AlbumName}*\n"));
 }
예제 #19
0
 public static Artist ToArtist(this LastTrack Artist)
 {
     return(new Artist
     {
         Name = Artist.ArtistName.Trim().Replace("  ", " "),
         ProviderId =
             !string.IsNullOrEmpty(Artist.Mbid) ? ("mbid." + Artist.Mbid) : ("lastid." + Artist.Id)
     });
 }
예제 #20
0
        private static async Task <SavingError> SaveLastTrackLevel2(LastTrack track)
        {
            if (track == null)
            {
                return(SavingError.Unknown);
            }
            var alreadySaving = LastfmSavingTracks.FirstOrDefault(p => p == track.Id) != null;

            if (alreadySaving)
            {
                return(SavingError.AlreadySaving);
            }

            LastfmSavingTracks.Add(track.Id);
            while (!App.Locator.CollectionService.IsLibraryLoaded)
            {
            }
            var startTransaction = !App.Locator.SqlService.DbConnection.IsInTransaction;

            if (startTransaction)
            {
                App.Locator.SqlService.BeginTransaction();
            }
            var result = await SaveLastTrackLevel3(track);

            if (startTransaction)
            {
                App.Locator.SqlService.Commit();
            }
            ShowResults(result.Error, track.Name);
            LastfmSavingTracks.Remove(track.Id);

            if (result.Song != null)
            {
                if (!result.Song.Album.HasArtwork && !result.Song.Album.NoArtworkFound)
                {
                    if (track.Images != null && track.Images.Largest != null)
                    {
                        await DownloadArtworks.SaveAlbumImageAsync(result.Song.Album, track.Images.Largest.AbsoluteUri);
                    }
                    else
                    {
                        await DownloadArtworks.DownloadAlbumsArtworkAsync();
                    }
                }
            }

            if (App.Locator.Setting.SpotifyArtworkSync)
            {
                await DownloadArtworks.DownloadArtistsArtworkAsyncFromSpotify(false, result.Song.Artist.Name);
            }
            else
            {
                await DownloadArtworks.DownloadArtistsArtworkAsync(false, result.Song.Artist.Name);
            }
            return(result.Error);
        }
예제 #21
0
        public static Song ToSong(this LastTrack track)
        {
            var song = new Song
            {
                ProviderId = track.Id,
                Name       = track.Name.Trim().Replace("  ", " ")
            };

            return(song);
        }
예제 #22
0
        public static Song ToSong(this LastTrack track)
        {
            var song = new Song
            {
                ProviderId = !string.IsNullOrEmpty(track.Mbid) ? ("mbid." + track.Mbid) : ("lastid." + track.Id),
                Name       = track.Name.Trim().Replace("  ", " ")
            };

            return(song);
        }
예제 #23
0
        public static Album ToAlbum(this LastTrack Album)
        {
            var album = new Album
            {
                ProviderId =
                    !string.IsNullOrEmpty(Album.Mbid) ? ("mbid." + Album.Mbid) : ("lastid." + Album.Id),
                Name = Album.AlbumName.Trim().Replace("  ", " "),
            };

            return(album);
        }
예제 #24
0
        private static string FormatLastPlayed(string username, LastTrack track)
        {
            var formattedMessage = new StringBuilder();

            formattedMessage.AppendFormat(
                track.IsNowPlaying.HasValue ? Strings.LastFMCurrentPlaying : Strings.LastFMLastPlayed, username);

            formattedMessage.AppendFormat("\n{0} ♪ {1}", track.ArtistName, track.Name);

            return(formattedMessage.ToString());
        }
예제 #25
0
 private static bool CheckUp(LastTrack track)
 {
     if (!string.IsNullOrEmpty(track.Name) && !string.IsNullOrEmpty(track.ArtistName) &&
         !string.IsNullOrEmpty(track.AlbumName))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #26
0
 public TrackDto MapTrack(LastTrack track)
 {
     return(new TrackDto {
         Name = track.Name,
         Rank = track.Rank ?? 0,
         PlayCount = track.PlayCount ?? 0,
         PictureURL = GetTrackImage(track.Images),
         TrackURL = track.Url.AbsoluteUri,
         ArtistName = track.ArtistName ?? "",
         AlbumName = track.AlbumName ?? ""
     });
 }
예제 #27
0
        public static string TrackToLinkedString(LastTrack track)
        {
            if (track.Url.ToString().IndexOfAny(new[] { '(', ')' }) >= 0)
            {
                return(TrackToString(track));
            }

            return($"[{track.Name}]({track.Url})\n" +
                   $"By **{track.ArtistName}**" +
                   (string.IsNullOrWhiteSpace(track.AlbumName)
                       ? "\n"
                       : $" | *{track.AlbumName}*\n"));
        }
예제 #28
0
        protected string LastTrackToString(LastTrack LastTrack)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(LastTrack.created_at.ToString())
            .Append(FIELD_SEPARATOR)
            .Append(LastTrack.FolderPath)
            .Append(FIELD_SEPARATOR)
            .Append(LastTrack.Artist)
            .Append(FIELD_SEPARATOR)
            .Append(LastTrack.Title);
            return(sb.ToString());
        }
예제 #29
0
        public static async Task <SaveResults> SaveTrackAsync(LastTrack track)
        {
            try
            {
                Song preparedSong = null;
                var  providerId   = track.ToSong().ProviderId;
                if (providerId == "lastid.")
                {
                    preparedSong = await PrepareTrackForDownloadAsync(track);

                    providerId = preparedSong.ProviderId;
                }

                var exists = App.Locator.CollectionService.SongAlreadyExists(
                    providerId,
                    track.Name,
                    track.AlbumName,
                    track.ArtistName);
                if (exists != null)
                {
                    return(new SaveResults()
                    {
                        Error = SavingError.AlreadyExists, Entry = exists
                    });
                }

                if (preparedSong == null)
                {
                    preparedSong = await PrepareTrackForDownloadAsync(track);
                }

                await App.Locator.CollectionService.AddSongAsync(preparedSong).ConfigureAwait(false);

                CollectionHelper.MatchSong(preparedSong);
                return(new SaveResults {
                    Error = SavingError.None, Entry = preparedSong
                });
            }
            catch (NetworkException)
            {
                return(new SaveResults {
                    Error = SavingError.Network
                });
            }
            catch
            {
                return(new SaveResults {
                    Error = SavingError.Unknown
                });
            }
        }
예제 #30
0
        public List <LastTrack> GetCurrentTracksList()
        {
            DbConnection     dbConnection = _MasterDB.MasterDBConnection;
            List <LastTrack> lastTracks   = null;

            using (var qry = dbConnection.CreateCommand())
            {
                qry.CommandText = Queries.QRY_ON_AIR;
                StringBuilder sb = new StringBuilder();

                using (DbDataReader edr = qry.ExecuteReader(CommandBehavior.SequentialAccess))
                {
                    lastTracks = new List <LastTrack>();
                    while (edr.Read())
                    {
                        int       i  = 0;
                        LastTrack lt = new LastTrack();
                        lt.ID         = DBNullHelper.SafeGetString(edr, i++);
                        lt.created_at = edr.GetDateTime(i++);
                        lt.FolderPath = DBNullHelper.SafeGetString(edr, i++).Replace('/', '\\');
                        lt.Title      = DBNullHelper.SafeGetString(edr, i++);
                        lt.Artist     = DBNullHelper.SafeGetString(edr, i++);
                        lt.ImagePath  = edr.GetString(i++).Replace('/', '\\');
                        lt.BPM        = (
                            (double)(DBNullHelper.SafeGetInt32(edr, i++, 0))
                            / 100).ToString("0.00", CultureInfo.InvariantCulture);

                        lt.Rating      = DBNullHelper.SafeGetInt32(edr, i++, 0);
                        lt.ReleaseYear = (edr.IsDBNull(i) ? (int?)null : edr.GetInt32(i));
                        i++;
                        lt.ReleaseDate = DBNullHelper.SafeGetString(edr, i++);
                        lt.Length      = TimeSpan.FromSeconds(edr.GetInt32(i++)).ToString(@"mm\:ss", CultureInfo.InvariantCulture);
                        lt.ColorID     = (edr.IsDBNull(i) ? (int?)null : edr.GetInt32(i));
                        i++;
                        lt.TrackComment = DBNullHelper.SafeGetString(edr, i++);
                        lt.ColorName    = DBNullHelper.SafeGetString(edr, i++);
                        lt.AlbumName    = DBNullHelper.SafeGetString(edr, i++);
                        lt.LabelName    = DBNullHelper.SafeGetString(edr, i++);
                        lt.GenreName    = DBNullHelper.SafeGetString(edr, i++);
                        lt.KeyName      = DBNullHelper.SafeGetString(edr, i++);
                        lt.RemixerName  = DBNullHelper.SafeGetString(edr, i++);
                        lt.Message      = DBNullHelper.SafeGetString(edr, i++);

                        lastTracks.Add(lt);
                    }
                }
            }

            return(lastTracks);
        }