Beispiel #1
0
        public AudioTrackContract DownloadAudioBookTrack(DownloadAudioBookTrackContract requestContract)
        {
            m_authorizationManager.AuthorizeBook(requestContract.BookId);
            var audioType = (AudioType)requestContract.RequestedAudioType;
            var book      = m_bookVersionRepository.GetBookWithLastVersion(requestContract.BookId);

            TrackRecording recording = m_bookVersionRepository.GetRecordingByTrackAndAudioType(requestContract.BookId, requestContract.TrackPosition, audioType);

            if (recording == null)
            {
                var message =
                    $"Cannot locate recording'{requestContract.TrackPosition}' for book:'{requestContract.BookId}' of requested type:'{requestContract.RequestedAudioType}'";
                if (m_log.IsErrorEnabled)
                {
                    m_log.ErrorFormat(message);
                }
                throw new ArgumentException(message);
            }

            var stream = m_fileSystemManager.GetResource(book.Guid, book.LastVersion.VersionId, recording.FileName, ResourceType.Audio);

            return(new AudioTrackContract
            {
                FileName = recording.FileName,
                FileData = stream,
                Lenght = recording.Length,
                MimeType = recording.MimeType,
            });
        }
Beispiel #2
0
 public AudioTrackContract DownloadAudioBookTrack(DownloadAudioBookTrackContract requestContract)
 {
     try
     {
         return(Channel.DownloadAudioBookTrack(requestContract));
     }
     catch (CommunicationException ex)
     {
         if (m_log.IsErrorEnabled)
         {
             m_log.ErrorFormat("{0} failed with: {1}", GetCurrentMethod(), ex);
         }
         throw;
     }
     catch (TimeoutException ex)
     {
         if (m_log.IsErrorEnabled)
         {
             m_log.ErrorFormat("{0} failed with: {1}", GetCurrentMethod(), ex);
         }
         throw;
     }
     catch (ObjectDisposedException ex)
     {
         if (m_log.IsErrorEnabled)
         {
             m_log.ErrorFormat("{0} failed with: {1}", GetCurrentMethod(), ex);
         }
         throw;
     }
 }
        public FileResult DownloadAudioBookTrack(long bookId, int trackPosition, AudioTypeContract audioType)
        {
            var audioTrackContract = new DownloadAudioBookTrackContract
            {
                BookId             = bookId,
                RequestedAudioType = audioType,
                TrackPosition      = trackPosition
            };

            using (var client = GetStreamingClient())
            {
                var audioTrack = client.DownloadAudioBookTrack(audioTrackContract);
                var result     = new FileStreamResult(audioTrack.FileData, audioTrack.MimeType)
                {
                    FileDownloadName = audioTrack.FileName
                };
                return(result);
            }
        }
Beispiel #4
0
 public AudioTrackContract DownloadAudioBookTrack(DownloadAudioBookTrackContract requestContract)
 {
     return(m_audioBookManager.DownloadAudioBookTrack(requestContract));
 }