예제 #1
0
        public void Store(string originalFileName, string guid)
        {
            string mediaServerUrlBase = ConfigurationManager.AppSettings["MediaServerSaveBaseUrl"];
            string fullName = Path.Combine(mediaServerUrlBase, guid);
            using(SmartPlayerEntities context = new SmartPlayerEntities())
            {
                MusicRepository repo = new MusicRepository(context);

                var allSongs = repo.GetAll()
                    .Select(x => new AnalyzableSong { Id = x.Id, PhysicalFileName = x.Guid })
                    .ToList();

                allSongs.ForEach(x => x.PhysicalFileName = Path.Combine(mediaServerUrlBase, x.PhysicalFileName));

                List<double> correlationCoefficients = Analyzer.GetCorreleationCoefficientsFor(fullName, allSongs);

                Song song = new Song()
                {
                    Name = originalFileName,
                    Guid = guid
                };

                for(int i = 0; i < correlationCoefficients.Count; i++)
                {
                    song.CorrelationsAsPrimary.Add(new SongSongCorrelation { SecondarySongId = allSongs[i].Id, CorrelationScore = correlationCoefficients[i] });
                }

                repo.Create(song);
            }
        }
예제 #2
0
 private PlayerSongDto ExtractSongResult(string username, SmartPlayerEntities context, Song requestedSong, string songUrl)
 {
     PlayerSongDto song = new PlayerSongDto()
     {
         Id = requestedSong.Id,
         Name = requestedSong.Name,
         Url = songUrl,
         CurrentUserVote = GetUserRatingForSong(context, username, requestedSong)
     };
     return song;
 }
예제 #3
0
        private int? GetUserRatingForSong(SmartPlayerEntities context, string username, Song song)
        {
            var currentUser = default(User);
            if (!string.IsNullOrWhiteSpace(username))
            {
                var userRepo = new UserRepository(context);
                currentUser = userRepo.GetUserByUsername(username);
            }

            var songVote = default(int?);
            if (currentUser != null && song.UserSongVotes.Where(x => x.UserId == currentUser.Id).Any())
            {
                songVote = song.UserSongVotes.First(x => x.UserId == currentUser.Id).Rating;
            }

            return songVote;
        }
예제 #4
0
 private static string ExtractSongUrl(Song selectedSong)
 {
     var songUrl = string.Format("http://{0}{1}{2}",
         IpV4Provider.GetLocalIPAddress(),
         ConfigurationManager.AppSettings["MediaServerLoadPort"],
         selectedSong.Guid);
     return songUrl;
 }