Esempio n. 1
0
        private async void Search_Clicked(object sender, RoutedEventArgs e)
        {
            // Disable the Search button while watcher is being started to avoid a potential
            // race condition of having two RemoteSystemWatchers running in parallel.
            Button searchButton = sender as Button;

            searchButton.IsHitTestVisible = false;

            // Cleaning up any existing systems from previous searches.
            SearchCleanup();

            // Verify access for Remote Systems.
            // Note: RequestAccessAsync needs to called from the UI thread.
            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                if (HostNameSearch.IsChecked.Value)
                {
                    await SearchByHostNameAsync();
                }
                else
                {
                    SearchByRemoteSystemWatcher();
                }
            }
            else
            {
                UpdateStatus("Access to Remote Systems is " + accessStatus.ToString(), NotifyType.ErrorMessage);
            }

            searchButton.IsHitTestVisible  = true;
            DeviceInfoTextBlock.Visibility = Visibility.Visible;
        }
        private async void btnGetDevices_Click(object sender, RoutedEventArgs e)
        {
            RemoteSystems.Clear();
            // Verify access for Remote Systems.
            // Note: RequestAccessAsync needs to called from the UI thread.
            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus != RemoteSystemAccessStatus.Allowed)
            {
                return;
            }

            if (remoteSystemWatcher != null)
            {
                remoteSystemWatcher.Stop();
                remoteSystemWatcher = null;
            }

            // Build a watcher to continuously monitor for all remote systems.
            remoteSystemWatcher = RemoteSystem.CreateWatcher();

            remoteSystemWatcher.RemoteSystemAdded   += M_remoteSystemWatcher_RemoteSystemAdded;
            remoteSystemWatcher.RemoteSystemRemoved += M_remoteSystemWatcher_RemoteSystemRemoved;
            remoteSystemWatcher.RemoteSystemUpdated += M_remoteSystemWatcher_RemoteSystemUpdated;

            // Start the watcher.
            remoteSystemWatcher.Start();
        }
Esempio n. 3
0
        public async Task <bool> Initialize()
        {
            if (_remoteSystemWatcher != null)
            {
                return(true);
            }

            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                // Construct a user type filter that includes anonymous devices
                //RemoteSystemAuthorizationKindFilter authorizationKindFilter = new RemoteSystemAuthorizationKindFilter(RemoteSystemAuthorizationKind.Anonymous);
                //_remoteSystemWatcher = RemoteSystem.CreateWatcher((new IRemoteSystemFilter[] { authorizationKindFilter }));

                _remoteSystemWatcher = RemoteSystem.CreateWatcher();
                _remoteSystemWatcher.RemoteSystemAdded   += RemoteSystemWatcher_RemoteSystemAdded;
                _remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;
                _remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;
                _remoteSystemWatcher.Start();

                if (timer == null)
                {
                    timer = new Timer(Timer_Tick, null, (int)delayBeforeTimerBegin.TotalMilliseconds, (int)refreshInterval.TotalMilliseconds);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        /// <summary>

        /// Signs in the current user.

        /// </summary>

        /// <returns></returns>



        private async void discoverDevices()
        {
            //Describes what happens when the button in the application is clicked
            //Verify Access for Remote Systems
            //RequestAccessAsync() is a method within the
            //RemoteSystem class that gets the status of calling app's access to the RemoteSystem feature
            RemoteSystemAccessStatus accessStat = await RemoteSystem.RequestAccessAsync();

            int accessInt = (int)accessStat;

            if (accessStat == RemoteSystemAccessStatus.Allowed)
            {
                //build a watcher to monitor for remote systems
                remoteSystemWatcher = RemoteSystem.CreateWatcher();
                // Start the watcher.
                remoteSystemWatcher.Start();
                //events for changes in remote system discovery
                remoteSystemWatcher.RemoteSystemAdded   += RemoteSystemWatcher_RemoteSystemAdded;
                remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;
            }
            else
            {
                var errDialog = new MessageDialog("Cannot access Remote Systems.." + accessInt.ToString());
                await errDialog.ShowAsync();
            }
        }
Esempio n. 5
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.");
            }
        }
