public void SetStatAsNumber(XboxLiveUser user, string statName, double value)
        {
            this.CheckUserValid(user);

            if (statName == null)
            {
                throw new ArgumentException("statName");
            }

            this.userDocumentMap[user.XboxUserId].SetStat(statName, value);
        }
Esempio n. 2
0
 void UpdateSocialGroup(XboxLiveUser user, bool create, PresenceFilter presenceFilter, RelationshipFilter relationshipFilter)
 {
     if (create)
     {
         m_socialManagerUI.CreateSocialGroupFromFilters(user, presenceFilter, relationshipFilter);
     }
     else
     {
         m_socialManagerUI.DestroySocialGroup(user, presenceFilter, relationshipFilter);
     }
 }
Esempio n. 3
0
    private void XblSignInUI_OnUserSignedIn(object sender, XboxLiveUser user)
    {
        m_xboxLiveContext = new Microsoft.Xbox.Services.XboxLiveContext(user);
        xblDataUI.SetXboxLiveContext(m_xboxLiveContext);

#if DEBUG
        m_xboxLiveContext.Settings.EnableServiceCallRoutedEvents = true;
        m_xboxLiveContext.Settings.DiagnosticsTraceLevel         = Microsoft.Xbox.Services.XboxServicesDiagnosticsTraceLevel.Verbose;
        m_xboxLiveContext.Settings.ServiceCallRouted            += Settings_ServiceCallRouted;
#endif
    }
Esempio n. 4
0
        public virtual void TestInitialize()
        {
            const ulong userBase = 0x0099000000000000;

#pragma warning disable CS0675 // Bitwise-or operator used on a sign-extended operand
            string xuid = (userBase | (ulong)this.rng.Next(0, int.MaxValue)).ToString();
#pragma warning restore CS0675 // Bitwise-or operator used on a sign-extended operand
            string gamertag = "Gamer " + xuid;

            this.user    = new XboxLiveUser();
            this.context = new XboxLiveContext(this.user);
        }
        public void SetStatAsString(XboxLiveUser user, string statName, string value)
        {
            this.CheckUserValid(user);

            if (statName == null)
            {
                throw new ArgumentException("statName");
            }

            this.userStatContextMap[user.XboxUserId].statsValueDocument.SetStat(statName, value);
            RequestFlushToService(user);
        }
Esempio n. 6
0
        public async Task UserSigninSilentlyUserInteractionRequired()
        {
            var user   = new XboxLiveUser();
            var result = new TokenRequestResult(null);

            result.ResponseStatus = WebTokenRequestStatus.UserInteractionRequired;

            var signinResult = await user.SignInSilentlyAsync();

            Assert.AreEqual(signinResult.Status, SignInStatus.UserInteractionRequired);
            Assert.IsFalse(user.IsSignedIn);
        }
Esempio n. 7
0
        public async Task UserSigninUIUserCancel()
        {
            var user   = new XboxLiveUser();
            var result = new TokenRequestResult(null);

            result.ResponseStatus = WebTokenRequestStatus.UserCancel;

            var signinResult = await user.SignInAsync();

            Assert.AreEqual(signinResult.Status, SignInStatus.UserCancel);
            Assert.IsFalse(user.IsSignedIn);
        }
