コード例 #1
0
        public static void AddSong(Entity.Song song)
        {
            DataAccess.InitializeDatabase();
            using (SqliteConnection db = new SqliteConnection("Filename=songs_manager.db"))
            {
                db.Open();

                SqliteCommand insertCommand = new SqliteCommand();
                insertCommand.Connection = db;

                // Use parameterized query to prevent SQL injection attacks
                insertCommand.CommandText = "INSERT INTO songs (title, description, author, kind, singer, link, thumbnail) VALUES (@title, @description, @author, @kind, @singer, @link, @thumbnail);";
                insertCommand.Parameters.AddWithValue("@title", song.Title);
                insertCommand.Parameters.AddWithValue("@description", song.Description);
                insertCommand.Parameters.AddWithValue("@author", song.Author);
                insertCommand.Parameters.AddWithValue("@kind", song.Kind);
                insertCommand.Parameters.AddWithValue("@singer", song.Singer);
                insertCommand.Parameters.AddWithValue("@link", song.Link);
                insertCommand.Parameters.AddWithValue("@thumbnail", song.Thumbnail);

                insertCommand.ExecuteReader();

                db.Close();
            }
            if (listSong == null)
            {
                listSong = new ObservableCollection <Entity.Song>();
            }
            listSong.Add(song);
        }
コード例 #2
0
        private void Add()
        {
            Console.Clear();

            Entity.Song song = new Entity.Song();
            song.ParentUserId = AuthenticationService.LoggedUser.Id;

            Console.WriteLine("Add new Song:");
            Console.Write("Title: ");
            song.Title = Console.ReadLine();
            Console.Write("Atist Name: ");
            song.ArtistName = Console.ReadLine();
            Console.Write("Year :");
            song.Year = Console.ReadLine();


            SongsRepository songRepository = new SongsRepository("songs.txt");

            songRepository.Save(song);

            Console.WriteLine("Songs saved successfully.");
            Console.ReadKey(true);

            Console.WriteLine("-------------------------------------------");
        }
コード例 #3
0
ファイル: SearchPage.xaml.cs プロジェクト: SlowV/UWPfrontEnd
 private void LoadSong(Entity.Song currentSong)
 {
     this.NowPlaying.Text = "Loading";
     MediaPlayer.Source   = new Uri(currentSong.link);
     Debug.WriteLine(MediaPlayer.NaturalDuration.TimeSpan.TotalSeconds);
     this.NowPlaying.Text = currentSong.name + " - " + currentSong.singer;
 }
コード例 #4
0
        public List <Entity.Song> GetAll(int ParentUserId)
        {
            List <Entity.Song> songs = new List <Entity.Song>();

            FileStream   fs = new FileStream(this.filePath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);

            try
            {
                while (!sr.EndOfStream)
                {
                    Entity.Song song = new Entity.Song();
                    song.Id           = Convert.ToInt32(sr.ReadLine());
                    song.ParentUserId = Convert.ToInt32(sr.ReadLine());
                    song.Title        = sr.ReadLine();
                    song.ArtistName   = sr.ReadLine();
                    song.Year         = sr.ReadLine();

                    if (song.ParentUserId == ParentUserId)
                    {
                        songs.Add(song);
                    }
                }
            }
            finally
            {
                sr.Close();
                fs.Close();
            }

            return(songs);
        }
コード例 #5
0
        private void View()
        {
            Console.Clear();

            Console.Write("Song ID: ");
            int songId = Convert.ToInt32(Console.ReadLine());

            SongsRepository songsRepository = new SongsRepository("songs.txt");

            Entity.Song song = songsRepository.GetById(songId);
            if (song == null)
            {
                Console.Clear();
                Console.WriteLine("Song not found.");
                Console.ReadKey(true);
                return;
            }

            Console.WriteLine("ID:" + song.Id);
            Console.WriteLine("Title :" + song.Title);
            Console.WriteLine("Artist Name :" + song.ArtistName);
            Console.WriteLine("Year :" + song.Year + "y");

            Console.WriteLine("------------------------------------");
            Console.WriteLine();

            Console.ReadKey(true);
        }
コード例 #6
0
        private int GetNextId()
        {
            FileStream   fs = new FileStream(this.filePath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);

            int id = 1;

            try
            {
                while (!sr.EndOfStream)
                {
                    Entity.Song song = new Entity.Song();
                    song.Id           = Convert.ToInt32(sr.ReadLine());
                    song.ParentUserId = Convert.ToInt32(sr.ReadLine());
                    song.Title        = sr.ReadLine();
                    song.ArtistName   = sr.ReadLine();
                    song.Year         = sr.ReadLine();

                    if (id <= song.Id)
                    {
                        id = song.Id + 1;
                    }
                }
            }
            finally
            {
                sr.Close();
                fs.Close();
            }

            return(id);
        }
