public UserImpl(User systemUser) { if (IsMultiUserApplication) { if (systemUser == null) { throw new XboxException("Xbox Live User object is required to be constructed by a Windows.System.User object for a multi-user application."); } //Initiate user watcher if (userWatcher == null) { userWatcher = User.CreateWatcher(); userWatcher.Removed += UserWatcher_UserRemoved; } } this.CreationContext = systemUser; // TODO: This config is broken. var appConfig = XboxLiveAppConfiguration.Instance; this.AuthConfig = new AuthConfig { Sandbox = appConfig.Sandbox, EnvironmentPrefix = appConfig.EnvironmentPrefix, Environment = appConfig.Environment, UseCompactTicket = appConfig.UseFirstPartyToken }; }
public UserImpl(EventHandler <SignInCompletedEventArgs> signInCompleted, EventHandler <SignOutCompletedEventArgs> signOutCompleted, User systemUser, XboxLiveUser xboxLiveuser) { if (systemUser == null && IsMultiUserApplication()) { throw(new XboxException("Xbox Live User object is required to be constructed by a Windows.System.User object for a multi-user application.")); } //Initiate user watcher if (IsMultiUserApplication()) { if (userWatcher == null) { userWatcher = Windows.System.User.CreateWatcher(); userWatcher.Removed += UserWatcher_UserRemoved; } } this.signInCompleted = signInCompleted; this.signOutCompleted = signOutCompleted; this.CreationContext = systemUser; this.UserWeakReference = new WeakReference(xboxLiveuser); var appConfig = XboxLiveAppConfiguration.Instance; this.AuthConfig = new AuthConfig { Sandbox = appConfig.Sandbox, EnvrionmentPrefix = appConfig.EnvironmentPrefix, Envrionment = appConfig.Environment, UseCompactTicket = appConfig.UseFirstPartyToken }; }
private async void OnEnumerationCompleted(UserWatcher sender, Object e) { // UI work must happen on the UI thread. await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { rootPage.NotifyUser("Enumeration complete. Watching for changes...", NotifyType.StatusMessage); }); }
private async void OnWatcherStopped(UserWatcher sender, Object e) { // UI work must happen on the UI thread. await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { StopWatching(); }); }
private static void UserWatcher_UserRemoved(UserWatcher sender, UserChangedEventArgs args) { UserImpl signoutUser; if (trackingUsers.TryGetValue(args.User.NonRoamableId, out signoutUser)) { signoutUser.UserSignedOut(); } }
private async void OnUserRemoved(UserWatcher sender, UserChangedEventArgs e) { User user = e.User; // UI work must happen on the UI thread. await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { // Look for the user in our collection and remove it. UserViewModel model = FindModelByUserId(user.NonRoamableId); if (model != null) { Users.Remove(model); } }); }
private async void OnUserUpdated(UserWatcher sender, UserChangedEventArgs e) { User user = e.User; // UI work must happen on the UI thread. await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async() => { // Look for the user in our collection and update the display name. UserViewModel model = FindModelByUserId(user.NonRoamableId); if (model != null) { model.DisplayName = await GetDisplayNameOrGenericNameAsync(user); } }); }
private void StartWatching() { rootPage.NotifyUser("", NotifyType.StatusMessage); userNumber = 1; Users.Clear(); userWatcher = User.CreateWatcher(); userWatcher.Added += OnUserAdded; userWatcher.Updated += OnUserUpdated; userWatcher.Removed += OnUserRemoved; userWatcher.EnumerationCompleted += OnEnumerationCompleted; userWatcher.Stopped += OnWatcherStopped; userWatcher.Start(); StartButton.IsEnabled = false; StopButton.IsEnabled = true; }
private void StopWatching() { if (userWatcher != null) { // Unregister all event handlers in case events are in flight. userWatcher.Added -= OnUserAdded; userWatcher.Updated -= OnUserUpdated; userWatcher.Removed -= OnUserRemoved; userWatcher.EnumerationCompleted -= OnEnumerationCompleted; userWatcher.Stopped -= OnWatcherStopped; userWatcher.Stop(); userWatcher = null; Users.Clear(); StartButton.IsEnabled = true; StopButton.IsEnabled = false; } }
private async void OnUserAdded(UserWatcher sender, UserChangedEventArgs e) { User user = e.User; // UI work must happen on the UI thread. await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async() => { // Create the user with "..." as the temporary display name. // Add it right away, because it might get removed while the // "await GetDisplayNameOrGenericNameAsync()" is running. var model = new UserViewModel(user.NonRoamableId, "\u2026"); Users.Add(model); // Try to get the display name. model.DisplayName = await GetDisplayNameOrGenericNameAsync(user); }); }
public UserWatcherEvents(UserWatcher This) { this.This = This; }
private async void OnUserUpdated(UserWatcher sender, UserChangedEventArgs e) { User user = e.User; // UI work must happen on the UI thread. await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async () => { // Look for the user in our collection and update the display name. UserViewModel model = FindModelByUserId(user.NonRoamableId); if (model != null) { model.DisplayName = await GetDisplayNameOrGenericNameAsync(user); } }); }
private async void OnUserAdded(UserWatcher sender, UserChangedEventArgs e) { User user = e.User; // UI work must happen on the UI thread. await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async () => { // Create the user with "..." as the temporary display name. // Add it right away, because it might get removed while the // "await GetDisplayNameOrGenericNameAsync()" is running. var model = new UserViewModel(user.NonRoamableId, "\u2026"); Users.Add(model); // Try to get the display name. model.DisplayName = await GetDisplayNameOrGenericNameAsync(user); }); }