private void Current_LeavingBackground(object sender, LeavingBackgroundEventArgs e) { if (Windows.System.Power.PowerManager.EnergySaverStatus != Windows.System.Power.EnergySaverStatus.On) { if ((int)NepApp.Network.ConnectionType > 1) //wifi or ethernet { remoteSystemWatcher.Start(); } } }
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(); } }
/// <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(); } }
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(); }
private async void DiscoverDevices() { var accessStatus = await RemoteSystem.RequestAccessAsync(); if (accessStatus == RemoteSystemAccessStatus.Allowed) { _remoteSystemWatcher = RemoteSystem.CreateWatcher(); //Add RemoteSystem to DeviceList (on the UI Thread) _remoteSystemWatcher.RemoteSystemAdded += async(sender, args) => await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => DeviceList.Add(args.RemoteSystem)); //Remove RemoteSystem from DeviceList (on the UI Thread) _remoteSystemWatcher.RemoteSystemRemoved += async(sender, args) => await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => DeviceList.Remove(DeviceList.FirstOrDefault(system => system.Id == args.RemoteSystemId))); //Update RemoteSystem on DeviceList (on the UI Thread) _remoteSystemWatcher.RemoteSystemUpdated += async(sender, args) => await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { DeviceList.Remove(DeviceList.FirstOrDefault(system => system.Id == args.RemoteSystem.Id)); DeviceList.Add(args.RemoteSystem); }); _remoteSystemWatcher.Start(); } }
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 systems...", NotifyType.StatusMessage); SystemListBox.Visibility = Visibility.Visible; }
/// <summary> /// Initiate Enumeration with specific RemoteSystemKind with Filters /// </summary> private async void GenerateSystemsWithFilterAsync(List <IRemoteSystemFilter> filter) { var accessStatus = await RemoteSystem.RequestAccessAsync(); if (accessStatus == RemoteSystemAccessStatus.Allowed) { _remoteSystemWatcher = filter != null?RemoteSystem.CreateWatcher(filter) : RemoteSystem.CreateWatcher(); _remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded; _remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved; _remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated; if (ApiInformation.IsEventPresent("Windows.System.RemoteSystems.RemoteSystemWatcher", "EnumerationCompleted")) { _remoteSystemWatcher.EnumerationCompleted += RemoteSystemWatcher_EnumerationCompleted; } else { ThreadPoolTimer.CreateTimer( (e) => { RemoteSystemWatcher_EnumerationCompleted(_remoteSystemWatcher, null); }, TimeSpan.FromSeconds(2)); } _remoteSystemWatcher.Start(); } }
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); }
public void StartDiscovery() { if (authStatus != AuthenticationStatus.Authenticated) { throw new InvalidOperationException("Can't discover until you are authenticated"); } if (remoteSystemWatcher == null) { lock (instance) { remoteSystemWatcher = RemoteSystem.CreateWatcher(); //hook up event handlers remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded;; remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved;; remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated;; remoteSystemWatcher.Complete += RemoteSystemWatcher_Complete; //start watcher try { remoteSystemWatcher.Start(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } } }
private async void StartWatch() { RemoteSystemAccessStatus Status = await RemoteSystem.RequestAccessAsync(); Watcher = RemoteSystem.CreateWatcher(); Watcher.RemoteSystemAdded += Watcher_RemoteSystemAdded; Watcher.RemoteSystemRemoved += Watcher_RemoteSystemRemoved; Watcher.Start(); }
private void RefreshDevices() { remoteSystemWatcher = RemoteSystem.CreateWatcher(); remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded; remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved; remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated; remoteSystemWatcher.Start(); }
public void DiscoverDevices() { _remoteSystemWatcher = RemoteSystem.CreateWatcher(); _remoteSystemWatcher.RemoteSystemAdded += RemoteSystemAdded; _remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemRemoved; _remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemUpdated; _remoteSystemWatcher.Start(); }
private void DiscoverDevicesAsync() { var filters = GetRemoteSystemFilter(); // Filters 需要在建立 RemoteSystemWatcher 建構子一起傳入 devicesWatcher = RemoteSystem.CreateWatcher(filters); devicesWatcher.RemoteSystemAdded += DevicesWatcher_RemoteSystemAdded; devicesWatcher.RemoteSystemRemoved += DevicesWatcher_RemoteSystemRemoved; devicesWatcher.RemoteSystemUpdated += DevicesWatcher_RemoteSystemUpdated; //devicesWatcher.ErrorOccurred += DevicesWatcher_ErrorOccurred; devicesWatcher.Start(); }
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(); }
/// <summary> /// Initiate Enumeration with specific RemoteSysemKind with Filters /// </summary> private async void GenerateSystemsWithFilterAsync(List <IRemoteSystemFilter> filter) { var accessStatus = await RemoteSystem.RequestAccessAsync(); if (accessStatus == RemoteSystemAccessStatus.Allowed) { _remoteSystemWatcher = filter != null?RemoteSystem.CreateWatcher(filter) : RemoteSystem.CreateWatcher(); _remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded; _remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved; _remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated; _remoteSystemWatcher.EnumerationCompleted += RemoteSystemWatcher_EnumerationCompleted; _remoteSystemWatcher.Start(); } }
public static void DiscoverDevices() { RequestAccess(); // Create Watcher for remote devices _watcher = RemoteSystem.CreateWatcher(BuildFilters()); // Hook up event handlers _watcher.RemoteSystemAdded += _watcher_RemoteSystemAdded; _watcher.RemoteSystemRemoved += _watcher_RemoteSystemRemoved; _watcher.RemoteSystemUpdated += _watcher_RemoteSystemUpdated; // Start the Watcher _watcher.Start(); Events.TrackEvent(Events.StartRemoteSystemWatcher); }
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 void SetupRemoteWatcher() { var accessStatus = await RemoteSystem.RequestAccessAsync(); if (accessStatus == RemoteSystemAccessStatus.Allowed) { // Create and start the remote system _remoteSystemWatcher = RemoteSystem.CreateWatcher(); // Bind methods _remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcher_RemoteSystemAdded; _remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved; _remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated; _remoteSystemWatcher.Start(); } }
private async Task ListDevicesAsync() { using (await _listDevicesAsyncLock.LockAsync()) { RequestAccessError = string.Empty; var result = await RemoteSystem.RequestAccessAsync(); if (result != RemoteSystemAccessStatus.Allowed) { RequestAccessError = "Impossible de lister les périphériques : " + result; return; } if (_watcher != null) { _watcher.RemoteSystemAdded -= OnWatcherRemoteSystemAdded; _watcher.RemoteSystemRemoved -= OnWatcherRemoteSystemRemoved; _watcher.RemoteSystemUpdated -= OnWatcher_RemoteSystemUpdated; } RemoteSystems = new ObservableCollection <RemoteSystem>(); #region listing if (IsListingOnlyActiveDevices) { var filter = new IRemoteSystemFilter[] { new RemoteSystemStatusTypeFilter(RemoteSystemStatusType.Available), new RemoteSystemDiscoveryTypeFilter(RemoteSystemDiscoveryType.Any) }; _watcher = RemoteSystem.CreateWatcher(filter); } else { #endregion _watcher = RemoteSystem.CreateWatcher(); _watcher.RemoteSystemAdded += OnWatcherRemoteSystemAdded; _watcher.RemoteSystemRemoved += OnWatcherRemoteSystemRemoved; } _watcher.RemoteSystemUpdated += OnWatcher_RemoteSystemUpdated; _watcher.Start(); } }
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(); } }
private void DiscoverDevices() { if (remoteSystemWatcher != null) { remoteSystemWatcher.Stop(); } var filters = new List <IRemoteSystemFilter> { new RemoteSystemKindFilter(remoteSystemKind), new RemoteSystemDiscoveryTypeFilter(remoteSystemDiscoveryKind) }; remoteSystemWatcher = RemoteSystem.CreateWatcher(filters); remoteSystemWatcher.RemoteSystemAdded += RemoteSystemWatcherOnRemoteSystemAdded; remoteSystemWatcher.RemoteSystemRemoved += RemoteSystemWatcher_RemoteSystemRemoved; remoteSystemWatcher.RemoteSystemUpdated += RemoteSystemWatcher_RemoteSystemUpdated; remoteSystemWatcher.Start(); }
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 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 async void Timer_Tick(object state) { //Debug.WriteLine("Timer_Tick"); if (firstTimeRefresh) { firstTimeRefresh = false; if (_remoteSystems.Count == 0) { return; } } //Debug.WriteLine("Timer_Tick. Stopping watcher..."); _remoteSystemWatcher.Stop(); //Debug.WriteLine("Timer_Tick. Stopped watcher..."); await Task.Delay(500); //Debug.WriteLine("Timer_Tick. Starting watcher..."); _remoteSystemWatcher.Start(); //Debug.WriteLine("Timer_Tick. Started watcher..."); }
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 Timer_Tick(object state) { remoteSystemWatcher.Stop(); remoteSystemWatcher.Start(); }