Esempio n. 6
0
        public async Task BuildDeviceList()
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                if (DeviceList != null)
                {
                    DeviceList.Clear();
                }
                RaisePropertyChanged("ShowEmptyErrorMessage");
            });

            if (m_remoteSystemWatcher != null)
            {
                m_remoteSystemWatcher.Stop();
            }
            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                m_remoteSystemWatcher = RemoteSystem.CreateWatcher();
                // Subscribing to the event raised when a new remote system is found by the watcher.
                m_remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded;
                // Subscribing to the event raised when a previously found remote system is no longer available.
                m_remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;
                m_remoteSystemWatcher.Start();
            }
        }
Esempio n. 7
0
        // Creates a new session, shared experience, for particpants to join
        // Handles incoming requests to join the newly created session
        public async Task <bool> CreateSession(string sessionName)
        {
            bool status = false;
            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            // Checking that remote system access is allowed - ensure capability in the project manifest is set
            if (accessStatus != RemoteSystemAccessStatus.Allowed)
            {
                return(status);
            }

            m_currentSessionName = sessionName;
            SendDebugMessage($"Creating session {m_currentSessionName}...");
            var manager = new RemoteSystemSessionController(m_currentSessionName);

            // Handles incoming requests to join the session.
            manager.JoinRequested += Manager_JoinRequested;

            try
            {
                // Create session
                RemoteSystemSessionCreationResult createResult = await manager.CreateSessionAsync();

                if (createResult.Status == RemoteSystemSessionCreationStatus.Success)
                {
                    RemoteSystemSession currentSession = createResult.Session;
                    // Handles disconnect
                    currentSession.Disconnected += (sender, args) =>
                    {
                        SessionDisconnected(sender, args);
                    };

                    m_currentSession = currentSession;

                    SendDebugMessage($"Session {m_currentSession.DisplayName} created successfully.");

                    status = true;
                }
                // Session creation has reached a maximum - message user that there are too many sessions
                else if (createResult.Status == RemoteSystemSessionCreationStatus.SessionLimitsExceeded)
                {
                    status = false;
                    SendDebugMessage("Session limits exceeded.");
                }
                // Failed to create the session
                else
                {
                    status = false;
                    SendDebugMessage("Failed to create session.");
                }
            }
            catch (Win32Exception)
            {
                status = false;
                SendDebugMessage("Failed to create session.");
            }

            return(status);
        }
        private async void StartWatch()
        {
            RemoteSystemAccessStatus Status = await RemoteSystem.RequestAccessAsync();

            Watcher = RemoteSystem.CreateWatcher();
            Watcher.RemoteSystemAdded   += Watcher_RemoteSystemAdded;
            Watcher.RemoteSystemRemoved += Watcher_RemoteSystemRemoved;
            Watcher.Start();
        }
Esempio n. 9
0
        internal static async void SelectOption(string text)
        {
            switch (currentState)
            {
            case AppState.selectingURL:
                currentURL = text;
                RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

                if (accessStatus == RemoteSystemAccessStatus.Allowed)
                {
                    var remoteSystemWatcher = RemoteSystem.CreateWatcher();
                    remoteSystemWatcher.RemoteSystemAdded   += RemoteSystemWatcher_RemoteSystemAdded;
                    remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;
                    remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;
                    remoteSystemWatcher.Start();
                    (currentPage as SelectList).setMessage("Finding devices");
                    (currentPage as SelectList).setList(startingDevices);
                    currentState = AppState.selectingDevice;
                }
                else
                {
                    (currentPage as SelectList).setMessage("Select a device");
                    (currentPage as SelectList).setList(startingDevices);
                    currentState = AppState.selectingDevice;
                }
                break;

            case AppState.selectingDevice:
                var downloadUrl = new Uri("https://arcadiogarcia.github.io/HTML5VideoDownloadUWP/?" + Uri.EscapeDataString(currentURL));
                if (startingDevices.Contains(text))
                {
                    //Asuming it never fails
                    await Windows.System.Launcher.LaunchUriAsync(downloadUrl);

                    Application.Current.Exit();
                }
                else
                {
                    var launchUriStatus = await RemoteLauncher.LaunchUriAsync(new RemoteSystemConnectionRequest(remoteSystems.Find(x => x.DisplayName == text)), downloadUrl);

                    if (launchUriStatus == RemoteLaunchUriStatus.Success)
                    {
                        Application.Current.Exit();
                    }
                    else
                    {
                        (currentPage as SelectList).setMessage(launchUriStatus.ToString());
                    }
                }
                break;
            }
        }
        private async void RemoteDevicePicker_Loading(FrameworkElement sender, object args)
        {
            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                RemoteSystemWatcher m_remoteSystemWatcher = RemoteSystem.CreateWatcher();
                m_remoteSystemWatcher.RemoteSystemAdded   += RemoteSystemWatcher_RemoteSystemAdded;
                m_remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;
                m_remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;
                m_remoteSystemWatcher.Start();
            }
            _progressRing.IsActive = true;
            UpdateList();
        }
