コード例 #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();
                }
            }));
        }
コード例 #2
0
ファイル: AzureService.cs プロジェクト: youngcm2/Sport
        public Task UnregisterAthleteForPush(Athlete athlete)
        {
            return(new Task(() =>
            {
                if (athlete == null || athlete.NotificationRegistrationId == null)
                {
                    return;
                }

                var values = new Dictionary <string, string> {
                    {
                        "id",
                        athlete.NotificationRegistrationId
                    }
                };
                var registrationId = Client.InvokeApiAsync <string>("unregister", HttpMethod.Delete, values).Result;
            }));
        }
コード例 #3
0
        /// <summary>
        /// Gets the athlete's profile from the Azure backend
        /// </summary>
        async Task <Athlete> GetAthletesProfile()
        {
            Athlete athlete = null;

            //Let's try to load based on email address
            if (athlete == null && AuthUserProfile != null && !AuthUserProfile.Email.IsEmpty())
            {
                var task = AzureService.Instance.AthleteManager.GetAthleteByEmail(AuthUserProfile.Email);
                await RunSafe(task);

                if (task.IsCompleted && !task.IsFaulted)
                {
                    athlete = task.Result;
                }
            }

            return(athlete);
        }
コード例 #4
0
        public void CreateChallenge(Athlete challenger, Athlete challengee, League league)
        {
            var time = TimeSpan.FromTicks(DateTime.Now.AddMinutes(60).Subtract(DateTime.Today).Ticks);

            if (time.Ticks > TimeSpan.TicksPerDay)
            {
                time = time.Subtract(TimeSpan.FromTicks(TimeSpan.TicksPerDay));
            }

            SelectedTime = time;
            SelectedDate = DateTime.Today;

            var membership = league.Memberships.SingleOrDefault(m => m.AthleteId == challengee.Id);

            Challenge = new Challenge {
                BattleForRank       = membership.CurrentRank,
                ChallengerAthleteId = challenger.Id,
                ChallengeeAthleteId = challengee.Id,
                ProposedTime        = SelectedDateTime,
                LeagueId            = league.Id,
            };
        }
コード例 #5
0
ファイル: AthleteViewModel.cs プロジェクト: llenroc/Sport-1
 public override void NotifyPropertiesChanged([CallerMemberName] string caller = "")
 {
     _athlete = null;
     SetPropertyChanged("Athlete");
     base.NotifyPropertiesChanged(caller);
 }
コード例 #6
0
		public AthleteLeaguesPage(Athlete athlete)
		{
			//ViewModel is newed up in the ViewModel getter of BaseContentPage
			ViewModel.Athlete = athlete;
			Initialize();
		}
コード例 #7
0
ファイル: Extensions.cs プロジェクト: llenroc/Sport-1
 public static bool CanChallengeAthlete(this Membership membership, Athlete athlete)
 {
     return(membership.GetChallengeConflictReason(athlete) == null);
 }
コード例 #8
0
        //async public Task GetLeagues(bool forceRefresh = false)
        //{
        //	if(Athlete == null)
        //		return;

        //	if(!forceRefresh)
        //	{
        //		Athlete.LocalRefresh();
        //		return;
        //	}

        //	if(IsBusy)
        //		return;

        //	using(new Busy(this))
        //	{
        //		Athlete.LocalRefresh();

        //		var task = AzureService.Instance.GetAllLeaguesForAthlete();
        //		await RunSafe(task);

        //		if(task.IsFaulted)
        //			return;

        //		Athlete.LocalRefresh();
        //		SetPropertyChanged("Athlete");
        //	}

        //	IsBusy = false;
        //}

        public override void NotifyPropertiesChanged([System.Runtime.CompilerServices.CallerMemberName] string caller = "")
        {
            _athlete = null;
            SetPropertyChanged("Athlete");
            base.NotifyPropertiesChanged();
        }
コード例 #9
0
ファイル: Membership.cs プロジェクト: llenroc/Sport-1
 public bool HasExistingChallengeWithAthlete(Athlete athlete)
 {
     return(GetOngoingChallenge(athlete) != null);
 }