Exemple #1
0
        private async void BluetoothServerOnClientConnected(BluetoothServer Server, ClientConnectedEventArgs Args)
        {
            var device = Args.Device;

            _connection = Args.Connection;

            SafeInvoke(() => {
                LogTextBlock.Text = string.Format("Connected to {0} hostname {1} service {2}", device.DisplayName, device.HostName, device.ServiceName);
            });

            var connection = Args.Connection;
            
            // The number of locations to sync
            var count = await connection.ReceiveUInt32();
            
            var app = (App)Application.Current;
            using (var db = new SQLiteConnection(app.DatabasePath))
            {
                for (int i = 0; i < count; ++i)
                {
                    var location = await connection.ReceiveObject<Models.Location>();
                    location.CountryId = _quadtree.Query(new Coordinate((float) location.Longitude, (float) location.Latitude));
                    db.Insert(location);
                }
            }

            SafeInvoke(() =>
            {
                LogTextBlock.Text += string.Format("\n\rSynced {0} locations!", count);
            });
        }
Exemple #2
0
 public MainPage()
 {
     this.InitializeComponent();
     _bluetoothServer = new BluetoothServer(ServiceGUID);
     _bluetoothServer.StateChanged += BluetoothServerOnStateChanged;
     _bluetoothServer.ClientConnected += BluetoothServerOnClientConnected;
     _bluetoothServer.ConnectionError += BluetoothServerOnConnectionError;
     LoadCountriesAndQuadTree();
 }
Exemple #3
0
 private void BluetoothServerOnStateChanged(BluetoothServer Server, BluetoothServer.BluetoothServerState ServerState)
 {
     SafeInvoke(() => {
         ServerStatusTextBlock.Text = ServerState.ToString();
         if (ServerState == BluetoothServer.BluetoothServerState.Advertising || ServerState == BluetoothServer.BluetoothServerState.Connected)
         {
             ToggleServerButton.Content = "Start Bluetooth server";
         }
         else
         {
             ToggleServerButton.Content = "Stop Bluetooth server";
         }
     });
 }
Exemple #4
0
 private void BluetoothServerOnConnectionError(BluetoothServer Sender, Exception Args)
 {
     SafeInvoke(() => {
         LogTextBlock.Text = "Error: " + Args.Message;
     });
 }