public static Fail ( |
||
ex | ||
return | void |
// This performs a query and returns the result. Returns null on failure. public DataTable Query(string sql) { if (conn.State != ConnectionState.Open) { General.Fail("Lost connection to database. Connection state is " + conn.State + "."); return(null); } try { MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.CommandTimeout = QUERY_TIMEOUT; MySqlDataReader reader = cmd.ExecuteReader(); DataTable table = new DataTable(reader); reader.Close(); reader.Dispose(); lastinsertid = cmd.LastInsertedId; cmd.Dispose(); return(table); } catch (MySqlException e) { General.Fail(e, "when querying database"); return(null); } }
// This starts the capturing public void Start() { // DISABLED return; List <PcapDevice> devices = Pcap.GetAllDevices(); if (devices.Count < 1) { General.Fail("No network devices connected."); return; } // Find the device we want to track traffic on foreach (PcapDevice dev in devices) { // Just pick any device that has an address if (dev.Addresses.Count > 0) { trackdevice = dev; } } string addrstr = ""; for (int i = 0; i < trackdevice.Addresses.Count; i++) { if (trackdevice.Addresses[i].Addr.type != SharpPcap.Containers.Sockaddr.Type.HARDWARE) { if (addrstr.Length > 0) { addrstr += ", "; } addrstr += "'" + trackdevice.Addresses[i].Addr.ipAddress + "'"; } } General.WriteLogLine("Tracking network on device '" + trackdevice.Description.Trim() + "' with address " + addrstr); // Start capturing packets trackdevice.Open(true, 1000); trackdevice.OnPacketArrival += PacketHandler; trackdevice.StartCapture(); }
// This performs a query and returns the number of rows affected. Returns -1 on failure. public int Update(string sql) { if (conn.State != ConnectionState.Open) { General.Fail("Lost connection to database. State is " + conn.State); return(-1); } try { MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.CommandTimeout = QUERY_TIMEOUT; int r = cmd.ExecuteNonQuery(); lastinsertid = cmd.LastInsertedId; cmd.Dispose(); return(r); } catch (MySqlException e) { General.Fail(e, "when querying database"); return(-1); } }
// This performs a query and returns the result. Returns null on failure. public object QueryScalar(string sql) { if (conn.State != ConnectionState.Open) { General.Fail("Lost connection to database. State is " + conn.State); return(null); } try { MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.CommandTimeout = QUERY_TIMEOUT; object s = cmd.ExecuteScalar(); lastinsertid = cmd.LastInsertedId; cmd.Dispose(); return(s); } catch (MySqlException e) { General.Fail(e, "when querying database"); return(null); } }
// This finds and updates the available bluetooth devices private void UpdateThread() { BluetoothClient cli; while (true) { // This is allowed to fail when there are no bluetooth devices connected try { cli = new BluetoothClient(); } catch (ThreadInterruptedException) { return; } catch (Exception e) { General.WriteLogLine(e.GetType().Name + " while updating bluetooth manager: " + e.Message + "\r\n" + e.StackTrace); return; } List <ObexBluetoothDevice> newdevices = null; try { cli.Client.ReceiveTimeout = 1000; cli.Client.SendTimeout = 1000; BluetoothDeviceInfo[] peers = cli.DiscoverDevices(ObexTransferDisplayPanel.NUM_DEVICE_BUTTONS, true, true, true); string p = "Found " + peers.Length + " peers: "; int index = 0; newdevices = new List <ObexBluetoothDevice>(); foreach (BluetoothDeviceInfo bdi in peers) { // Make sure the information on this device is accurate! string addrname = bdi.DeviceName.Replace(":", ""); if (addrname == bdi.DeviceAddress.ToString()) { bdi.Refresh(); bdi.Update(); } p += bdi.DeviceName + " "; // Make info struct newdevices.Add(new ObexBluetoothDevice(bdi)); } General.WriteLogLine(p); } catch (ThreadInterruptedException) { return; } #if !DEBUG catch (NotImplementedException e) { // Ignore this, it's probably due to outdated code in the Bluetooth classes made by 'In The Hand' //General.WriteLogLine(e.GetType().Name + " while updating bluetooth devices: " + e.Message); } #endif catch (Exception e) { General.Fail(e, "while updating bluetooth devices"); } // Make the new devices array on success if (newdevices != null) { lock (this) { devicesinfo = newdevices.ToArray(); } } try { Queue <ObexTransferObject> dotransfers = new Queue <ObexTransferObject>(); lock (transferobjects) { while (transferobjects.Count > 0) { dotransfers.Enqueue(transferobjects.Dequeue()); } } while (dotransfers.Count > 0) { ObexTransferObject obj = dotransfers.Peek(); Transfer(obj); dotransfers.Dequeue(); } } catch (ThreadInterruptedException) { return; } #if !DEBUG catch (NotImplementedException e) { // Ignore this, it's probably due to outdated code in the Bluetooth classes made by 'In The Hand' //General.WriteLogLine(e.GetType().Name + " while updating bluetooth devices: " + e.Message); } #endif catch (Exception e) { General.Fail(e, "while transferring bluetooth data"); } try { Thread.Sleep(300); } catch (ThreadInterruptedException) { return; } } }