/// <summary> /// This app uses Azure as the backend which utilizes Notifications hubs /// </summary> /// <returns>The athlete notification hub registration.</returns> public Task UpdateAthleteNotificationHubRegistration(Athlete athlete, bool forceSave = false, bool sendTestPush = true) { return(new Task(() => { if (athlete == null) { throw new ArgumentNullException(nameof(Athlete)); } if (athlete.Id == null || athlete.DeviceToken == null) { return; } //Add all tags here var tags = new List <string> { athlete.Id, "All", }; App.Instance.CurrentAthlete.LocalRefresh(); App.Instance.CurrentAthlete.Memberships.Select(m => m.LeagueId).ToList().ForEach(tags.Add); athlete.DevicePlatform = Xamarin.Forms.Device.OS.ToString(); var reg = new DeviceRegistration { Handle = athlete.DeviceToken, Platform = athlete.DevicePlatform, Tags = tags.ToArray() }; var registrationId = Client.InvokeApiAsync <DeviceRegistration, string>("registerWithHub", reg, HttpMethod.Put, null).Result; athlete.NotificationRegistrationId = registrationId; if (athlete.IsDirty || forceSave) { var success = AthleteManager.UpsertAsync(athlete).Result; } //Used to verify the device is successfully registered with the backend if (sendTestPush) { var qs = new Dictionary <string, string>(); qs.Add("athleteId", athlete.Id); Client.InvokeApiAsync("sendTestPushNotification", null, HttpMethod.Get, qs).Wait(); } })); }
public async Task <bool> SyncAllAsync() { var list = new List <Task <bool> >(); list.Add(GameResultManager.SyncAsync()); list.Add(ChallengeManager.SyncAsync()); list.Add(MembershipManager.SyncAsync()); list.Add(AthleteManager.SyncAsync()); list.Add(LeagueManager.SyncAsync()); var successes = await Task.WhenAll(list).ConfigureAwait(false); var count = MembershipManager.Table.ToListAsync().Result; return(successes.Any(x => !x)); }
public AzureService() { var url = new Uri(Keys.AzureDomain); var store = new MobileServiceSQLiteStore($"{url.Host}.db"); store.DefineTable <Athlete>(); store.DefineTable <League>(); store.DefineTable <Membership>(); store.DefineTable <Challenge>(); store.DefineTable <GameResult>(); Client.SyncContext.InitializeAsync(store); LeagueManager = new LeagueManager(); MembershipManager = new MembershipManager(); AthleteManager = new AthleteManager(); ChallengeManager = new ChallengeManager(); GameResultManager = new GameResultManager(); }