Esempio n. 8
0
        public XboxSocialUserGroup CreateSocialUserGroupFromFilters(XboxLiveUser user, PresenceFilter presenceFilter, RelationshipFilter relationshipFilter)
        {
            Dictionary <string, XboxSocialUser> users = Enumerable.Range(0, 5)
                                                        .Select(id =>
            {
                var groupUser = CreateUser();

                switch (presenceFilter)
                {
                case PresenceFilter.AllOnline:
                case PresenceFilter.TitleOnline:
                    InitUserForOnlinePresence(ref groupUser);
                    break;

                case PresenceFilter.AllOffline:
                case PresenceFilter.TitleOffline:
                    InitUserForOfflinePresence(ref groupUser);
                    break;

                case PresenceFilter.AllTitle:
                case PresenceFilter.All:
                    if (id % 2 == 0)
                    {
                        InitUserForOnlinePresence(ref groupUser);
                    }
                    else
                    {
                        InitUserForOfflinePresence(ref groupUser);
                    }
                    break;
                }

                switch (relationshipFilter)
                {
                case RelationshipFilter.Friends:
                    groupUser.IsFollowedByCaller = true;
                    break;

                case RelationshipFilter.Favorite:
                    groupUser.IsFollowedByCaller = true;
                    groupUser.IsFavorite         = true;
                    break;
                }

                return(groupUser);
            }).ToDictionary(u => u.XboxUserId);

            XboxSocialUserGroup group = new XboxSocialUserGroup(user, SocialUserGroupType.Filter, presenceFilter, relationshipFilter, users);

            mEvents.Add(new SocialEvent(SocialEventType.SocialUserGroupLoaded, user, null, group));

            return(group);
        }
        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()));
            });
        }
        public void AddLocalUser(XboxLiveUser user)
        {
            if (user == null)
            {
                throw new ArgumentException("user");
            }

            string xboxUserId = user.XboxUserId;

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

            this.userDocumentMap.Add(xboxUserId, new StatsValueDocument(null));

            this.statsService.GetStatsValueDocument(user).ContinueWith(statsValueDocTask =>
            {
                if (user.IsSignedIn)
                {
                    lock (this.userDocumentMap)
                    {
                        if (this.userDocumentMap.ContainsKey(xboxUserId))
                        {
                            StatsValueDocument document;
                            if (statsValueDocTask.IsFaulted)    // if there was an error, but the user is signed in, we assume offline sign in
                            {
                                document       = this.userDocumentMap[xboxUserId];
                                document.State = StatsValueDocument.StatValueDocumentState.OfflineNotLoaded;
                            }
                            else
                            {
                                document = statsValueDocTask.Result;
                                this.userDocumentMap[xboxUserId].MergeStatDocument(document);
                            }

                            document.FlushEvent += (sender, e) =>
                            {
                                if (this.userDocumentMap.ContainsKey(xboxUserId))
                                {
                                    this.FlushToService(user, document);
                                }
                            };

                            this.userDocumentMap[xboxUserId] = document;
                        }
                    }
                }

                this.AddEvent(new StatEvent(StatEventType.LocalUserAdded, user, statsValueDocTask.Exception, new StatEventArgs()));
            });
        }
Esempio n. 11
0
        public void Enqueue(InternalSocialEvent internalEvent, XboxLiveUser user)
        {
            if (internalEvent == null)
            {
                throw new ArgumentNullException("internalEvent");
            }
            if (internalEvent.Type == InternalSocialEventType.Unknown)
            {
                throw new ArgumentException("Unable to handle Unknown event type.", "internalEvent");
            }

            SocialEventType eventType;

            switch (internalEvent.Type)
            {
            case InternalSocialEventType.UsersAdded:
                eventType = SocialEventType.UsersAddedToSocialGraph;
                break;

            case InternalSocialEventType.UsersRemoved:
                eventType = SocialEventType.UsersRemovedFromSocialGraph;
                break;

            case InternalSocialEventType.PresenceChanged:
            case InternalSocialEventType.DevicePresenceChanged:
            case InternalSocialEventType.TitlePresenceChanged:
                eventType = SocialEventType.PresenceChanged;
                break;

            case InternalSocialEventType.ProfilesChanged:
                eventType = SocialEventType.ProfilesChanged;
                break;

            case InternalSocialEventType.SocialRelationshipsChanged:
                eventType = SocialEventType.SocialRelationshipsChanged;
                break;

            case InternalSocialEventType.Unknown:
            case InternalSocialEventType.UsersChanged:
                // These events are not converted into public events.
                return;

            default:
                throw new ArgumentOutOfRangeException("internalEvent", internalEvent.Type, null);
            }

            SocialEvent evt = new SocialEvent(eventType, user, internalEvent.UserIdsAffected);

            this.events.Enqueue(evt);

            this.State = EventState.ReadyToRead;
        }
        public void RemoveLocalUser(XboxLiveUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            lock (this.syncRoot)
            {
                this.localUsers.Remove(user);
                this.userGraphs.Remove(user);
            }
        }
 public void GetSocialLeaderboard(XboxLiveUser user, string statName, string socialGroup, LeaderboardQuery query)
 {
     this.CheckUserValid(user);
     this.userStatContextMap[user.XboxUserId].xboxLiveContext.LeaderboardService.GetSocialLeaderboardAsync(statName, socialGroup, query).ContinueWith(responseTask =>
     {
         ((StatsManager)Singleton).AddEvent(
             new StatEvent(StatEventType.GetLeaderboardComplete,
                           user,
                           responseTask.Exception,
                           new LeaderboardResultEventArgs(responseTask.Result)
                           ));
     });
 }
        public XboxSocialUserGroup CreateSocialUserGroupFromList(XboxLiveUser user, List <ulong> userIds)
        {
            var group = new XboxSocialUserGroup(user, userIds);

            // Create 'real' users for the userIds
            var users = userIds
                        .Select(CreateUser)
                        .ToDictionary(u => u.XboxUserId);

            group.UpdateView(users, null);

            return(group);
        }
