コード例 #1
0
        /// <summary>
        /// Processes the user for the specified badge type
        /// </summary>
        /// <param name="badgeType"></param>
        /// <param name="user"></param>
        /// <returns>True if badge was awarded</returns>
        public bool ProcessBadge(BadgeType badgeType, MembershipUser user)
        {
            var databaseUpdateNeeded = false;

            var e = new BadgeEventArgs {
                User = user, BadgeType = badgeType
            };

            EventManager.Instance.FireBeforeBadgeAwarded(this, e);

            if (!e.Cancel)
            {
                if (_badges.ContainsKey(badgeType))
                {
                    if (!RecentlyProcessed(badgeType, user))
                    {
                        databaseUpdateNeeded = true;

                        var badgeSet = _badges[badgeType];

                        foreach (var badgeMapping in badgeSet)
                        {
                            if (!BadgeCanBeAwarded(user, badgeMapping))
                            {
                                continue;
                            }

                            // Instantiate the badge and execute the rule
                            var badge = GetInstance <IBadge>(badgeMapping);

                            // Award badge?
                            if (badge != null && badge.Rule(user))
                            {
                                // Re-fetch the badge otherwise system will try and create new badges!
                                var dbBadge = _badgeRepository.Get(badgeMapping.DbBadge.Id);
                                if (dbBadge.AwardsPoints != null && dbBadge.AwardsPoints > 0)
                                {
                                    var points = new MembershipUserPoints
                                    {
                                        DateAdded = DateTime.UtcNow,
                                        Points    = (int)dbBadge.AwardsPoints
                                    };
                                    user.Points.Add(points);
                                }
                                user.Badges.Add(dbBadge);
                                _activityService.BadgeAwarded(badgeMapping.DbBadge, user, DateTime.UtcNow);

                                EventManager.Instance.FireAfterBadgeAwarded(this,
                                                                            new BadgeEventArgs
                                {
                                    User      = user,
                                    BadgeType = badgeType
                                });
                            }
                        }
                    }
                }
            }
            return(databaseUpdateNeeded);
        }
コード例 #2
0
        private void ShowBadge(object sender, BadgeEventArgs e)
        {
            string urisource;

            Application.Current.Dispatcher.Invoke(delegate
            {
                switch (e.badgeType)
                {
                case BadgeEventArgs.BadgeType.CONNECTED:
                    {
                        urisource = @"pack://*****:*****@"pack://application:,,,/Resources/error-01.png";
                        break;
                    }

                default:
                    {
                        urisource = @"pack://application:,,,/Resources/error-01.png";
                        break;
                    }
                }

                NotifyPic = new BitmapImage();
                NotifyPic.BeginInit();
                NotifyPic.UriSource = new Uri(urisource, UriKind.RelativeOrAbsolute);
                NotifyPic.EndInit();
                NotifyPic.Freeze();
                OnPropertyChanged("NotifyPic");
            });
        }
コード例 #3
0
ファイル: BadgeManager.cs プロジェクト: aliken9/MyZooPets
    /// <summary>
    /// Checks the unlock progress meets the unlock condition
    /// </summary>
    /// <returns><c>true</c>, if new badge unlocked.</returns>
    /// <param name="badge">Badge.</param>
    /// <param name="progress">Progress.</param>
    private bool CheckUnlockProgress(ImmutableDataBadge badge, int progress)
    {
        bool unlockNewBadge = false;

        if (progress >= badge.UnlockCondition) //Check if progress matches unlock conditions
        {
            bool isUnlocked = IsBadgeUnlocked(badge.ID);

            if (!isUnlocked) //Unlock new badges
            {
                DataManager.Instance.GameData.Badge.UpdateBadgeStatus(badge.ID, true, true);
                // Debug.Log("Unlock: " + badge.Name);

                //Send analytics
                Analytics.Instance.BadgeUnlocked(badge.ID);

                //Fire event for UI update
                if (OnNewBadgeUnlocked != null)
                {
                    BadgeEventArgs arg = new BadgeEventArgs(badge);
                    OnNewBadgeUnlocked(this, arg);
                }
                unlockNewBadge = true;
            }
        }
        return(unlockNewBadge);
    }
