public async static Task UpdateScores() { if (!ScoreboardDialog.IsUpdating) { ScoreboardDialog.IsUpdating = true; try { IMobileServiceTable <Score> scoreTable = App.MobileService.GetTable <Score>(); MobileServiceCollection <Score, Score> scores = await scoreTable.ToCollectionAsync(); Database.Current.Scoreboard = scores.OrderByDescending(x => x.PlayerScore).Take(20).ToList(); var myScore = Database.Current.Scoreboard.SingleOrDefault(x => x.DeviceId.ToString() == Database.Current.DeviceId.ToString()); if (myScore != null) { if (myScore.PlayerScore > Database.Current.Player.Score.PlayerScore) { Database.Current.Player.Score = myScore; } } } catch (Exception) { } ScoreboardDialog.IsUpdating = false; } }
public async Task RefreshTelemetryItems() { MobileServiceInvalidOperationException exception = null; try { // This code refreshes the entries in the list view by querying the telemetry2 table. telemetryItems = await telemetryTable .Where (s => (s.Complete == false)) .ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { exception = e; } if (exception != null) { await new MessageDialog(exception.Message, "Error loading items").ShowAsync(); } else { //Sort in descending order = Most recent first .. Ww want the latest value of each sensor var sortedTelemetryItems = telemetryItems .OrderByDescending(telemetryItem => telemetryItem.Id); //Group by sensor name var orderGroups = from p in sortedTelemetryItems group p by p.Sensor into g select new { Category = g.Key, Sensors = g }; //Get only the first item in each group = Most Recent List<Telemetry2> telemetryItemsListMostRecentInGroup = new List<Telemetry2>(); foreach (var key in orderGroups) { telemetryItemsListMostRecentInGroup.Add(key.Sensors.First<Telemetry2>()); //Mark other vakues as complete. Embedded devices then can just get the "incomplete values". for (int i = 1; i < key.Sensors.Count(); i++) { Telemetry2 t2i = key.Sensors.ElementAt<Telemetry2>(i); t2i.Complete = true; await telemetryTable.UpdateAsync(t2i); } } if (listTelemetryPage != null) //Set as displayed list listTelemetryPage.ListItems.ItemsSource = telemetryItemsListMostRecentInGroup.OrderBy(s => s.Id).Reverse(); // telemetryItems; //this.ButtonSave.IsEnabled = true; } }