Esempio n. 15
0
        public async Task UserSigninUIUserCancel()
        {
            var user   = new XboxLiveUser();
            var result = new TokenRequestResult(null);

            result.ResponseStatus = WebTokenRequestStatus.UserCancel;
            user.Impl.Provider    = CreateMockAccountProvider(null, result).Object;

            var signinResult = await user.SignInAsync();

            Assert.AreEqual(signinResult.Status, SignInStatus.UserCancel);
            Assert.IsFalse(user.IsSignedIn);
        }
 private void OnPlayerSignOut(XboxLiveUser xboxLiveUser, XboxLiveAuthStatus authStatus, string errorMessage)
 {
     if (authStatus == XboxLiveAuthStatus.Succeeded)
     {
         this.xboxLiveUser = null;
         this.initializing = false;
         lock (this.logText)
         {
             this.logLines.Clear();
             this.logText = string.Empty;
         }
     }
 }
Esempio n. 17
0
 public void GetLeaderboard(XboxLiveUser user, LeaderboardQuery query)
 {
     this.CheckUserValid(user);
     this.leaderboardService.GetLeaderboardAsync(user, query).ContinueWith(responseTask =>
     {
         this.AddEvent(
             new StatEvent(StatEventType.GetLeaderboardComplete,
                           user,
                           responseTask.Exception,
                           new LeaderboardResultEventArgs(responseTask.Result)
                           ));
     });
 }
        public Task <XboxUserProfile> GetUserProfileAsync(XboxLiveUser user, string xboxUserId)
        {
            if (string.IsNullOrEmpty(xboxUserId))
            {
                throw new ArgumentException("invalid xboxUserId", "xboxUserId");
            }

            List <string> profiles = new List <string> {
                xboxUserId
            };

            return(this.GetUserProfilesAsync(user, profiles).ContinueWith(task => task.Result[0]));
        }
Esempio n. 19
0
 public void OnSignOut(object sender, SignOutCompletedEventArgs e)
 {
     // 6. When the game exits or the user signs-out, release the XboxLiveUser object and XboxLiveContext object by setting them to null
     xlu = null;
     xlc = null;
     this.viewModel.XblSignedIn    = false;
     this.viewModel.XboxToken      = string.Empty;
     this.viewModel.HasXblToken    = false;
     this.viewModel.XblOutput      = string.Empty;
     this.viewModel.XblTokenOutput = string.Empty;
     this.viewModel.PFOutput       = string.Empty;
     this.viewModel.GameTag        = string.Empty;
 }
        internal TitleStorageBlobMetadataResult HandleBlobMetadataResult(
            XboxLiveUser user,
            Task <XboxLiveHttpResponse> responseTask,
            TitleStorageType storageType,
            string blobPath)
        {
            var response = responseTask.Result;

            return(TitleStorageBlobMetadataResult.Deserialize(
                       response.ResponseBodyString,
                       storageType,
                       user,
                       blobPath));
        }
