Ejemplo n.º 1
0
        // Discovery of existing sessions
        // Handles the addition, removal, or updating of a session
        public async void DiscoverSessions()
        {
            try
            {
                RemoteSystemAccessStatus status = await RemoteSystem.RequestAccessAsync();

                // Checking that remote system access is allowed - ensure capability in the project manifest is set
                if (status != RemoteSystemAccessStatus.Allowed)
                {
                    SendDebugMessage("Access is denied, ensure the \'bluetooth\' and \'remoteSystem\' capabilities are set.");
                    return;
                }

                //  Create watcher to observe for added, updated, or removed sessions
                m_sessionWatcher          = RemoteSystemSession.CreateWatcher();
                m_sessionWatcher.Added   += RemoteSystemSessionWatcher_RemoteSessionAdded;
                m_sessionWatcher.Removed += RemoteSystemSessionWatcher_RemoteSessionRemoved;
                m_sessionWatcher.Start();
                SendDebugMessage("Session discovery started.");
            }
            catch (Win32Exception)
            {
                SendDebugMessage("Session discovery failed.");
            }
        }
        private static void OnSessionWatcherAdded(RemoteSystemSessionWatcher sender, RemoteSystemSessionAddedEventArgs args)
        {
            DebugString($"Session Added {args.SessionInfo.DisplayName}: {args.SessionInfo.ControllerDisplayName}");
            AvailableSessions.Add(args.SessionInfo);

            SessionListUpdated?.Invoke(null, EventArgs.Empty);
        }
Ejemplo n.º 3
0
 private void RemoteSystemSessionWatcher_RemoteSessionRemoved(RemoteSystemSessionWatcher sender, RemoteSystemSessionRemovedEventArgs args)
 {
     SendDebugMessage($"Session {args.SessionInfo.DisplayName}:{args.SessionInfo.ControllerDisplayName} was ended by host.");
     SessionRemoved(this, new SessionEventArgs()
     {
         SessionInfo = args.SessionInfo
     });
 }
Ejemplo n.º 4
0
 // Discovered sessions are joined, messsge channel established
 private void RemoteSystemSessionWatcher_RemoteSessionAdded(RemoteSystemSessionWatcher sender, RemoteSystemSessionAddedEventArgs args)
 {
     SendDebugMessage($"Discovered Session {args.SessionInfo.DisplayName}:{args.SessionInfo.ControllerDisplayName}.");
     SessionFound(this, new SessionEventArgs()
     {
         SessionInfo = args.SessionInfo
     });
 }
Ejemplo n.º 5
0
 private async void RemoteSystemSessionWatcher_RemoteSessionAdded(RemoteSystemSessionWatcher sender, RemoteSystemSessionAddedEventArgs args)
 {
     Debug.WriteLine($"Discovered Session {args.SessionInfo.DisplayName}:{args.SessionInfo.ControllerDisplayName}.");
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         sessionNames.Add(args.SessionInfo);
         SessionList.ItemsSource = sessionNames;
     });
 }
        public void OnDescoverSessionAsync(object sender, RoutedEventArgs e)
        {
            if (sessionWatcher != null)
            {
                return;
            }

            // 建立 Watcher 來查看有哪些 Sessions 被建立或是刪除
            sessionWatcher = RemoteSystemSession.CreateWatcher();

            sessionWatcher.Added += (s, a) => {
                // 將找到的 RemoteSystemInfo 加入 UI 顯示
                RemoteSystemSessionInfo sessionInfo = a.SessionInfo;

                var addedTask = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    sessionList.Add(sessionInfo);
                });
            };

            sessionWatcher.Removed += (s, a) => {
                // 將已經結束的 session 從 UI 移除
                var removedSession = a.SessionInfo;
                var exist          = sessionList.Where(x => x.ControllerDisplayName == removedSession.ControllerDisplayName && x.DisplayName == removedSession.DisplayName).FirstOrDefault();

                if (exist != null)
                {
                    var removedTask = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        sessionList.Remove(exist);
                    });
                }
            };

            sessionWatcher.Updated += (s, a) => {
                // 講更新的 RemoteSystemInfo 加入到 UI
                var updatedSession = a.SessionInfo;
                var exist          = sessionList.Where(x => x.ControllerDisplayName == updatedSession.ControllerDisplayName && x.DisplayName == updatedSession.DisplayName).FirstOrDefault();

                if (exist != null)
                {
                    var updatedTask = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        sessionList.Remove(exist);
                        sessionList.Add(updatedSession);
                    });
                }
            };

            sessionWatcher.Start();
        }
Ejemplo n.º 7
0
        public void EndSession()
        {
            if (m_currentSession != null)
            {
                m_currentSession.Dispose();
            }

            if (m_sessionWatcher != null)
            {
                m_sessionWatcher.Stop();
                m_sessionWatcher.Added   -= RemoteSystemSessionWatcher_RemoteSessionAdded;
                m_sessionWatcher.Removed -= RemoteSystemSessionWatcher_RemoteSessionRemoved;
                m_sessionWatcher          = null;
            }

            SendDebugMessage("Session ended.");
        }
        public static async Task DiscoverSessionsAsync()
        {
            var status = await RemoteSystem.RequestAccessAsync();

            if (status == RemoteSystemAccessStatus.Allowed)
            {
                _sessionWatcher?.Stop();
                AvailableSessions.Clear();

                _sessionWatcher          = RemoteSystemSession.CreateWatcher();
                _sessionWatcher.Added   += OnSessionWatcherAdded;
                _sessionWatcher.Removed += OnSessionWatcherRemoved;
                _sessionWatcher.Updated += OnSessionWatcherUpdated;

                _sessionWatcher.Start();
            }
        }
Ejemplo n.º 9
0
        public async void DiscoverSessions()
        {
            Debug.WriteLine("InsideSessionDiscovery");
            try
            {
                RemoteSystemAccessStatus status = await RemoteSystem.RequestAccessAsync();

                if (status != RemoteSystemAccessStatus.Allowed)
                {
                    Debug.WriteLine("Access Denied");
                    return;
                }
                m_sessionWatcher        = RemoteSystemSession.CreateWatcher();
                m_sessionWatcher.Added += RemoteSystemSessionWatcher_RemoteSessionAdded;
                m_sessionWatcher.Start();
                Debug.WriteLine("Starting Discovery");
            }
            catch (Win32Exception)
            {
                Debug.WriteLine("Discovery Failed");
            }
        }