Ejemplo n.º 1
0
        /// <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();
                }
            }));
        }
Ejemplo n.º 2
0
		/// <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 = false)
		{
			return new Task(() =>
			{
				if(athlete == null)
					throw new ArgumentNullException(nameof(Athlete));

				if(athlete.Id == null || athlete.DeviceToken == null)
					return;

				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();
				}
			});
		}