Esempio n. 21
0
 public void AddUser(XboxLiveUser user)
 {
     lock (m_socialManager)
     {
         if (m_user == null)
         {
             m_user    = user;
             m_context = new XboxLiveContext(user);
             m_socialManager.AddLocalUser(user, SocialManagerExtraDetailLevel.NoExtraDetail);
             m_socialManagerUserGroup = m_socialManager.CreateSocialUserGroupFromFilters(m_user, PresenceFilter.All, RelationshipFilter.Friends);
             LogLine("Adding user from graph");
         }
     }
 }
Esempio n. 22
0
 /// <summary>
 /// This is set as a XBL Sign out callback in Start()
 /// This will invoke every time a player tries to sign out
 /// </summary>
 /// <param name="user">The XboxLiveUser that is signing out</param>
 /// <param name="status">How did the sign out go? Should be Succeeded if complete.</param>
 /// <param name="errorMessage">What went wrong if not Succeeded</param>
 private void OnXBLSignOut(XboxLiveUser user, XboxLiveAuthStatus status, string errorMessage)
 {
     try {
         Debug.Log("Signed out: " + status);
         if (status == XboxLiveAuthStatus.Succeeded)
         {
             XBL_User               = null;
             XBL_SignedIn           = false;
             signinButton_Text.text = signinToXBLText;
         }
     } catch (Exception ex) {
         Debug.LogError(ex);
     }
 }
Esempio n. 23
0
        public async Task UserSignOut()
        // provider error
        {
            var user = new XboxLiveUser();

            Assert.IsFalse(user.IsSignedIn);

            AutoResetEvent signoutEvent = new AutoResetEvent(false);

            XboxLiveUser.SignOutCompleted += ((Object o, SignOutCompletedEventArgs args) =>
            {
                Assert.AreEqual(args.User, user);
                signoutEvent.Set();
            });

            var successResponse = CreateSuccessTokenResponse();
            var errorResponse   = new TokenRequestResult(null);

            errorResponse.ResponseStatus = WebTokenRequestStatus.UserInteractionRequired;

            var provider = new Mock <AccountProvider>();

            provider
            .SetupSequence(o => o.GetTokenSilentlyAsync(It.IsAny <WebTokenRequest>()))
            .ReturnsAsync(successResponse)
            .ReturnsAsync(errorResponse);

            user.Impl.Provider = provider.Object;

            var silentResult = await user.SignInSilentlyAsync();

            Assert.AreEqual(silentResult.Status, SignInStatus.Success);
            Assert.IsTrue(user.IsSignedIn);

            try
            {
                var token = await user.GetTokenAndSignatureAsync("GET", "", "");
            }
            catch (XboxException ex)
            {
                Assert.IsFalse(string.IsNullOrEmpty(ex.Message));
                Assert.IsFalse(user.IsSignedIn);

                Assert.IsTrue(signoutEvent.WaitOne(100), "wait signout event time out");

                return;
            }

            Assert.Fail("No exception was thrown.");
        }
        private Task SetPresenceHelper(XboxLiveUser user, bool isUserActiveInTitle, PresenceData presenceData)
        {
            var subQuery    = SetPresenceSubPath(user, isUserActiveInTitle);
            var httpRequest = XboxLiveHttpRequest.Create(HttpMethod.Post, UserPresenceBaseUri.ToString(), subQuery);

            httpRequest.ContractVersion = PresenceWriterApiContract;
            httpRequest.XboxLiveAPI     = XboxLiveAPIName.SetPresenceHelper;
            httpRequest.RequestBody     = JsonSerialization.ToJson(new SimplePresenceRequest {
                State = isUserActiveInTitle? "active":"inactive"
            });

            return(httpRequest.GetResponseWithAuth(user).ContinueWith(
                       responseTask => HandleSetPresenceResponse(user, responseTask.Result)));
        }
