Example #1
0
        public static Objects.Record UploadFile(string fileDir, string name, string extension)
        {
            using (LiteDatabase db = new LiteDatabase(DATABASE_LOCATION))
            {
                var records = db.GetCollection <Objects.Record>(MEDIA_TABLE);

                Objects.Record record = new Objects.Record(name.GetHashCode().ToString(), name, fileDir, extension, DateTime.Now);

                bool success = false;

                success = records.Upsert(record);

                if (db.FileStorage.Exists(name.GetHashCode().ToString()))
                {
                    db.FileStorage.Delete(name.GetHashCode().ToString());
                }

                try
                {
                    db.FileStorage.Upload(name.GetHashCode().ToString(), name);
                } catch (Exception e)
                {
                    success = false;
                    Console.Write(e);
                }

                if (!success)
                {
                    return(record);
                }
                return(null);
            }
        }
Example #2
0
        public static void RemoveRecordFromPlaylist(string playlistName, string songName)
        {
            using (LiteDatabase db = new LiteDatabase(DATABASE_LOCATION))
            {
                var playlistTable     = db.GetCollection <Objects.Playlist>(PLAYLIST_TABLE);
                var playlistSongTable = db.GetCollection <Objects.PlaylistSong>(PLAYLIST_SONG_TABLE);
                var recordTable       = db.GetCollection <Objects.Record>(MEDIA_TABLE);

                Objects.Playlist playlist = playlistTable.FindOne(x => x.id.Equals(playlistName.GetHashCode().ToString()));
                Objects.Record   record   = recordTable.FindOne(x => x.id.Equals(songName.GetHashCode().ToString()));

                playlistSongTable.Delete(x => x.playlistId.Equals(playlist.id) && x.mediaId.Equals(record.id));
            }
        }
Example #3
0
        public static void SetRecordToPlaylist(string playlistName, ArrayList records)
        {
            using (LiteDatabase db = new LiteDatabase(DATABASE_LOCATION))
            {
                var playlistTable     = db.GetCollection <Objects.Playlist>(PLAYLIST_TABLE);
                var playlistSongTable = db.GetCollection <Objects.PlaylistSong>(PLAYLIST_SONG_TABLE);
                var recordTable       = db.GetCollection <Objects.Record>(MEDIA_TABLE);

                foreach (string recordName in records)
                {
                    Objects.Playlist     playlist     = playlistTable.FindById(playlistName.GetHashCode().ToString());
                    Objects.Record       record       = recordTable.FindById(recordName.GetHashCode().ToString());
                    Objects.PlaylistSong playlistSong = new Objects.PlaylistSong(playlist.id + record.id, record.id, playlist.id);
                    playlistSongTable.Upsert(playlistSong);
                }
            }
        }
        private void BtnUpload_Click(object sender, EventArgs e)
        {
            ArrayList failed = new ArrayList();

            foreach (DataGridViewRow row in lstFiles.SelectedRows)
            {
                Objects.Record record = DatabaseManager.UploadFile(row.Cells[1].Value.ToString(),
                                                                   row.Cells[2].Value.ToString(), row.Cells[3].Value.ToString());
                if (record == null)
                {
                    failed.Add(row.Cells[2].Value.ToString());
                }
            }
            if (failed.Count >= 1)
            {
                ShowPopup(failed);
            }
            else
            {
                MessageBox.Show("Records added successfully");
            }
        }