public async Task <GameSaveErrorStatus> Initialize(XboxLiveContext context) { if (context == null) { throw new ArgumentNullException("context"); } // Getting a GameSaveProvider requires the Windows user object. It will automatically get the correct // provider for the current Xbox Live user. var users = await Windows.System.User.FindAllAsync(); if (users.Count > 0) { GameSaveProviderGetResult result = await GameSaveProvider.GetForUserAsync( users[0], context.AppConfig.ServiceConfigurationId); if (result.Status == GameSaveErrorStatus.Ok) { m_context = context; m_saveProvider = result.Value; } return(result.Status); } else { throw new Exception("No Windows users found when creating save provider."); } }
public async void InitializeSaveSystem(XboxLiveContext context) { m_context = context; if (context == null) { LogLine("Resetting save system."); LogLine(""); m_saveManager.Reset(); } else { try { LogLine("Initializing save system..."); GameSaveErrorStatus status = await m_saveManager.Initialize(context); if (status == GameSaveErrorStatus.Ok) { LogLine("Successfully initialized save system."); } else { LogLine(String.Format("InitializeSaveSystem failed: {0}", status)); } } catch (Exception ex) { LogLine("InitializeSaveSystem failed: " + ex.Message); } LogLine(""); } }
/// <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; } }
public IEnumerator SignInAsync() { SignInStatus signInStatus; var signInSilentlyTask = this.User.SignInSilentlyAsync(coreDispatcher).AsTask(); yield return(signInSilentlyTask.AsCoroutine()); if (signInSilentlyTask.IsCompleted) { signInStatus = signInSilentlyTask.Result.Status; if (signInStatus == SignInStatus.UserInteractionRequired) { var signInTask = this.User.SignInAsync(coreDispatcher).AsTask(); yield return(signInTask.AsCoroutine()); if (signInTask.IsCompleted) { signInStatus = signInTask.Result.Status; } } if (signInStatus == SignInStatus.Success) { StatisticManager.SingletonInstance.AddLocalUser(this.User); SocialManager.SingletonInstance.AddLocalUser(this.User, SocialManagerExtraDetailLevel.PreferredColorLevel); this.XboxLiveContext = new XboxLiveContext(this.User); } } }
public static async Task <bool> SignInAsync() { Profile.Gamertag = "Signing in..."; try { _user = new XboxLiveUser(); SignInResult result = await _user.SignInAsync(Window.Current.Dispatcher); if (result.Status == SignInStatus.Success) { _context = new XboxLiveContext(_user); _profile = await _context.ProfileService.GetUserProfileAsync(_context.User.XboxUserId); Profile.Gamertag = _profile.Gamertag; SignedIn = true; Profile.Gamerpic = await GetTexture2dFromUriAsync(_profile.GameDisplayPictureResizeUri); } } catch (Exception ex) { Debug.WriteLine(ex); Profile.Gamertag = "Not logged in"; return(false); } return(true); }
private void signOutPrimaryUser() { // CancelledSignIn = false; SignedIn = false; primaryUser = null; xboxLiveContext = null; mainGameScreen.Mode = MainGameScreen.MainGameScreenMode.ShowSignedOutMessage; }
public SocialGraph(XboxLiveUser localUser, SocialManagerExtraDetailLevel detailLevel) { this.localUser = localUser; this.detailLevel = detailLevel; this.context = new XboxLiveContext(this.localUser); this.peopleHubService = new PeopleHubService(this.context.Settings, this.context.AppConfig); this.eventQueue = new EventQueue(this.localUser); this.internalEventQueue = new InternalEventQueue(); }
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 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 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; }
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"); } } }
public IEnumerator SignInAsync() { this.User = new XboxLiveUser(); TaskYieldInstruction <SignInResult> signInTask = this.User.SignInAsync().AsCoroutine(); yield return(signInTask); // Throw any exceptions if needed. if (signInTask.Result.Status != SignInStatus.Success) { throw new Exception("Sign in Failed"); } this.Context = new XboxLiveContext(this.User); }
private void UpdateCurrentUser() { if (xboxLiveUser != null && xboxLiveUser.IsSignedIn) { XboxLiveUser.SignOutCompleted += XboxLiveUser_SignOutCompleted; xboxLiveContext = new XboxLiveContext(xboxLiveUser); gamertag = xboxLiveUser.Gamertag; Debug.WriteLine("Signed in, gametag: " + gamertag); } else { xboxLiveUser = new XboxLiveUser(); xboxLiveContext = null; gamertag = null; Debug.WriteLine("Please sign in"); //SignIn();//Re-sign for Debug } }
public void RemoveUser(XboxLiveUser user) { lock (m_socialManager) { if (m_socialManagerUserGroup != null) { m_socialManager.DestroySocialUserGroup(m_socialManagerUserGroup); m_socialManagerUserGroup = null; } if (m_user != null) { m_socialManager.RemoveLocalUser(m_user); m_user = null; LogLine("Removing user from graph"); } m_context = null; } }
// Start is called before the first frame update void Start() { #if UNITY_PS4 try { Sony.NP.Main.OnAsyncEvent += OnAsyncEvent; Sony.NP.InitToolkit init = new Sony.NP.InitToolkit(); init.SetPushNotificationsFlags(Sony.NP.PushNotificationsFlags.NewInGameMessage | Sony.NP.PushNotificationsFlags.NewInvitation | Sony.NP.PushNotificationsFlags.UpdateBlockedUsersList | Sony.NP.PushNotificationsFlags.UpdateFriendPresence | Sony.NP.PushNotificationsFlags.UpdateFriendsList); Sony.NP.Main.Initialize(init); PrintLog("\n NpToolkit has been initialized."); } catch (Sony.NP.NpToolkitException e) { Debug.Log("Exception thrown - test past."); PrintLog("\n NpToolkit failed to initialized. Error: " + e.Message); } catch (System.Exception e) { // Unexcepted expection occured. Debug.LogException(e); PrintLog("\n NpToolkit failed to initialized. Error: " + e.Message); } #endif #if ENABLE_WINMD_SUPPORT mCurrentUser = Windows.Xbox.ApplicationModel.Core.CoreApplicationContext.CurrentUser; mContext = new XboxLiveContext(mCurrentUser); #endif #if UNITY_PS4 || ENABLE_WINMD_SUPPORT PrintLog("\n Start Sign-in"); SignIn(); #endif }
internal ProfileService(XboxLiveAppConfiguration config, XboxLiveContext context, XboxLiveContextSettings settings) { this.config = config; this.context = context; this.settings = settings; }
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; } }
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); }
public void Reset() { m_context = null; m_saveProvider = null; }
public void SetXboxLiveContext(XboxLiveContext context) { m_context = context; }
internal StatsService(XboxLiveContext context) { this.config = context.AppConfig; this.context = context; this.settings = context.Settings; }
public SignInCompletedEventArgs(XboxLiveUser user, XboxLiveContext context) { this.User = user; this.Context = context; }