Exemplo n.º 1
0
 void OnEnumberationCompleted(EnumberationCompletedEventArgs args)
 {
     if (StopEventHandle != null)
     {
         StopEventHandle(this, args);
     }
 }
Exemplo n.º 2
0
 private void EnumberationCompletedEvent_StopEventHandle(object sender, EnumberationCompletedEventArgs e)
 {
     e.Button.IsEnabled      = true;
     e.ProgressRing.IsActive = false;
     //e.ProgressRing.Visibility =
     e.TextBlock.Text = "--Scan Completed--";
 }
Exemplo n.º 3
0
 public void EnumberationCompleted(EnumberationCompletedEventArgs args)
 {
     OnEnumberationCompleted(args);
 }
Exemplo n.º 4
0
        private void InitilizedWatcher()
        {
            handlerAdded = new TypedEventHandler <DeviceWatcher, DeviceInformation>(async(watcher, deviceInfo) =>
            {
                // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    var info = new DeviceInformationDisplay(deviceInfo);
                    if (!info.IsPaired && info.CanPair)
                    {
                        ResultCollection.Add(info);
                    }
                });
            });
            deviceWatcher.Added += handlerAdded;

            handlerUpdated = new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>(async(watcher, deviceInfoUpdate) =>
            {
                // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    // Find the corresponding updated DeviceInformation in the collection and pass the update object
                    // to the Update method of the existing DeviceInformation. This automatically updates the object
                    // for us.
                    foreach (DeviceInformationDisplay deviceInfoDisp in ResultCollection)
                    {
                        if (deviceInfoDisp.Id == deviceInfoUpdate.Id)
                        {
                            deviceInfoDisp.Update(deviceInfoUpdate);

                            //// If the item being updated is currently "selected", then update the pairing buttons
                            ////DeviceInformationDisplay selectedDeviceInfoDisp = (DeviceInformationDisplay)resultsListView.SelectedItem;
                            //if (deviceInfoDisp == selectedDeviceInfoDisp)
                            //{
                            //    //UpdatePairingButtons();
                            //}
                            break;
                        }
                    }
                });
            });
            deviceWatcher.Updated += handlerUpdated;

            handlerRemoved = new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>(async(watcher, deviceInfoUpdate) =>
            {
                // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    // Find the corresponding DeviceInformation in the collection and remove it
                    foreach (DeviceInformationDisplay deviceInfoDisp in ResultCollection)
                    {
                        if (deviceInfoDisp.Id == deviceInfoUpdate.Id)
                        {
                            ResultCollection.Remove(deviceInfoDisp);
                            break;
                        }
                    }
                });
            });
            deviceWatcher.Removed += handlerRemoved;

            handlerEnumCompleted = new TypedEventHandler <DeviceWatcher, Object>(async(watcher, obj) =>
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    foreach (var item in ResultCollection)
                    {
                        Debug.WriteLine(String.Format("Name         = {0}", item.Name));
                        Debug.WriteLine(String.Format("Id           = {0}", item.Id));
                        Debug.WriteLine(String.Format("NameIsPaired = {0}", item.IsPaired));
                        listView.ItemsSource       = ResultCollection.Select(s => new { s.Name, s.Id });
                        listView.DisplayMemberPath = "Name";
                        listView.SelectedValuePath = "Id";
                    }


                    enumberationCompletedEvent.StopEventHandle += EnumberationCompletedEvent_StopEventHandle;
                    EnumberationCompletedEventArgs args         = new EnumberationCompletedEventArgs();
                    args.Button       = btnStart;
                    args.ProgressRing = progressRing;
                    args.TextBlock    = lblComplete;
                    enumberationCompletedEvent.EnumberationCompleted(args);
                });
            });
            deviceWatcher.EnumerationCompleted += handlerEnumCompleted;

            handlerStopped = new TypedEventHandler <DeviceWatcher, Object>(async(watcher, obj) =>
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    //rootPage.NotifyUser(
                    //    String.Format("{0} devices found. Watcher {1}.",
                    //        ResultCollection.Count,
                    //        DeviceWatcherStatus.Aborted == watcher.Status ? "aborted" : "stopped"),
                    //    NotifyType.StatusMessage);
                });
            });
            deviceWatcher.Stopped += handlerStopped;
        }