コード例 #4
0
 /// <summary>
 /// Notifies us that a badge has been earned.
 /// </summary>
 private void OnBadgeEarned(object badgesObj, BadgeEventArgs args)
 {
     _sprite.GetSprite <TextSprite>("Name").Text        = args.Badge.Name;
     _sprite.GetSprite <TextSprite>("Description").Text = args.Badge.Description;
     _animation = _sprite.GetAnimation("Show");
     _animation.Start();
 }
コード例 #5
0
 /// <summary>
 /// Handles the 'BadgeStatusChanged' BadgeController event.
 /// </summary>
 /// <param name="sender">The object sending the event.</param>
 /// <param name="badgeEventArgs">Object containing the badge data.</param>
 private void _onBadgeStatusChanged(object sender, BadgeEventArgs badgeEventArgs)
 {
     if (badgeEventArgs.Badge.AppId == "org.tizen.w-phone")
     {
         _callBadge.SetCounter(badgeEventArgs.Badge.Count);
     }
 }
コード例 #6
0
ファイル: WebView.shared.cs プロジェクト: weavy/weavy-webview
        internal void OnBadgeUpdate(object sender, BadgeEventArgs e)
        {
            var handler = this.BadgeUpdated;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #7
0
ファイル: BadgeService.cs プロジェクト: yaobos/mvcforum
        /// <summary>
        /// Processes the user for the specified badge type
        /// </summary>
        /// <param name="badgeType"></param>
        /// <param name="user"></param>
        /// <returns>True if badge was awarded</returns>
        public bool ProcessBadge(BadgeType badgeType, MembershipUser user)
        {
            var databaseUpdateNeeded = false;

            var e = new BadgeEventArgs {
                User = user, BadgeType = badgeType
            };

            EventManager.Instance.FireBeforeBadgeAwarded(this, e);

            if (!e.Cancel)
            {
                if (_badges.ContainsKey(badgeType))
                {
                    if (!RecentlyProcessed(badgeType, user))
                    {
                        databaseUpdateNeeded = true;

                        var badgeSet = _badges[badgeType];

                        foreach (var badgeMapping in badgeSet)
                        {
                            if (!BadgeCanBeAwarded(user, badgeMapping))
                            {
                                continue;
                            }

                            // Instantiate the badge and execute the rule
                            var badge = GetInstance <IBadge>(badgeMapping);

                            if (badge != null)
                            {
                                var dbBadge = _badgeRepository.Get(badgeMapping.DbBadge.Id);

                                // Award badge?
                                if (badge.Rule(user))
                                {
                                    // Re-fetch the badge otherwise system will try and create new badges!
                                    if (dbBadge.AwardsPoints != null && dbBadge.AwardsPoints > 0)
                                    {
                                        var points = new MembershipUserPoints
                                        {
                                            Points      = (int)dbBadge.AwardsPoints,
                                            PointsFor   = PointsFor.Badge,
                                            PointsForId = dbBadge.Id,
                                            User        = user
                                        };
                                        _membershipUserPointsService.Add(points);
                                    }
                                    user.Badges.Add(dbBadge);
                                    _activityService.BadgeAwarded(badgeMapping.DbBadge, user, DateTime.UtcNow);

                                    EventManager.Instance.FireAfterBadgeAwarded(this,
                                                                                new BadgeEventArgs
                                    {
                                        User      = user,
                                        BadgeType = badgeType
                                    });
                                }
                                //else
                                //{
                                //    // If we get here the user should not have the badge
                                //    // Remove the badge if the user no longer has the criteria to be awarded it
                                //    // and also remove any points associated with it.
                                //    user.Badges.Remove(dbBadge);
                                //    _membershipUserPointsService.Delete(user, PointsFor.Badge, dbBadge.Id);
                                //}
                            }
                        }
                    }
                }
            }
            return(databaseUpdateNeeded);
        }
コード例 #8
0
 private void _EventManagerInstance_AfterBadgeAwarded(object sender, BadgeEventArgs args)
 {
     args.User.Email = TestString;
 }
コード例 #9
0
 private void _EventManagerInstance_BeforeBadgeAwardedAllow(object sender, BadgeEventArgs args)
 {
     args.Cancel = false;
 }
コード例 #10
0
 private void _EventManagerInstance_BeforeBadgeAwardedCancel(object sender, BadgeEventArgs args)
 {
     args.Cancel = true;
 }
コード例 #11
0
ファイル: BadgeService.cs プロジェクト: zhyqhb/mvcforum
        /// <summary>
        ///     Processes the user for the specified badge type
        /// </summary>
        /// <param name="badgeType"></param>
        /// <param name="user"></param>
        /// <returns>True if badge was awarded</returns>
        public async Task <bool> ProcessBadge(BadgeType badgeType, MembershipUser user)
        {
            var databaseUpdateNeeded = false;

            var e = new BadgeEventArgs {
                User = user, BadgeType = badgeType
            };

            EventManager.Instance.FireBeforeBadgeAwarded(this, e);

            if (!e.Cancel)
            {
                try
                {
                    if (_badges.ContainsKey(badgeType))
                    {
                        if (!RecentlyProcessed(badgeType, user))
                        {
                            databaseUpdateNeeded = true;

                            var badgeSet = _badges[badgeType];

                            foreach (var badgeMapping in badgeSet)
                            {
                                if (!BadgeCanBeAwarded(user, badgeMapping))
                                {
                                    continue;
                                }

                                // Instantiate the badge and execute the rule
                                IBadge badge;
                                if (badgeMapping.BadgeClassInstance != null)
                                {
                                    badge = badgeMapping.BadgeClassInstance;
                                }
                                else
                                {
                                    badgeMapping.BadgeClassInstance = UnityHelper.Container.Resolve(badgeMapping.BadgeClass) as IBadge;
                                    badge = badgeMapping.BadgeClassInstance;
                                }

                                if (badge != null)
                                {
                                    var dbBadge = Get(badgeMapping.DbBadge.Id);

                                    // Award badge?
                                    if (badge.Rule(user))
                                    {
                                        // Re-fetch the badge otherwise system will try and create new badges!
                                        if (dbBadge.AwardsPoints != null && dbBadge.AwardsPoints > 0)
                                        {
                                            var points = new MembershipUserPoints
                                            {
                                                Points      = (int)dbBadge.AwardsPoints,
                                                PointsFor   = PointsFor.Badge,
                                                PointsForId = dbBadge.Id,
                                                User        = user
                                            };
                                            var pointsAddResult = await _membershipUserPointsService.Add(points);

                                            if (!pointsAddResult.Successful)
                                            {
                                                _loggingService.Error(pointsAddResult.ProcessLog.FirstOrDefault());
                                                return(false);
                                            }
                                        }
                                        user.Badges.Add(dbBadge);
                                        //_activityService.BadgeAwarded(badgeMapping.DbBadge, user, DateTime.UtcNow);
                                        var badgeActivity =
                                            BadgeActivity.GenerateMappedRecord(badgeMapping.DbBadge, user, DateTime.UtcNow);
                                        _context.Activity.Add(badgeActivity);
                                        EventManager.Instance.FireAfterBadgeAwarded(this,
                                                                                    new BadgeEventArgs
                                        {
                                            User      = user,
                                            BadgeType = badgeType
                                        });
                                    }
                                    //else
                                    //{
                                    //    // If we get here the user should not have the badge
                                    //    // Remove the badge if the user no longer has the criteria to be awarded it
                                    //    // and also remove any points associated with it.
                                    //    user.Badges.Remove(dbBadge);
                                    //    _membershipUserPointsService.Delete(user, PointsFor.Badge, dbBadge.Id);
                                    //}
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _loggingService.Error(ex);
                }
            }
            return(databaseUpdateNeeded);
        }
コード例 #12
0
 /// <summary>
 /// Handles the 'Changed' BadgeControl event.
 /// </summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="badgeEventArgs">Structure containing the badge data.</param>
 private void BadgeControlOnChanged(object sender, BadgeEventArgs badgeEventArgs)
 {
     BadgeStatusChanged?.Invoke(this, badgeEventArgs);
 }
コード例 #13
0
 private void BeforeBadgeAwardedHandler(object sender, BadgeEventArgs eventArgs)
 {
     // Do something
 }