public void AddLocalUser(XboxLiveUser user)
        {
            if (user == null)
            {
                throw new ArgumentException("user");
            }

            string xboxUserId = user.XboxUserId;

            if (this.userStatContextMap.ContainsKey(xboxUserId))
            {
                throw new ArgumentException("User already in map");
            }

            var context = new StatsUserContext();

            this.userStatContextMap.Add(xboxUserId, context);

            var xboxLiveContext = new XboxLiveContext(user);
            var statsService    = new StatsService(xboxLiveContext);

            context.xboxLiveContext    = xboxLiveContext;
            context.statsService       = statsService;
            context.user               = user;
            context.statsValueDocument = new StatsValueDocument(null);

            statsService.GetStatsValueDocument().ContinueWith(statsValueDocTask =>
            {
                lock (this.userStatContextMap)
                {
                    if (user.IsSignedIn)
                    {
                        if (statsValueDocTask.IsCompleted)
                        {
                            if (this.userStatContextMap.ContainsKey(xboxUserId))
                            {
                                this.userStatContextMap[xboxUserId].statsValueDocument             = statsValueDocTask.Result;
                                this.userStatContextMap[xboxUserId].statsValueDocument.FlushEvent += (sender, e) =>
                                {
                                    if (this.userStatContextMap.ContainsKey(xboxUserId))
                                    {
                                        this.FlushToService(this.userStatContextMap[xboxUserId]);
                                    }
                                };
                            }
                        }
                    }
                }

                this.AddEvent(new StatEvent(StatEventType.LocalUserAdded, user, statsValueDocTask.Exception, new StatEventArgs()));
            });
        }
Ejemplo n.º 2
0
        private StatsManager()
        {
            this.userDocumentMap = new Dictionary <string, StatsValueDocument>();
            this.eventList       = new List <StatEvent>();

            this.statTimer            = new CallBufferTimer <XboxLiveUser>(TimePerCall);
            this.statTimer.Completed += this.TimerCompleteCallback;

            this.statPriorityTimer            = new CallBufferTimer <XboxLiveUser>(TimePerCall);
            this.statPriorityTimer.Completed += this.TimerCompleteCallback;

            this.statsService       = new StatsService();
            this.leaderboardService = new LeaderboardService();

            RunFlushTimer();
        }