private async void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { if (!deviceMap.ContainsKey(args.RemoteSystem.Id)) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Devices.Add(args.RemoteSystem)); deviceMap[args.RemoteSystem.Id] = args.RemoteSystem; } }
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(); } }
private async Task BuildDeviceListAsync() { var accessStatus = await RemoteSystem.RequestAccessAsync(); if (accessStatus == RemoteSystemAccessStatus.Allowed) { watcher = GetWatcher(); // Subscribing to the event raised when a new remote system is found by the watcher. watcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded; // Subscribing to the event raised when a previously found remote system is no longer available. watcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved; watcher.Start(); } else { //throw new UnauthorizedAccessException("Remote system not allowed " + accessStatus); } }
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"); } }
private void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { CompanionDevice d = new CompanionDevice(args.RemoteSystem.Id, true, args.RemoteSystem.DisplayName, string.Empty, args.RemoteSystem.Kind); if ((d != null) && (listCompanionDevices != null) && (listRemoteSystems != null)) { d.IsAvailableByProximity = args.RemoteSystem.IsAvailableByProximity; // Anniversary issue // d.IsAvailableBySpatialProximity = args.RemoteSystem.IsAvailableBySpatialProximity; d.Status = CompanionDeviceStatus.Available; if (listCompanionDevices.ContainsKey(args.RemoteSystem.Id)) { listCompanionDevices.Remove(args.RemoteSystem.Id); } listCompanionDevices.Add(args.RemoteSystem.Id, d); OnDeviceAdded(this, d); if (listRemoteSystems.ContainsKey(args.RemoteSystem.Id)) { listRemoteSystems.Remove(args.RemoteSystem.Id); } listRemoteSystems.Add(args.RemoteSystem.Id, args.RemoteSystem); } }
private static void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { remoteSystems.Add(args.RemoteSystem); updateSystems(); }
private static void RemoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher sender, RemoteSystemRemovedEventArgs args) { remoteSystems.RemoveAll(x => x.Id == args.RemoteSystemId); updateSystems(); }
private static void RemoteSystemWatcher_RemoteSystemUpdated(RemoteSystemWatcher sender, RemoteSystemUpdatedEventArgs args) { remoteSystems[remoteSystems.FindIndex(x => x.Id == args.RemoteSystem.Id)] = args.RemoteSystem; updateSystems(); }
private void RemoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher sender, RemoteSystemRemovedEventArgs args) { systemList.Remove(systemList.First(x => x.Id == args.RemoteSystemId)); RemoteSystemsListUpdated?.Invoke(this, EventArgs.Empty); }
private void RemoteSystemWatcherOnRemoteSystemAdded(RemoteSystemWatcher watcher, RemoteSystemAddedEventArgs args) { RunOnUiThread(() => _adapter.Add(args.P0)); }
private async void RemoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher sender, RemoteSystemRemovedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (m_rootPage.deviceMap.ContainsKey(args.RemoteSystemId)) { m_rootPage.deviceList.Remove(m_rootPage.deviceMap[args.RemoteSystemId]); UpdateStatus(m_rootPage.deviceMap[args.RemoteSystemId].DisplayName + " removed.", NotifyType.StatusMessage); m_rootPage.deviceMap.Remove(args.RemoteSystemId); } }); }
private void RemoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher watcher, RemoteSystemRemovedEventArgs args) { _remoteSystems.RemoveAll(system => system.Id == args.P0); RunOnUiThread(() => _adapter.Remove(args.P0)); }
private void SearchByRemoteSystemWatcher() { if (FilterSearch.IsChecked.Value) { // Build a watcher to continuously monitor for filtered remote systems. m_remoteSystemWatcher = RemoteSystem.CreateWatcher(BuildFilters()); } else { // Build a watcher to continuously monitor for all remote systems. m_remoteSystemWatcher = RemoteSystem.CreateWatcher(); } // Subscribing to the event that will be raised when a new remote system is found by the watcher. m_remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded; // Subscribing to the event that will be raised when a previously found remote system is no longer available. m_remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved; // Subscribing to the event that will be raised when a previously found remote system is updated. m_remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated; // Start the watcher. m_remoteSystemWatcher.Start(); UpdateStatus("Searching for devices...", NotifyType.StatusMessage); DeviceListBox.Visibility = Visibility.Visible; }
private async void RemoteSystemWatcher_RemoteSystemUpdated(RemoteSystemWatcher sender, RemoteSystemUpdatedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (m_rootPage.deviceMap.ContainsKey(args.RemoteSystem.Id)) { m_rootPage.deviceList.Remove(m_rootPage.deviceMap[args.RemoteSystem.Id]); m_rootPage.deviceMap.Remove(args.RemoteSystem.Id); } m_rootPage.deviceList.Add(args.RemoteSystem); m_rootPage.deviceMap.Add(args.RemoteSystem.Id, args.RemoteSystem); UpdateStatus("Device updated with Id = " + args.RemoteSystem.Id, NotifyType.StatusMessage); }); }
private void RemoteSystemWatcher_RemoteSystemAdded( RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { m_deviceList.Add(args.RemoteSystem); m_deviceMap.Add(args.RemoteSystem.Id, args.RemoteSystem); }
public async Task InitializeAsync() { if (IsInitialized) { return; } IsSupported = Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.System.RemoteSystems.RemoteSystem"); if (!IsSupported) { return; } if (!await CheckRemoteAppServiceEnabledAsync()) { //app service listing got removed while building for store. IsSupported = false; #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } #endif return; } RemoteSystemAccess = await await App.Dispatcher.RunAsync(() => RemoteSystem.RequestAccessAsync()); systemList = new ObservableCollection <RemoteSystem>(); RemoteSystemsList = new ReadOnlyObservableCollection <RemoteSystem>(systemList); IsInitialized = true; if (RemoteSystemAccess == RemoteSystemAccessStatus.Allowed) { remoteSystemWatcher = RemoteSystem.CreateWatcher(new IRemoteSystemFilter[] { new RemoteSystemDiscoveryTypeFilter(RemoteSystemDiscoveryType.Any), new RemoteSystemAuthorizationKindFilter(RemoteSystemAuthorizationKind.SameUser), new RemoteSystemStatusTypeFilter(RemoteSystemStatusType.Available) }); remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded; remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved; remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated; App.Current.EnteredBackground += Current_EnteredBackground; App.Current.LeavingBackground += Current_LeavingBackground; if (Windows.System.Power.PowerManager.EnergySaverStatus != Windows.System.Power.EnergySaverStatus.On) { if ((int)NepApp.Network.ConnectionType > 1) //wifi or ethernet { remoteSystemWatcher.Start(); //auto runs for 30 seconds. stops when app is suspended - https://docs.microsoft.com/en-us/uwp/api/windows.system.remotesystems.remotesystemwatcher } } } }
private void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { systemList.Add(args.RemoteSystem); RemoteSystemsListUpdated?.Invoke(this, EventArgs.Empty); }
private async void Watcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => Devices.Add(args.RemoteSystem)); }
private async void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { m_rootPage.deviceList.Add(args.RemoteSystem); m_rootPage.deviceMap.Add(args.RemoteSystem.Id, args.RemoteSystem); UpdateStatus(string.Format("Found {0} devices.", m_rootPage.deviceList.Count), NotifyType.StatusMessage); }); }
private async void Watcher_RemoteSystemRemoved(RemoteSystemWatcher sender, RemoteSystemRemovedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => Devices.Remove(Devices.First(x => x.Id == args.RemoteSystemId))); }
private void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { waitHandle.Set(); m_deviceList.Add(args.RemoteSystem); }
private void RemoteSystemWatcherOnRemoteSystemAdded(RemoteSystemWatcher watcher, RemoteSystemAddedEventArgs args) { _remoteSystems.Add(args.P0); RunOnUiThread(() => _adapter.Add(args.P0.DisplayName)); }
private void DevicesWatcher_ErrorOccurred(RemoteSystemWatcher sender, RemoteSystemWatcherErrorOccurredEventArgs args) { Debug.WriteLine(args.Error); }
private void RemoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher watcher, RemoteSystemRemovedEventArgs args) { RunOnUiThread(() => _adapter.Remove(_adapter.Items.FirstOrDefault(system => system.Id == args.P0)) ); }
private void RemoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher watcher, RemoteSystemRemovedEventArgs args) { System.Diagnostics.Debug.WriteLine("KNOWZY: RemoteSystemRemoved " + args.P0); remoteSystems.RemoveAll(system => system.Id == args.P0); RemoteSystemRemoved?.Invoke(this, args); }
private void SearchCleanup() { if (m_remoteSystemWatcher != null) { m_remoteSystemWatcher.Stop(); m_remoteSystemWatcher = null; } m_rootPage.deviceList.Clear(); m_rootPage.deviceMap.Clear(); }
private void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher watcher, RemoteSystemAddedEventArgs args) { System.Diagnostics.Debug.WriteLine($"KNOWZY: RemoteSystemAdded: {args.P0.DisplayName} + ({args.P0.Id})"); remoteSystems.Add(args.P0); RemoteSystemAdded?.Invoke(this, args); }
private void RemoteSystemWatcher_EnumerationCompleted(RemoteSystemWatcher sender, RemoteSystemEnumerationCompletedEventArgs args) { _remoteSystemWatcher.Stop(); }
private async void M_remoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher sender, RemoteSystemRemovedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => RemoteSystems.Remove(RemoteSystems.First(rs => rs.Id == args.RemoteSystemId))); }
private void RemoteSystemUpdated(RemoteSystemWatcher watcher, RemoteSystemUpdatedEventArgs args) { }
private void RemoteSystemWatcher_Complete(RemoteSystemWatcher watcher) { DiscoveryCompleted?.Invoke(this, null); }