Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public void FillList()
 {
     string[][] items = BlacklistManager.GetAllItems();
     foreach (string[] item in items)
     {
         this.blacklistView.Items.Add(new ListViewItem(item));
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
0
        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);
        }