Пример #1
0
        /// <summary>
        /// - Create a DataReader object
        /// - Create an async task to read from the SerialDevice InputStream
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Listen()
        {
            try
            {
                if (serialPort != null)
                {
                    dataReaderObject = new DataReader(serialPort.InputStream);
                    gpsScanner       = new GpsScanner();

                    // keep reading the serial input
                    while (true)
                    {
                        await ReadAsync(ReadCancellationTokenSource.Token);
                    }
                }
            }
            catch (TaskCanceledException ex)
            {
                StatusTextBox.Text = ex.Message;
            }
            catch (Exception ex)
            {
                StatusTextBox.Text = ex.Message;
            }
            finally
            {
                if (dataReaderObject != null)
                {
                    dataReaderObject.DetachStream();
                    dataReaderObject = null;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// AddWifiScanResultsToWifiScannerDatabase adds the Wifi and GPS data to the SQLite database
        /// </summary>
        /// <param name="wifiSignal"></param>
        /// <param name="gpsScanner"></param>
        /// <param name="databaseName"></param>
        /// <param name="tableName"></param>
        private void AddWifiScanResultsToWifiScannerDatabase(WifiSignal wifiSignal, GpsScanner gpsScanner, string databaseName, string tableName)
        {
            using (SqliteConnection database = new SqliteConnection("Filename = " + databaseName))
            {
                try
                {
                    database.Open();
                }
                catch (SqliteException ex)
                {
                    StatusTextBox.Text = ex.Message;
                    throw new Exception("SQL database not opened.");
                }

                // create if table doesn't exist
                SqliteCommand createTable = new SqliteCommand
                {
                    Connection  = database,
                    CommandText = $"CREATE TABLE IF NOT EXISTS {tableName} (Rmc TEXT, Bssid TEXT, NetworkRssiInDecibelMilliwatts REAL, Ssid TEXT)"
                };

                try
                {
                    createTable.ExecuteNonQuery();
                }
                catch (SqliteException ex)
                {
                    StatusTextBox.Text = ex.Message;
                    throw new Exception("SQL table " + tableName + " not created.");
                }

                database.Close(); database.Dispose();
            }

            using (SqliteConnection database = new SqliteConnection("Filename = " + databaseName))
            {
                try
                {
                    database.Open();
                }
                catch (SqliteException ex)
                {
                    StatusTextBox.Text = ex.Message;
                    throw new Exception("SQL database not opened.");
                }

                // insert venue data
                SqliteCommand insertCommand = new SqliteCommand
                {
                    Connection  = database,
                    CommandText = $"INSERT INTO {tableName} (Rmc, Bssid, NetworkRssiInDecibelMilliwatts, Ssid) VALUES (@Rmc, @Bssid, @NetworkRssiInDecibelMilliwatts, @Ssid)"
                };
                insertCommand.Parameters.AddWithValue("@Rmc", gpsScanner.RmcMessage);                                                //string TEXT
                insertCommand.Parameters.AddWithValue("@Bssid", wifiSignal.Bssid);                                                   //string TEXT
                insertCommand.Parameters.AddWithValue("@NetworkRssiInDecibelMilliwatts", wifiSignal.NetworkRssiInDecibelMilliwatts); //double REAL
                // This is for the GUI only
                insertCommand.Parameters.AddWithValue("@Ssid", wifiSignal.Ssid);                                                     //string TEXT

                try
                {
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException ex)
                {
                    StatusTextBox.Text = ex.Message;
                }
                database.Close(); database.Dispose();
            }

            VenueIdTextBox.Text         = tableName;
            OutputTextBlock.ItemsSource = ReadWifiScannerDatabase(databaseName, tableName);
        }