コード例 #7
0
        public Entity.Song GetById(int Id)
        {
            FileStream   fs = new FileStream(this.filePath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);

            try
            {
                while (!sr.EndOfStream)
                {
                    Entity.Song song = new Entity.Song();
                    song.Id           = Convert.ToInt32(sr.ReadLine());
                    song.ParentUserId = Convert.ToInt32(sr.ReadLine());
                    song.Title        = sr.ReadLine();
                    song.ArtistName   = sr.ReadLine();
                    song.Year         = sr.ReadLine();

                    if (song.Id == Id)
                    {
                        return(song);
                    }
                }
            }
            finally
            {
                sr.Close();
                fs.Close();
            }

            return(null);
        }
コード例 #8
0
        public async static Task <string> Create_Song(Entity.Song song)
        {
            HttpClient httpClient = new HttpClient();
            var        content    = new StringContent(JsonConvert.SerializeObject(song), System.Text.Encoding.UTF8, "application/json");
            var        response   = httpClient.PostAsync(SONG_API_URL, content);
            var        contents   = await response.Result.Content.ReadAsStringAsync();

            Debug.WriteLine(contents);
            return(contents);
        }
コード例 #9
0
        private void Update()
        {
            Console.Clear();

            Console.Write("Song ID: ");
            int songId = Convert.ToInt32(Console.ReadLine());

            SongsRepository songsRepository = new SongsRepository("songs.txt");

            Entity.Song song = songsRepository.GetById(songId);


            if (song == null)
            {
                Console.Clear();
                Console.WriteLine("Song not found.");
                Console.ReadKey(true);
                return;
            }

            Console.WriteLine("Editing Song (" + song.Title + ")");
            Console.WriteLine("ID:" + song.Id);

            Console.WriteLine("Title :" + song.Title);
            Console.Write("New Title:");
            string Title = Console.ReadLine();

            Console.WriteLine("Artist Name :" + song.ArtistName);
            Console.Write("New Artist Name :");
            string ArtistName = Console.ReadLine();

            Console.WriteLine("Year :" + song.Year);
            Console.Write("New Year :");
            string Year = Console.ReadLine();


            if (!string.IsNullOrEmpty(Title))
            {
                song.Title = Title;
            }
            if (!string.IsNullOrEmpty(ArtistName))
            {
                song.ArtistName = ArtistName;
            }
            if (!string.IsNullOrEmpty(Year))
            {
                song.Year = Year;
            }

            songsRepository.Save(song);

            Console.WriteLine("Song saved successfully.");
            Console.ReadKey(true);
        }
コード例 #10
0
 public void Save(Entity.Song item)
 {
     if (item.Id > 0)
     {
         Update(item);
     }
     else
     {
         Insert(item);
     }
 }
コード例 #11
0
        private void Update(Entity.Song item)
        {
            string tempFilePath = "temp." + filePath;

            FileStream   ifs = new FileStream(filePath, FileMode.OpenOrCreate);
            StreamReader sr  = new StreamReader(ifs);

            FileStream   ofs = new FileStream(tempFilePath, FileMode.OpenOrCreate);
            StreamWriter sw  = new StreamWriter(ofs);

            try
            {
                while (!sr.EndOfStream)
                {
                    Entity.Song song = new Entity.Song();
                    song.Id           = Convert.ToInt32(sr.ReadLine());
                    song.ParentUserId = Convert.ToInt32(sr.ReadLine());
                    song.Title        = sr.ReadLine();
                    song.ArtistName   = sr.ReadLine();
                    song.Year         = sr.ReadLine();

                    if (song.Id != item.Id)
                    {
                        sw.WriteLine(song.Id);
                        sw.WriteLine(song.ParentUserId);
                        sw.WriteLine(song.Title);
                        sw.WriteLine(song.ArtistName);
                        sw.WriteLine(song.Year);
                    }
                    else
                    {
                        sw.WriteLine(item.Id);
                        sw.WriteLine(item.ParentUserId);
                        sw.WriteLine(item.Title);
                        sw.WriteLine(item.ArtistName);
                        sw.WriteLine(item.Year);
                    }
                }
            }
            finally
            {
                sw.Close();
                ofs.Close();
                sr.Close();
                ifs.Close();
            }

            File.Delete(filePath);
            File.Move(tempFilePath, filePath);
        }
コード例 #12
0
        private void Insert(Entity.Song item)
        {
            item.Id = GetNextId();

            FileStream   fs = new FileStream(filePath, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);

            try
            {
                sw.WriteLine(item.Id);
                sw.WriteLine(item.ParentUserId);
                sw.WriteLine(item.Title);
                sw.WriteLine(item.ArtistName);
                sw.WriteLine(item.Year);
            }
            finally
            {
                sw.Close();
                fs.Close();
            }
        }
コード例 #13
0
        private void Delete()
        {
            SongsRepository songsRepository = new SongsRepository("songs.txt");

            Console.Clear();

            Console.WriteLine("Delete Task:");
            Console.Write("Task Id: ");
            int taskId = Convert.ToInt32(Console.ReadLine());

            Entity.Song song = songsRepository.GetById(taskId);
            if (song == null)
            {
                Console.WriteLine("Song not found!");
            }
            else
            {
                songsRepository.Delete(song);
                Console.WriteLine("Song deleted successfully.");
            }
            Console.ReadKey(true);
        }