Esempio n. 11
0
        //
        // Summary:
        //     Launch the Discovery Thread.
        public virtual async System.Threading.Tasks.Task <bool> StartDiscovery()
        {
            // Verify access for Remote Systems.
            // Note: RequestAccessAsync needs to called from the UI thread.
            try
            {
                RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

                if (accessStatus == RemoteSystemAccessStatus.Allowed)
                {
                    // Stop Discovery service if it was running
                    StopDiscovery();
                    // Clear the current list of devices
                    if (listCompanionDevices != null)
                    {
                        listCompanionDevices.Clear();
                    }
                    if (listRemoteSystems != null)
                    {
                        listRemoteSystems.Clear();
                    }

                    // Build a watcher to continuously monitor for all remote systems.
                    remoteSystemWatcher = RemoteSystem.CreateWatcher();
                    if (remoteSystemWatcher != null)
                    {
                        // Subscribing to the event that will be raised when a new remote system is found by the watcher.
                        remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded;

                        // Subscribing to the event that will be raised when a previously found remote system is no longer available.
                        remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;

                        // Subscribing to the event that will be raised when a previously found remote system is updated.
                        remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;

                        // Start the watcher.
                        remoteSystemWatcher.Start();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception while starting discovery: " + ex.Message);
                remoteSystemWatcher = null;
            }
            return(false);
        }
        private async void BuildDeviceList()
        {
            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                remoteSystemWatcher = RemoteSystem.CreateWatcher(BuildDeviceFilter());

                // Subscribing to the event raised when a new remote system is found by the watcher.
                remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded;

                // Subscribing to the event raised when a previously found remote system is no longer available.
                remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;

                remoteSystemWatcher.Start();
            }
        }
Esempio n. 13
0
        public async Task Initialize()
        {
            if (_remoteSystemWatcher != null)
            {
                return;
            }

            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                _remoteSystemWatcher = RemoteSystem.CreateWatcher(BuildFilters());
                _remoteSystemWatcher.RemoteSystemAdded   += RemoteSystemWatcher_RemoteSystemAdded;
                _remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;
                _remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;
                _remoteSystemWatcher.Start();
            }
        }
Esempio n. 14
0
        public async void initWatcher()
        {
            RemoteSystemAccessStatus status = await RemoteSystem.RequestAccessAsync();

            if (status == RemoteSystemAccessStatus.Allowed)
            {
                // <SnippetCreateWatcher>
                // store filter list
                List <IRemoteSystemFilter> listOfFilters = makeFilterList();

                // construct watcher with the list
                m_remoteSystemWatcher = RemoteSystem.CreateWatcher(listOfFilters);
                // </SnippetCreateWatcher>

                // assign to event handlers, etc...

                // start detecting
                m_remoteSystemWatcher.Start();
            }
        }
        private async Task StartWatcherAsync()
        {
            RemoteSystemAccessStatus accessStatus = await RemoteSystem.RequestAccessAsync();

            if (accessStatus == RemoteSystemAccessStatus.Allowed)
            {
                remoteSystemWatcher = RemoteSystem.CreateWatcher();

                remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded;

                remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;

                remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;

                remoteSystemWatcher.Start();
            }
            else
            {
                Debug.WriteLine("Access to Remote Systems is " + accessStatus.ToString());
                Debug.WriteLine("Make sure you have set the Remote System capability");
            }
        }
Esempio n. 16
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");
            }
        }