Beispiel #1
0
        /// <summary>
        /// Obtiene todas las canciones de un usario y su metadata
        /// </summary>
        /// <param name="user_name">
        /// nombre del usuario
        /// </param>
        /// <returns>
        /// Lista de objetos metadata 
        /// </returns>
        public async Task<List<Metadata>> getMetadataSongByUser(string user_name)
        {
            List<Metadata> songs_metadata = new List<Metadata>();

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(server_url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(format));

                HttpResponseMessage response = await client.GetAsync(songs_by_user_path + "/" + user_name);

                MetadataAndSong[] sngs_n_met = await response.Content.ReadAsAsync<MetadataAndSong[]>();

                for (int i = 0; i < sngs_n_met.Length; i++)
                {
                    Metadata song_met = new Metadata();

                    song_met._ID3Artist = (sngs_n_met[i].id3v2_author);

                    song_met._ID3Title = (sngs_n_met[i].id3v2_title);
                    song_met._ID3Album = (sngs_n_met[i].id3v2_album);
                    song_met._ID3Year = (sngs_n_met[i].year.ToString());
                    song_met._ID3Genre = (sngs_n_met[i].id3v2_genre);
                    song_met._ID3Lyrics = (sngs_n_met[i].id3v2_lyrics);
                    song_met._SongID = (sngs_n_met[i].song_id.ToString());
                    song_met._ID3Title = (sngs_n_met[i].song_name);
                    song_met._SongDirectory = (sngs_n_met[i].song_directory);
                    song_met._SubmissionDate = (sngs_n_met[i].submission_date);
                    songs_metadata.Add(song_met);
                }
            }
            return songs_metadata;

        }
        public Version(Metadata met)
        {
            song_id = Convert.ToInt32(met._SongID);

            id3v2_title = met._ID3Title;
            id3v2_author = met._ID3Artist;
            id3v2_album = met._ID3Album;
            id3v2_year = Convert.ToInt32(met._ID3Year);
            id3v2_genre = met._ID3Genre;
            id3v2_lyrics = met._ID3Lyrics;
            submission_date = met._SubmissionDate;
        }
Beispiel #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="met"></param>
        /// <returns></returns>
        public async Task<Song> createVersion(Metadata met)
        {
            Song song;

            Version ver = new Version(met);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(server_url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(format));

                HttpResponseMessage response = await client.PostAsJsonAsync(versions_path, ver);

                if (response.IsSuccessStatusCode)
                {
                    ver = await response.Content.ReadAsAsync<Version>();

                    song = await getSongById(Convert.ToInt32(met._SongID));

                    song.metadata_id = ver.version_id;

                    HttpResponseMessage updsng = await client.PutAsJsonAsync<Song>(songs_path + "/" + song.song_id, song);

                    if (updsng.IsSuccessStatusCode)
                    {
                        Console.WriteLine("\nSe creo correctamente, metadata_id {0}", song.metadata_id);
                    }
                    else
                    {
                        song = null;
                        Console.WriteLine("\nError {0}", updsng.StatusCode);
                    }
                }
                else
                {
                    song = null;
                }

                return song;
            }
        }