public static string[][] GetAllItems() { string[][] result = new string[BlacklistManager.GetCount()][]; SQLiteConnection connection = new SQLiteConnection(setConnection); SQLiteCommand command = new SQLiteCommand(getAllItems, connection); connection.Open(); SQLiteDataReader reader = null; try { reader = command.ExecuteReader(); for (int i = 0; reader.Read(); i++) { result[i] = new string[1] { (string)reader["address"] }; } reader.Close(); } catch (SQLiteException) { connection.Close(); BlacklistManager.SetUp(); //should be empty now, so no loop } finally { connection.Close(); } return(result); }
public static bool Contains(string address) { SQLiteConnection connection = new SQLiteConnection(setConnection); SQLiteCommand command = new SQLiteCommand(String.Format(getItemByAddress, address), connection); connection.Open(); SQLiteDataReader reader = null; try { reader = command.ExecuteReader(); while (reader.Read()) { reader.Close(); return(true); } reader.Close(); } catch (SQLiteException) { connection.Close(); BlacklistManager.SetUp(); //should always be empty here, so no loop } finally { connection.Close(); } return(false); }
public void FillList() { string[][] items = BlacklistManager.GetAllItems(); foreach (string[] item in items) { this.blacklistView.Items.Add(new ListViewItem(item)); } }
private void removeButtonClick(object sender, EventArgs e) { ListView.SelectedListViewItemCollection blackListedDevices = blacklistView.SelectedItems; foreach (ListViewItem item in blackListedDevices) { string address = item.SubItems[0].Text; BlacklistManager.Delete(address); } }
public static void SetUp() { SQLiteConnection.CreateFile("blacklist.sqlite"); SQLiteConnection connection = new SQLiteConnection(setConnection); SQLiteCommand command = new SQLiteCommand(createTable, connection); connection.Open(); command.ExecuteNonQuery(); connection.Close(); BlacklistManager.OnChange(); }
private void OnClientConnected(object sender, EventArgs e) { clientEP = server.GetClientEndpoint(); string address = Properties.Settings.Default.bluetooth ? clientEP : clientEP.Split(':')[0]; if (BlacklistManager.Contains(address)) { server.Disconnect(); return; } serverStatus = Status.Connected; this.connectivityChecker.Enabled = true; this.reader.Enabled = true; }
void blackListButton_Click(object sender, EventArgs e) { if (MainContext.ServerStatus != MainContext.Status.Connected) { return; } string address = MainContext.ClientEP; if (!Properties.Settings.Default.bluetooth) { address = address.Split(':')[0]; } GlobalAppEvents.RaiseDisconnectReqeustEvent(this, new EventArgs()); BlacklistManager.Insert(address); }
public static void Delete(string address) { SQLiteConnection connection = new SQLiteConnection(setConnection); connection.Open(); SQLiteCommand command = new SQLiteCommand(String.Format(removeItem, address), connection); try { command.ExecuteNonQuery(); BlacklistManager.OnChange(); } catch (SQLiteException) { connection.Close(); BlacklistManager.SetUp(); } finally { connection.Close(); } }
public static long GetCount() { SQLiteConnection connection = new SQLiteConnection(setConnection); SQLiteCommand command = new SQLiteCommand(getCount, connection); long result = 0; try { connection.Open(); SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); result = (long)reader[0]; reader.Close(); } catch (SQLiteException) { connection.Close(); BlacklistManager.SetUp(); return(0); } finally { connection.Close(); } return(result); }