public async Task Download(AudioBookDetailResult book)
        {
            var newBook = _audioBooks.Where(a => a.Book.Id == book.Id).FirstOrDefault();

            if (newBook == null)
            {
                newBook = new MyAudioBook
                {
                    Book              = book,
                    Path              = $"{Session.Instance.GetDataDir()}",
                    Filename          = $"{book.Id}.zip",
                    TmpFolder         = null,
                    Progress          = 0,
                    StatusDescription = "Pendiente de descarga",
                    ErrorCode         = 0,
                    StatusKey         = STATUS_PENDING
                };

                _audioBooks.Add(newBook);
            }
            else
            {
                newBook.TmpFolder         = null;
                newBook.Progress          = 0;
                newBook.StatusDescription = "Pendiente de descarga";
                newBook.ErrorCode         = 0;
                newBook.StatusKey         = STATUS_PENDING;
            }

            OnProgress?.Invoke(newBook);

            // save books
            await SaveBooks();

            // process download queue
#pragma warning disable 4014
            Task.Run(() => ProcessDownloadQueue());
#pragma warning restore 4014
        }
Exemple #2
0
        public async Task <AudioBookDetailResult> GetBookDetail(string id)
        {
            AudioBookDetailResult result = new AudioBookDetailResult();

            using (SqlConnection connection = new SqlConnection(
                       _connectionString))
            {
                SqlCommand commandDeatils = new SqlCommand($@"SELECT LHA.numero 'id', LHA.titulo, LHA.comentario, LHA.id_autor, LHA.horas, LHA.minutos,
                       SIA.nombre 'autor', SIE.nombre 'editorial'
                       FROM LH_audioteca LHA
                       INNER JOIN SI_autores SIA ON SIA.id = LHA.id_autor
                       INNER JOIN SI_editoriales SIE ON SIE.id = LHA.id_editorial
                       WHERE LHA.activo=1 AND LHA.numero=${id}",
                                                           connection);

                connection.Open();

                using SqlDataReader reader = await commandDeatils.ExecuteReaderAsync();

                while (reader.Read())
                {
                    result.Author = new AuthorModel
                    {
                        Id   = reader[3].ToString().Trim(),
                        Name = reader[6].ToString().Trim()
                    };
                    result.Comments    = reader[2].ToString().Trim();
                    result.Editorial   = reader[7].ToString().Trim();
                    result.Id          = reader[0].ToString().Trim();
                    result.LengthHours = Convert.ToInt32(reader[4]);
                    result.LengthMins  = Convert.ToInt32(reader[5]);
                    result.Title       = reader[1].ToString().Trim();
                }
            }

            return(result);
        }