private void UpdateRemoteDevices(Dictionary <string, Device> remoteDevicesToUpdate) { SQLiteCommand updateRemoteDevices = new SQLiteCommand(sqliteConnection); sqliteConnection.Open(); foreach (KeyValuePair <string, Device> kvp in remoteDevicesToUpdate) { if (remoteDevices.ContainsKey(kvp.Key)) { updateRemoteDevices.CommandText = "UPDATE Remote_Device SET Packets = " + (kvp.Value.Packets + remoteDevices[kvp.Key].Packets) + ", Total_Data = " + (kvp.Value.TotalData + remoteDevices[kvp.Key].TotalData) + " WHERE MAC_Address = " + '\'' + EncryptionHandler.Encrypt(kvp.Value.MAC_Address) b + '\'' + ";"; } else { updateRemoteDevices.CommandText = "INSERT INTO Remote_Device (MAC_Address, IP_Address, Packets, Total_Data) VALUES (" + '\'' + EncryptionHandler.Encrypt(kvp.Value.MAC_Address) + '\'' + "," + '\'' + EncryptionHandler.Encrypt(kvp.Value.IP_Address) + '\'' + "," + kvp.Value.Packets + "," + kvp.Value.TotalData + ");"; } updateRemoteDevices.ExecuteNonQuery(); } sqliteConnection.Close(); }
private void UpdateLocalDevices(Dictionary <string, Device> localDevicesToUpdate) { SQLiteCommand updateLocalDevices = new SQLiteCommand(sqliteConnection); sqliteConnection.Open(); foreach (KeyValuePair <string, Device> kvp in localDevicesToUpdate) { if (localDevices.ContainsKey(kvp.Key)) { updateLocalDevices.CommandText = "UPDATE Local_Device SET Packets = " + (kvp.Value.Packets + localDevices[kvp.Key].Packets) + ", Total_Data = " + (kvp.Value.TotalData + localDevices[kvp.Key].TotalData) + " WHERE MAC_Address = " + '\'' + EncryptionHandler.Encrypt(kvp.Value.MAC_Address) + '\'' + ";"; } else { updateLocalDevices.CommandText = "INSERT INTO Local_Device (MAC_Address, IP_Address, Packets, Total_Data) VALUES (" + '\'' + EncryptionHandler.Encrypt(kvp.Value.MAC_Address) + '\'' + "," + '\'' + EncryptionHandler.Encrypt(kvp.Value.IP_Address) + '\'' + "," + kvp.Value.Packets + "," + kvp.Value.TotalData + ");"; /* * PushbulletClient client = new PushbulletClient("DA API KEY"); * var currentUserInformation = client.CurrentUsersInformation(); * * if (currentUserInformation != null) * { * PushNoteRequest reqeust = new PushNoteRequest() * { * Email = currentUserInformation.Email, * Title = "New Device on network", * Body = "Device Mac: " + kvp.Value.MAC_Address + "\nDevice IP: " + kvp.Value.IP_Address * }; * * PushResponse response = client.PushNote(reqeust); * } */ } updateLocalDevices.ExecuteNonQuery(); } sqliteConnection.Close(); }