Пример #1
0
        public ICollection<Track> GetTracksByFilters(Filter filter)
        {
            Collection<Track> tracks = null;
            if (filter != null)
            {
                //filter.Value = "17,25,5,14";
                var names = new int[] { 17, 25, 5, 14 };

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT t.LiedID, t.Track, t.Lied ,t.Dauer");
                stringBuilder.Append(" FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" INNER JOIN tunesEntities.titel AS a ON t.TitelID = a.TitelID");
                stringBuilder.Append(" WHERE t.Liedpfad IS NOT NULL");
                //stringBuilder.Append(" AND a.genreid IN (17,25,5,14)");
                
                switch (filter.Mode)
                {
                    case FilterMode.Genre:
                        stringBuilder.Append(" AND a.genreid IN {" + filter.Value + "}");
                        //stringBuilder.Append(" AND a.genreid IN (@filterValue)");
                        break;
                    case FilterMode.Year:
                        break;
                    default:
                        break;
                }

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                   new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            //EntityParameter filterValue = new EntityParameter();
                            //filterValue.ParameterName = "filterValue";
                            //filterValue.Value = filter.Value;
                            //entityCommand.Parameters.Add(filterValue);
                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                // Start reading results.
                                while (dataReader.Read())
                                {
                                    if (tracks == null)
                                    {
                                        tracks = new Collection<Track>();
                                    }
                                    Track track = new Track
                                    {
                                        Id = dataReader.GetInt32("LiedID", false, 0)
                                    };
                                    tracks.Add(track);
                                }
                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }

            }
            return tracks;
        }
