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); }); }
private async void ClientOnConnectionEstablished(BluetoothClient Client, ClientConnectedEventArgs Args) { var connection = Args.Connection; using (var db = new SQLiteConnection(Database.DatabasePath)) { var query = db.Table<Location>().OrderBy(x => x.Timestamp).ToArray(); // First send the number of locations we want to send. await connection.SendUInt32((uint)query.Length); foreach (var location in query) { await connection.SendObject(location); } } // Disconnect }