コード例 #14
0
ファイル: SongModel.cs プロジェクト: NamDVD00453/musicbox
        public static ObservableCollection <Entity.Song> GetSongs()
        {
            DataAccess.InitializeDatabase();

            if (listSong == null)
            {
                listSong = new ObservableCollection <Entity.Song>();
            }
            using (SqliteConnection db = new SqliteConnection("Filename=songs_manager.db"))
            {
                db.Open();

                SqliteCommand selectCommand = new SqliteCommand();
                selectCommand.Connection  = db;
                selectCommand.CommandText = "SELECT * FROM songs";
                SqliteDataReader sqliteData = selectCommand.ExecuteReader();
                Entity.Song      song;
                while (sqliteData.Read())
                {
                    song = new Entity.Song {
                        Id          = Convert.ToInt16(sqliteData["id"]),
                        Title       = Convert.ToString(sqliteData["title"]),
                        Description = Convert.ToString(sqliteData["description"]),
                        Author      = Convert.ToString(sqliteData["author"]),
                        Kind        = Convert.ToString(sqliteData["kind"]),
                        Link        = Convert.ToString(sqliteData["link"]),
                        Singer      = Convert.ToString(sqliteData["singer"]),
                        Thumbnail   = Convert.ToString(sqliteData["thumbnail"]),
                    };
                    listSong.Add(song);
                }
                db.Close();
            }
            if (listSong == null)
            {
                listSong = new ObservableCollection <Entity.Song>();
            }
            return(listSong);
        }
コード例 #15
0
        private void Add()
        {
            Console.Clear();

            Entity.Playlist playlist = new Entity.Playlist();
            playlist.ParentUserId = AuthenticationService.LoggedUser.Id;
            PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt");

            Console.WriteLine("Add new Playlist:");
            Console.Write("Name: ");
            playlist.Name = Console.ReadLine();
            Console.Write("Description: ");
            playlist.Description = Console.ReadLine();
            Console.Write("Add Song by Song ID :");
            int songId = Convert.ToInt32(Console.ReadLine());

            SongsRepository songsRepository = new SongsRepository("songs.txt");

            Entity.Song song = songsRepository.GetById(songId);
            if (song == null)
            {
                Console.Clear();
                Console.WriteLine("Song not found.");
                Console.ReadKey(true);
                return;
            }
            playlist.Songs = song.Title + ", " + song.ArtistName + ", " + song.Year + " y.";

            Console.Write("IsPublic: ");
            playlist.IsPublic = Convert.ToBoolean(Console.ReadLine());

            playlistRepository.Save(playlist);

            Console.WriteLine("Playlist saved successfully.");
            Console.ReadKey(true);

            Console.WriteLine("-------------------------------------------");
        }
コード例 #16
0
        private void Update()
        {
            Console.Clear();

            Console.Write("Playlist ID: ");
            int playlistId = Convert.ToInt32(Console.ReadLine());

            PlaylistRepository playlistRepository = new PlaylistRepository("playlist.txt");

            Entity.Playlist playlist = playlistRepository.GetById(playlistId);


            if (playlist == null)
            {
                Console.Clear();
                Console.WriteLine("Playlist not found.");
                Console.ReadKey(true);
                return;
            }

            Console.WriteLine("Editing Playlist (" + playlist.Name + ")");
            Console.WriteLine("ID:" + playlist.Id);

            Console.WriteLine("Name :" + playlist.Name);
            Console.Write("New Name:");
            string Name = Console.ReadLine();

            Console.WriteLine("Description :" + playlist.Description);
            Console.Write("New Description :");
            string Description = Console.ReadLine();

            Console.WriteLine("IsPublic :" + playlist.IsPublic);
            Console.Write("New IsPublic :");
            string IsPublic = Console.ReadLine();


            Console.WriteLine("Add or Remove songs ?");
            string answer = Console.ReadLine();

            if (answer.ToLower() == "add")
            {
                Console.Write("Add Song by Song ID :");
                int songId = Convert.ToInt32(Console.ReadLine());

                SongsRepository songsRepository = new SongsRepository("songs.txt");
                Entity.Song     song            = songsRepository.GetById(songId);
                if (song == null)
                {
                    Console.Clear();
                    Console.WriteLine("Song not found.");
                    Console.ReadKey(true);
                    return;
                }
                playlist.Songs += "  /  " + song.Title + ", " + song.ArtistName + ", " + song.Year + " y.";
                Console.WriteLine("You add the song : " + song.Title + ", " + song.ArtistName + ", " + song.Year + " y. to your playlist!");
            }
            else if (answer.ToLower() == "remove")
            {
                Console.Write("Remove Song by Song Index in Playlist :");
                int songId = Convert.ToInt32(Console.ReadLine());
                //playlist.Songs;
            }


            if (!string.IsNullOrEmpty(Name))
            {
                playlist.Name = Name;
            }
            if (!string.IsNullOrEmpty(Description))
            {
                playlist.Description = Description;
            }

            playlistRepository.Save(playlist);

            Console.WriteLine("Playlist saved successfully.");
            Console.ReadKey(true);
        }