private async void Refresh()
        {
            // Get the XboxLiveConfiguration that holds the title ID for the current game.
            var xblConfig = XboxLiveAppConfiguration.SingletonInstance;

            titleId = xblConfig.TitleId;
            scid    = xblConfig.ServiceConfigurationId;
            if (!String.IsNullOrEmpty(xblConfig.Sandbox))
            {
                Debug.WriteLine("sandbox: " + xblConfig.Sandbox);
            }

            if (!xboxLiveUser.IsSignedIn)
            {
                try
                {
                    var signInResult = await xboxLiveUser.SignInSilentlyAsync(UIDispatcher);

                    HandleSignInResult(signInResult);
                }
                catch (Exception ex)
                {
                    string errorStr = "Silently sign in failed: " + ex.Message;
                    Debug.WriteLine(errorStr);
                    UpdateCurrentUser();
                    //throw; //Comment to avoid crashing
                }
            }
            else
            {
                UpdateCurrentUser();
            }
        }
Esempio n. 2
0
        public async Task UserSigninSilentlySuccess()
        {
            var user = new XboxLiveUser();

            Assert.IsFalse(user.IsSignedIn);

            AutoResetEvent signinEvent = new AutoResetEvent(false);

            XboxLiveUser.SignInCompleted += (Object o, SignInCompletedEventArgs args) =>
            {
                Assert.AreEqual(args.User, user);
                signinEvent.Set();
            };
            var response = CreateSuccessTokenResponse();

            // Create xbl user with system user
            var silentResult = await user.SignInSilentlyAsync();

            Assert.AreEqual(silentResult.Status, SignInStatus.Success);

            Assert.IsTrue(user.IsSignedIn);
            Assert.AreEqual(user.Gamertag, mockGamerTag);
            Assert.AreEqual(user.XboxUserId, mockXuid);
            Assert.AreEqual(user.AgeGroup, mockAgeGroup);
            Assert.AreEqual(user.Privileges, mockPrivileges);
            Assert.AreEqual(user.WebAccountId, mockWebAccountId);

            Assert.IsTrue(signinEvent.WaitOne(100), "wait signin event time out");
        }
Esempio n. 3
0
        public async Task UserSigninProviderError()
        // provider error
        {
            var user   = new XboxLiveUser();
            var result = new TokenRequestResult(null);

            result.ResponseStatus = WebTokenRequestStatus.ProviderError;
            result.ResponseError  = new WebProviderError(mockErrorcode, mockErrorMessage);

            // ProviderError will convert to exception
            try
            {
                var silentResult = await user.SignInSilentlyAsync();
            }
            catch (XboxException ex)
            {
                Assert.AreEqual(ex.HResult, mockErrorcode);
                Assert.IsFalse(string.IsNullOrEmpty(ex.Message));
                Assert.IsFalse(user.IsSignedIn);

                return;
            }

            Assert.Fail("No exception was thrown.");
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task SignInAsync()
        {
            var signInResult = await m_user.SignInSilentlyAsync();

            if (signInResult.Status == SignInStatus.UserInteractionRequired)
            {
                signInResult = await m_user.SignInAsync();
            }

            if (signInResult.Status == SignInStatus.Success)
            {
                this.OnPropertyChanged("User");

                StatsManager.Instance.AddLocalUser(m_user);

                await SocialManager.Instance.AddLocalUser(this.m_user, SocialManagerExtraDetailLevel.None);

                ulong userId = ulong.Parse(m_user.XboxUserId);
                var   group  = SocialManager.Instance.CreateSocialUserGroupFromList(m_user, new List <ulong> {
                    userId
                });
                m_profile = group.GetUser(userId);
                this.OnPropertyChanged("Profile");

                m_gamerpic = new BitmapImage(new Uri(m_profile.DisplayPicRaw));
                this.OnPropertyChanged("Gamerpic");

                m_context = new XboxLiveContext(m_user);

                m_signedIn = true;
            }
        }
Esempio n. 5
0
        public async Task <SignInStatus> LoginSilentlyAsync()
        {
            var coreDispatcher = Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().CoreWindow.Dispatcher;

            var result = await xboxUser.SignInSilentlyAsync(coreDispatcher);

            return((SignInStatus)result.Status);
        }
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 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.");
        }
        public async void OpenXboxLogin()
        {
            Debug.WriteLine("func start");
            var xboxUser = new XboxLiveUser();

            Debug.WriteLine("use xbox user");
            var dispatcher = CoreApplication.GetCurrentView().CoreWindow.Dispatcher;

            Debug.WriteLine("use core dispatcher");
            var result = await xboxUser.SignInSilentlyAsync(dispatcher);

            Debug.WriteLine("check xbox login result");
            await CheckResult(xboxUser, result);

            Debug.WriteLine("func exit");
            Debug.WriteLine("Logined --> " + Logined);
            Debug.WriteLine("Cancel --> " + LoginCancel);
            Debug.WriteLine("NeedAuth --> " + NeedAuth);
            return;
        }
Esempio n. 9
0
        async void SignInSilently()
        {
            UserInfoLabel.Text = "Trying to sign in silently...";
            Log(UserInfoLabel.Text);

            var allSysUser = await GetAllSystemUser();

            Log(string.Format("Signing in {0} user(s)", allSysUser.Count));
            allSysUser.ToList().ForEach(async user =>
            {
                try
                {
                    XboxLiveUser xboxLiveUser = new XboxLiveUser(user);
                    var signInResult          = await xboxLiveUser.SignInSilentlyAsync(UIDispatcher);
                    HandleSignInResult(signInResult, xboxLiveUser);
                }
                catch (Exception e)
                {
                    Log("SignInSilentlyAsync failed.  Exception: " + e.ToString());
                }
            });
        }