Esempio n. 25
0
        /// <summary>
        /// Gets a list of blob metadata objects under a given path for the specified service configuration, storage type and storage ID.
        /// </summary>
        /// <param name="user">The Xbox User of the title storage to enumerate. Ignored when enumerating GlobalStorage.</param>
        /// <param name="storageType">The storage type to get blob metadata objects for.</param>
        /// <param name="blobPath">(Optional) The root path to enumerate.  Results will be for blobs contained in this path and all subpaths.</param>
        /// <param name="skipItems">(Optional) The number of items to skip before returning results. (Optional)</param>
        /// <param name="maxItems">(Optional) The maximum number of items to return.</param>
        /// <returns>An instance of the <see cref="TitleStorageBlobMetadataResult"/> class containing the list of enumerated blob metadata objects.</returns>
        public Task <TitleStorageBlobMetadataResult> GetBlobMetadataAsync(XboxLiveUser user, TitleStorageType storageType, string blobPath, uint skipItems = 0, uint maxItems = 0)
        {
            if (this.appConfig == null)
            {
                throw new Exception("App Config is null.");
            }

            if (storageType == TitleStorageType.GlobalStorage && (user == null || !string.IsNullOrEmpty(user.XboxUserId)))
            {
                throw new Exception("Global Storage Type with a non-empty xbox user id");
            }

            return(this.InternalGetBlobMetadata(user, storageType, blobPath, skipItems, maxItems));
        }
Esempio n. 26
0
        public void UpdateUserGroup(XboxLiveUser user, XboxSocialUserGroup group, List <ulong> users)
        {
            if (group.SocialUserGroupType != SocialUserGroupType.UserList)
            {
                throw new ArgumentException("You can only modify the user list for a UserList type social group.");
            }

            this.userGraphs[user].AddUsers(users).ContinueWith(
                addUsersTask =>
            {
                SocialEvent socialEvent = new SocialEvent(SocialEventType.SocialUserGroupUpdated, user, users);
                this.eventQueue.Enqueue(socialEvent);
            });
        }
Esempio n. 27
0
        private void AddUserGroup(XboxLiveUser user, XboxSocialUserGroup group)
        {
            lock (this.syncRoot)
            {
                HashSet <WeakReference> userGroups;
                if (!this.userGroupsMap.TryGetValue(user, out userGroups))
                {
                    this.userGroupsMap[user] = userGroups = new HashSet <WeakReference>();
                }

                WeakReference groupReference = new WeakReference(group);
                userGroups.Add(groupReference);
            }
        }
Esempio n. 28
0
 protected void HandleGetStatHelper(object sender, XboxLiveUserEventArgs args)
 {
     if (this.xboxLiveUser == null)
     {
         this.xboxLiveUser = SignInManager.Instance.GetPlayer(this.PlayerNumber);
     }
     if (this.xboxLiveUser != null && this.xboxLiveUser.IsSignedIn)
     {
         if (args.User.Gamertag == this.xboxLiveUser.Gamertag)
         {
             this.HandleGetStat(args.User, this.ID);
         }
     }
 }
        public void SetStatisticNumberData(XboxLiveUser user, string statName, double value)
        {
            if (!LocalUsers.Contains(user))
            {
                throw new ArgumentException("Local User needs to be added.");
            }

            mChangedStats.Add(new StatisticValue()
            {
                Name     = statName,
                AsNumber = value,
                DataType = StatisticDataType.Number
            });
        }
    private void XblSignInUI_OnUserSignedIn(object sender, XboxLiveUser user)
    {
        m_xboxLiveContext = new Microsoft.Xbox.Services.XboxLiveContext(user);
        xblGameSaveUI.InitializeSaveSystem(m_xboxLiveContext);

        // In a real game, you should also call xblGameSaveUI.InitializeSaveSystem when resuming from
        // suspension, or you may encounter ObjectExpired errors.

#if DEBUG
        m_xboxLiveContext.Settings.EnableServiceCallRoutedEvents         = true;
        XboxLiveServicesSettings.SingletonInstance.DiagnosticsTraceLevel = Microsoft.Xbox.Services.XboxServicesDiagnosticsTraceLevel.Verbose;
        m_xboxLiveContext.Settings.ServiceCallRouted += Settings_ServiceCallRouted;
#endif
    }