Пример #2
0
        private void GetAlbumTracksByTitelId(Album album, System.Data.EntityClient.EntityConnection entityConnection)
        {
            if (album != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT t.LiedID, t.Track, t.Lied ,t.Dauer");
                stringBuilder.Append(" FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" WHERE t.titelid = @albumId");
                stringBuilder.Append(" AND t.Liedpfad IS NOT NULL");
                stringBuilder.Append(" ORDER BY t.Track");
                string sql = stringBuilder.ToString();

                using (EntityCommand entityCommand = entityConnection.CreateCommand())
                {
                    EntityParameter id = new EntityParameter();
                    id.ParameterName = "albumid";
                    id.Value = album.Id;
                    entityCommand.Parameters.Add(id);
                    entityCommand.CommandText = sql;

                    List<Track> tracks = null;
                    using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                    {
                        while (dataReader.Read())
                        {
                            if (tracks == null)
                            {
                                tracks = new List<Track>();
                            }
                            Track track = new Track
                            {
                                Id = dataReader.GetInt32("LiedID", false, 0),
                                TrackNumber = dataReader.GetInt32("Track", false, 0),
                                Name = dataReader.GetString("Lied", false, string.Empty),
                                Duration = dataReader.GetTimeSpan("Dauer", true, TimeSpan.MinValue)
                            };
                            tracks.Add(track);
                        }
                        if (tracks != null)
                        {
                            album.Tracks = tracks.ToArray();
                        }
                    }
                }
            }
        }
Пример #3
0
        public Track GetTrackById(int trackId)
        {
            Track track = null;
            string audioDirectory = this.AudioDirectory;
            if (string.IsNullOrEmpty(audioDirectory) == false)
            {
                StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("SELECT t.LiedID, t.Track, t.Lied ,t.Dauer, t.Liedpfad, t.guid, a.TitelID, a.Titel1, a.Guid as AlbumId, i.Interpret FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" JOIN tunesEntities.titel AS a ON a.TitelID = t.TitelID");
                stringBuilder.Append(" JOIN tunesEntities.interpreten AS i ON a.InterpretID = i.InterpretID");
                stringBuilder.Append(" WHERE t.LiedId = @trackid");

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                        new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter trackIdParam = new EntityParameter();
                            trackIdParam.ParameterName = "trackid";
                            trackIdParam.Value = trackId;
                            entityCommand.Parameters.Add(trackIdParam);

                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                if (dataReader.Read() == true)
                                {
									track = new Track
									{
										Id = dataReader.GetInt32("LiedID", false, 0),
										TrackNumber = dataReader.GetInt32("Track", false, 0),
										Name = dataReader.GetString("Lied", false, string.Empty),
										Duration = dataReader.GetTimeSpan("Dauer", true, TimeSpan.MinValue),
										Guid = dataReader.GetGuid("guid", false, Guid.Empty),
										Album = new Album
										{
											Id = dataReader.GetInt32("TitelID", false, 0),
											Title = dataReader.GetString("Titel1", false, string.Empty),
											AlbumId = dataReader.GetGuid("AlbumId", false, Guid.Empty),
											Artist = new Artist
											{
												Name = dataReader.GetString("Interpret", false, string.Empty)
											}
										}
									};
                                }
                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return track;
        }
Пример #4
0
        public async Task SetTrackAsync(Track track)
        {
            try
            {
                this.m_currentTrack = track;
                if (this.m_currentTrack != null)
                {
                    Guid guid = this.m_currentTrack.Guid;
                    if (guid != null && !guid.Equals(Guid.Empty))
                    {
                        string strUrl = string.Format("{0}/api/files/audio/{1}", this.m_dataService.ServiceUrl, guid.ToString());

                        this.m_audioStreamDownloader = new AudioStreamDownloader(this.m_dataService);
                        this.m_audioStreamDownloader.DownloadProgessStarted += OnDownloadProgessStarted;
                        await m_audioStreamDownloader.DownloadAsync(new Uri(strUrl), guid);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #5
0
 public async Task SetTrackAsync(Track track)
 {
     if (track != null)
     {
         try
         {
             await this.PlayerService.SetTrackAsync(track);
         }
         catch (Exception exception)
         {
             this.m_dialogService.ShowDialog(exception.Message);
         }
     }
 }
Пример #6
0
 public TrackMessage(Track track)
 {
     this.Track = track;
 }
Пример #7
0
 public async Task SetTrackAsync(Track track)
 {
     if (track != null)
     {
         try
         {
             await this.PlayerService.SetTrackAsync(track);
         }
         catch (UnauthorizedAccessException)
         {
             string message = string.Format(CultureInfo.CurrentCulture, this.m_resourceService.GetString("IDS_AudioDirectory_UnauthorizedAccessException"));
             this.m_dialogService.ShowDialog(message);
         }
         catch (Exception exception)
         {
             this.m_dialogService.ShowDialog(exception.Message);
         }
     }
 }
Пример #8
0
        public async Task SetTrackAsync(Track track)
        {
            try
            {
                this.m_currentTrack = track;
                if (this.m_currentTrack != null)
                {
                    Guid guid = this.m_currentTrack.Guid;
                    if (guid != null && !guid.Equals(Guid.Empty))
                    {
                        //string fileName = 
                        //var stream = await this.m_dataService.GetAudioFile(this.m_currentTrack.Guid);
                        //if (stream != null)
                        //{
                        //    var accessStream = await stream.AsRandomAccessStreamAsync();
                        //    this.m_mediaElement.SetSource(accessStream, "application/octet-stream");
                        //}


                        //var accessStream = await this.m_dataService.GetAudioStream(this.m_currentTrack.Guid);
                        //this.m_mediaElement.SetSource(accessStream, "audio/mpeg");

                        var tokenResponse = await this.m_accountService.RefreshToken();

                        string strUrl = string.Format("{0}/api/files/{1}/", this.m_dataService.ServiceUrl, guid.ToString());
                        this.m_mediaElement.Source = new Uri(strUrl);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #9
0
 public TrackChangedArgs(Track track)
 {
     this.Track = track;
 }
Пример #10
0
 private void OnInitializeView(Track track)
 {
     if (track != null)
     {
         Messenger.Default.Send<Track>(track);
         this.CurrentTrack = track;
         this.CurrentTitle = track.Name;
         this.CurrentArtist = track.Album.Artist.Name;
         this.Cover = track.Album.Cover;
     }
 }
Пример #11
0
 public async Task PrepareTrack(Track track)
 {
     try
     {
         Guid guid = track.Guid;
         if (guid != null && !guid.Equals(Guid.Empty))
         {
             string strUrl = string.Format("{0}/api/files/audio/{1}", m_dataService.ServiceUrl, guid.ToString());
             m_audioStreamPreloader = new AudioStreamDownloader(this.m_dataService);
             m_audioStreamPreloader.PreloadComplete += OnPreloadComplete;
             await m_audioStreamPreloader.PreloadAsync(new Uri(strUrl), guid);
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Пример #12
0
 private void LoadCoverSource(Track track)
 {
     if (track != null)
     {
         Uri coverSource = this.DataService.GetImage(track.Album.AlbumId);
         if (coverSource != null && !coverSource.Equals(this.CoverSource))
         {
             this.CoverSource = coverSource;
         }
     }
 }
Пример #13
0
 private void OnInitializeView(Track track)
 {
     if (track != null)
     {
         Messenger.Default.Send<Track>(track);
         this.CurrentTrack = track;
         this.CurrentTitle = track.Name;
         this.CurrentArtist = track.Album.Artist.Name;
         this.CoverSource = this.DataService.GetImage(track.Album.AlbumId);
     }
 }
Пример #14
0
 private void PlayTrack(Track track)
 {
     this.m_playerManager.PlayTrack(track.Id, PlayerMode.Song);
 }