Esempio n. 10
0
        private async void Start()
        {
            Log("Start");

            var allUser = await Windows.System.User.FindAllAsync();

            var validSysUser = allUser.Where(user => (user.Type != Windows.System.UserType.LocalGuest || user.Type != Windows.System.UserType.RemoteGuest)).ToList();

            Log($"Found {validSysUser.Count} system user.");

            validSysUser.ForEach(async user =>
            {
                var id = user.NonRoamableId;

                try
                {
                    Log($"Creating XboxLiveUser id: {id}");
                    XboxLiveUser xboxLiveUser = new XboxLiveUser(user);

                    Log($"Signing in silently, id: {id}");
                    var signInResult = await xboxLiveUser.SignInSilentlyAsync();

                    Log($"Sign in silently result: {signInResult.Status}, id: {id}");

                    if (signInResult.Status == SignInStatus.UserInteractionRequired)
                    {
                        Log($"Signing in with UI, id: {id}");
                        signInResult = await xboxLiveUser.SignInAsync();
                        Log($"Sign in result: {signInResult.Status}, id: {id}");
                    }
                }
                catch (Exception e)
                {
                    Log($"sign in failed, id:{id}, Exception: " + e.ToString());
                }
            });
        }
Esempio n. 11
0
        public async Task XBLSignIn()
        {
            // Get a list of the active Windows users.
            IReadOnlyList <Windows.System.User> users = await Windows.System.User.FindAllAsync();

            // Acquire the CoreDispatcher which will be required for SignInSilentlyAsync and SignInAsync.
            Windows.UI.Core.CoreDispatcher UIDispatcher = Windows.UI.Xaml.Window.Current.CoreWindow.Dispatcher;

            try
            {
                // 1. Create an XboxLiveUser object to represent the user
                xlu = new XboxLiveUser(users[0]);

                // 2. Sign-in silently to Xbox Live
                SignInResult signInSilentResult = await xlu.SignInSilentlyAsync(UIDispatcher);

                switch (signInSilentResult.Status)
                {
                case SignInStatus.Success:
                    HandleSuccessSignIn();
                    break;

                case SignInStatus.UserInteractionRequired:
                    this.viewModel.XblOutput = "Attempt to sign-in with UX";
                    //3. Attempt to sign-in with UX if required
                    SignInResult signInLoud = await xlu.SignInAsync(UIDispatcher);

                    switch (signInLoud.Status)
                    {
                    case SignInStatus.Success:
                        HandleSuccessSignIn();
                        break;

                    case SignInStatus.UserCancel:
                        // present in-game UX that allows the user to retry the sign-in operation. (For example, a sign-in button)
                        this.viewModel.XblOutput = "User cancelled";
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }
                if (this.viewModel.XblSignedIn)
                {
                    // 4. Create an Xbox Live context based on the interacting user
                    xlc = new Microsoft.Xbox.Services.XboxLiveContext(xlu);

                    //add the sign out event handler
                    XboxLiveUser.SignOutCompleted += OnSignOut;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                this.viewModel.XblOutput = e.Message;
            }
        }
Esempio n. 12
0
        public async Task <bool> SignIn()
        {
//            CancelledSignIn = true;

            // Get a list of the active Windows users.
            IReadOnlyList <Windows.System.User> users = await Windows.System.User.FindAllAsync();

            // Acquire the CoreDispatcher which will be required for SignInSilentlyAsync and SignInAsync.
            Windows.UI.Core.CoreDispatcher UIDispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
            //Windows.UI.Xaml.Window.Current.CoreWindow.Dispatcher;
            //CoreApplication.GetCurrentView().CoreWindow.Dispatcher;

            try
            {
                // 1. Create an XboxLiveUser object to represent the user
                //        XboxLiveUser primaryUser = new XboxLiveUser(users[0]);
                primaryUser = new XboxLiveUser();

                // 2. Sign-in silently to Xbox Live
                SignInResult signInSilentResult = await primaryUser.SignInSilentlyAsync(UIDispatcher);

                switch (signInSilentResult.Status)
                {
                case SignInStatus.Success:
                    SignedIn = true;
                    break;

                case SignInStatus.UserInteractionRequired:
                    //3. Attempt to sign-in with UX if required
                    SignInResult signInLoud = await primaryUser.SignInAsync(UIDispatcher);

                    switch (signInLoud.Status)
                    {
                    case SignInStatus.Success:
                        SignedIn = true;
                        break;

                    case SignInStatus.UserCancel:
                        // present in-game UX that allows the user to retry the sign-in operation. (For example, a sign-in button)
//                                CancelledSignIn = true;
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }

                if (SignedIn)
                {
                    // 4. Create an Xbox Live context based on the interacting user
                    xboxLiveContext = new XboxLiveContext(primaryUser);

                    //add the sign out event handler
                    XboxLiveUser.SignOutCompleted += OnSignOut;
                }
            }
            catch (Exception)
            {
//                System.Diagnostics.Debug.WriteLine($"Session#SignIn : Unexpected Exception: {e.Message}");
            }

            return(SignedIn);
        }