Пример #1
0
        private void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            var di = args.SelectedDevice;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(di.Name);
            sb.AppendLine(di.Id);
            sb.AppendLine(di.Kind.ToString());
            sb.AppendLine(di.Pairing.IsPaired.ToString());
            sb.AppendLine(di.Pairing.CanPair.ToString());
            sb.AppendLine("");
            foreach (var item in di.Properties.Keys)
            {
                sb.Append(item);

                string[] props = di.Properties[item] as string[];
                if (props != null)
                {
                    sb.AppendLine(":");
                    foreach (var prop in props)
                    {
                        sb.AppendLine("    " + prop);
                    }
                }
                else
                {
                    sb.AppendLine(": " + di.Properties[item]);
                }
            }

            Trace.WriteLine(sb.ToString());
        }
Пример #2
0
        private async Task CastingVideoToScreen(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                activeDevice         = args.SelectedDevice;
                CastingDevice device = await CastingDevice.FromIdAsync(args.SelectedDevice.Id);
                castingConnection    = device.CreateCastingConnection();

                //Hook up the casting events
                //castingConnection.ErrorOccurred += Connection_ErrorOccurred;
                //castingConnection.StateChanged += Connection_StateChanged;

                // Get the casting source from the MediaElement
                CastingSource source = null;

                try
                {
                    // Get the casting source from the Media Element
                    source = player.GetAsCastingSource();

                    // Start Casting
                    CastingConnectionErrorStatus status = await castingConnection.RequestStartCastingAsync(source);

                    if (status == CastingConnectionErrorStatus.Succeeded)
                    {
                        player.Play();
                    }
                }
                catch
                {
                }
            });
        }
Пример #3
0
        private async void DevicePicker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                DeviceInformation selectedDevice = args.SelectedDevice;

#if DEBUG
                // The args.SelectedCastingDevice is proxied from the picker process. The picker process is
                // dismissmed as soon as you break into the debugger. Creating a non-proxied version
                // allows debugging since the proxied version stops working once the picker is dismissed.
                selectedDevice = await DeviceInformation.CreateFromIdAsync(args.SelectedDevice.Id);
#endif

                if (await DialDevice.DeviceInfoSupportsDialAsync(selectedDevice))
                {
                    await SendDialParameter(sender, args);
                }
                else if (await CastingDevice.DeviceInfoSupportsCastingAsync(selectedDevice))
                {
                    await CastingVideoToScreen(sender, args);
                }
                else if (ProjectionManager.ProjectionDisplayAvailable)
                {
                    await ProjectioinViewToScreen(sender, args);
                }
            });
        }
Пример #4
0
        void DeviceSelectedPublish(DeviceDescriptionHolder dev, NvtSessionFactory sessionFactory)
        {
            var evargs = new DeviceSelectedEventArgs();

            evargs.sessionFactory = sessionFactory;
            evargs.devHolder      = dev;
            eventAggregator.GetEvent <DeviceSelectedEvent>().Publish(evargs);
        }
Пример #5
0
        private async void DevicePicker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                // 更新 picker 上設備的 status
                sender.SetDisplayStatus(args.SelectedDevice, "connecting", DevicePickerDisplayStatusOptions.ShowProgress);

                // 取得目前選到設備的資訊
                activeDevice = args.SelectedDevice;

                // 現在 view 的 Id 與 CoreDispatcher
                int currentViewId = ApplicationView.GetForCurrentView().Id;
                CoreDispatcher currentDispatcher = Window.Current.Dispatcher;

                // 建立新的 view,
                if (projectionInstance.ProjectionViewPageControl == null)
                {
                    await CoreApplication.CreateNewView().Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        // 建立新 viewe 的生命管理器
                        projectionInstance.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();
                        projectionInstance.MainViewId = currentViewId;

                        var rootFrame = new Frame();
                        rootFrame.Navigate(typeof(ProjectionPage), projectionInstance);

                        // 這裏的 Window 代表是新建立這個 view 的 Window
                        // 但是要等到呼叫 ProjectionManager.StartProjectingAsync 才會顯示
                        Window.Current.Content = rootFrame;
                        Window.Current.Activate();
                    });
                }

                // 直接切換到指定的 view id
                //bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(projectionInstance.ProjectionViewPageControl.Id);

                // 通知要使用新的 view
                projectionInstance.ProjectionViewPageControl.StartViewInUse();

                try
                {
                    txtViewId.Text = $"{projectionInstance.ProjectionViewPageControl.Id}, {currentViewId}";
                    await ProjectionManager.StartProjectingAsync(projectionInstance.ProjectionViewPageControl.Id, currentViewId, activeDevice);

                    player.Pause();

                    sender.SetDisplayStatus(args.SelectedDevice, "connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton);
                }
                catch (Exception ex)
                {
                    sender.SetDisplayStatus(args.SelectedDevice, ex.Message, DevicePickerDisplayStatusOptions.ShowRetryButton);
                    if (ProjectionManager.ProjectionDisplayAvailable == false)
                    {
                        throw;
                    }
                }
            });
        }
        private async void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            string deviceId = args.SelectedDevice.Id;

            //Casting must occur from the UI thread.  This dispatches the casting calls to the UI thread.
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                //Update the display status for the selected device to connecting.
                picker.SetDisplayStatus(args.SelectedDevice, "Connecting", DevicePickerDisplayStatusOptions.ShowProgress);

                // BUG: In order to support debugging it is best to retreive the device from the local app instead
                // of continuing to use the DeviceInformation instance that is proxied from the picker.
                DeviceInformation device = null;
                try { if (deviceId.IndexOf("dial", StringComparison.OrdinalIgnoreCase) == -1)
                      {
                          device = await DeviceInformation.CreateFromIdAsync(deviceId, RequiredDeviceProperties.Props, DeviceInformationKind.DeviceContainer);
                      }
                } catch { }
                try { if (device == null)
                      {
                          device = await DeviceInformation.CreateFromIdAsync(deviceId, RequiredDeviceProperties.Props, DeviceInformationKind.AssociationEndpoint);
                      }
                } catch { }
                // In case the workaround did not work
                if (device == null)
                {
                    device = args.SelectedDevice;
                }

                //Try casting using DIAL first
                bool castSucceeded = await TryLaunchDialAppAsync(device);
                //If DIAL did not work for the selected device, try the CAST API
                if (!castSucceeded)
                {
                    castSucceeded = await TryCastMediaElementAsync(device);
                }

                if (castSucceeded)
                {
                    //Update the display status for the selected device.
                    try { picker.SetDisplayStatus(device, "Connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton); } catch { }
                    disconnectButton.IsEnabled = true;

                    // Hide the picker now that all the work is completed
                    //picker.Hide();
                }
                else
                {
                    //Show a retry button when connecting to the selected device failed.
                    picker.SetDisplayStatus(device, "Connecting failed", DevicePickerDisplayStatusOptions.ShowRetryButton);
                }
            });
        }
Пример #7
0
        private async void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            string deviceId = args.SelectedDevice.Id;

            //Casting must occur from the UI thread.  This dispatches the casting calls to the UI thread.
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                //Update the display status for the selected device to connecting.
                try { picker.SetDisplayStatus(args.SelectedDevice, "Connecting", DevicePickerDisplayStatusOptions.ShowProgress); } catch { }

                //The selectedDeviceInfo instance is needed to be able to update the picker.
                DeviceInformation selectedDeviceInfo = args.SelectedDevice;
#if DEBUG
                // The args.SelectedCastingDevice is proxied from the picker process. The picker process is
                // dismissmed as soon as you break into the debugger. Creating a non-proxied version
                // allows debugging since the proxied version stops working once the picker is dismissed.
                selectedDeviceInfo = await DeviceInformation.CreateFromIdAsync(args.SelectedDevice.Id);
#endif

                bool castSucceeded = false;

                // If the ProjectionManager API did not work and the device id will have 'dial' in it.
                castSucceeded = await TryLaunchDialAppAsync(selectedDeviceInfo);

                // If it doesn't try the ProjectionManager API.
                if (!castSucceeded)
                {
                    castSucceeded = await TryProjectionManagerCastAsync(selectedDeviceInfo);
                }

                //If DIAL and ProjectionManager did not work for the selected device, try the CAST API
                if (!castSucceeded)
                {
                    castSucceeded = await TryCastMediaElementAsync(selectedDeviceInfo);
                }

                if (castSucceeded)
                {
                    //Update the display status for the selected device.  Try Catch in case the picker is not visible anymore.
                    try { picker.SetDisplayStatus(selectedDeviceInfo, "Connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton); } catch { }

                    // Hide the picker now that all the work is completed. Try Catch in case the picker is not visible anymore.
                    try { picker.Hide(); } catch { }
                }
                else
                {
                    //Show a retry button when connecting to the selected device failed.
                    try { picker.SetDisplayStatus(selectedDeviceInfo, "Connecting failed", DevicePickerDisplayStatusOptions.ShowRetryButton); } catch { }
                }
            });
        }
        private async void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            string deviceId = args.SelectedDevice.Id;

            //Casting must occur from the UI thread.  This dispatches the casting calls to the UI thread.
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                //Update the display status for the selected device to connecting.
                picker.SetDisplayStatus(args.SelectedDevice, "Connecting", DevicePickerDisplayStatusOptions.ShowProgress);

                // BUG: In order to support debugging it is best to retreive the device from the local app instead
                // of continuing to use the DeviceInformation instance that is proxied from the picker.
                DeviceInformation device = await DeviceInformation.CreateFromIdAsync(deviceId);

                bool castSucceeded = false;

                // The dial AssociationEndpoint ID will have 'dial' in the string.
                // If it doesn't try the ProjectionManager API.
                if (deviceId.IndexOf("dial", StringComparison.OrdinalIgnoreCase) == -1)
                {
                    castSucceeded = await TryProjectionManagerCastAsync(device);
                }
                // If the ProjectionManager API did not work and the device id will have 'dial' in it.
                if (!castSucceeded && deviceId.IndexOf("dial", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    castSucceeded = await TryLaunchDialAppAsync(device);
                }

                //If DIAL and ProjectionManager did not work for the selected device, try the CAST API
                if (!castSucceeded)
                {
                    castSucceeded = await TryCastMediaElementAsync(device);
                }

                if (castSucceeded)
                {
                    //Update the display status for the selected device.  Try Catch in case the picker is not visible anymore.
                    try { picker.SetDisplayStatus(device, "Connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton); } catch { }

                    // Hide the picker now that all the work is completed. Try Catch in case the picker is not visible anymore.
                    try { picker.Hide(); } catch { }
                }
                else
                {
                    //Show a retry button when connecting to the selected device failed.
                    try { picker.SetDisplayStatus(device, "Connecting failed", DevicePickerDisplayStatusOptions.ShowRetryButton); } catch { }
                }
            });
        }
Пример #9
0
        private void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            // Getting the selected device
            _selectedDeviceInformation = args.SelectedDevice;

            // Save a setting locally on the device
            ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            localSettings.Values[SelectedDeviceKey] = _selectedDeviceInformation.Id;

            _onDeviceSelected(_selectedDeviceInformation.Id);

            // Set status to Connecting
            _picker.SetDisplayStatus(args.SelectedDevice, "", DevicePickerDisplayStatusOptions.None);
        }
Пример #10
0
        void OnSelectedDeviceChanged()
        {
            var dev = (DeviceDescriptionHolder)SelectedDevice;

            if (dev == null)
            {
                return;
            }
            if (dev.Uris.Count() == 0)
            {
                return;
            }

            DeviceSelectedEventArgs evargs = new DeviceSelectedEventArgs();

            evargs.devHolder      = dev;
            evargs.sessionFactory = sessionFactory;
            eventAggregator.GetEvent <DeviceSelectedEvent>().Publish(evargs);
        }
Пример #11
0
        private async void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            //Casting must occur from the UI thread.  This dispatches the casting calls to the UI thread.
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                {
                    // Set status to Connecting
                    picker.SetDisplayStatus(args.SelectedDevice, "Connecting", DevicePickerDisplayStatusOptions.ShowProgress);

                    // Getting the selected device improves debugging
                    DeviceInformation selectedDevice = args.SelectedDevice;
                    try
                    {
                        await ProjectionManager.StartProjectingAsync(ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread()), thisViewId, selectedDevice);

                    }
                    catch (Exception ex)
                    {
                        if (!ProjectionManager.ProjectionDisplayAvailable)
                            throw ex;
                    }

                    try
                    {
                        
                            activeDevice = selectedDevice;
                        
                            // Set status to Connected
                            picker.SetDisplayStatus(args.SelectedDevice, "Connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton);
                            picker.Hide();
                    }
                    catch (Exception)
                    {
                        try { picker.SetDisplayStatus(args.SelectedDevice, "Connection Failed", DevicePickerDisplayStatusOptions.ShowRetryButton); } catch { }
                    }
                }
                catch (Exception ex)
                {
                    
                }
            });
        }
Пример #12
0
        //void XmlExplorerClick(DeviceLinkEventArgs evarg) {
        //    var view = container.Resolve<XMLExplorerView>();
        //    var viewModel = view.DataContext as XMLExplorerViewModel;
        //    if (viewModel != null) {
        //        viewModel.Init(evarg.session, evarg.currentAccount);
        //    }
        //    ShowView(view, "xmlexplorer_view", RegionNames.reg_property);
        //}

        #endregion DeviceLinks

        void OnSelectedDeviceChanged(DeviceSelectedEventArgs evArgs)
        {
            if (evArgs.devHolder == null)
            {
                return;
            }
            //var view = container.Resolve<DeviceView>();
            //view.Init(evArgs.devHolder, evArgs.sessionFactory);

            var view = container.Resolve <OnvifEntityPanel>();

            view.Init(evArgs.devHolder, evArgs.sessionFactory, container);

            //var viewModel = view.DataContext as DeviceViewModel;
            //if (viewModel != null) {
            //    viewModel.Init(evArgs.devHolder, evArgs.sessionFactory);
            //}
            ReleaseUI();
            ShowView(view, RegionNames.reg_entity_view, RegionNames.reg_device);
        }
Пример #13
0
 /// <summary>
 /// Obsługuje zdarzenie wyboru urządzenia. Obsługa polega na sprawdzeniu czy wybrane urządzenie jest sparowane.
 /// W przypadku, gdy wynik sprawdzenia jest pozytywny wywoływana jest metoda próbująca nawiązać połączenie z wybranym urządzeniem.
 /// W przeciwnym razie, jeśli jest taka możliwość wywoływana jest metoda parująca urządzenia.
 /// </summary>
 /// <param name="pckr"></param>
 /// <param name="args"></param>
 private void _selectedDeviceHandler(DevicePicker pckr, DeviceSelectedEventArgs args)
 {
     pckr.Hide();
     if (args.SelectedDevice.Pairing.IsPaired)
     {
         _connectToDevice(args.SelectedDevice);
     }
     else
     {
         if (args.SelectedDevice.Pairing.CanPair)
         {
             PopUp.Show(StringConsts.RobotNotPairedButCanPair, StringConsts.Error);
             _pairDevices(args.SelectedDevice);
         }
         else
         {
             PopUp.Show(StringConsts.RobotNotPairedAndCannotPair, StringConsts.Error);
         }
     }
 }
Пример #14
0
        private async Task SendDialParameter(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            try
            {
                // 設定遠端設備現在要準備連綫
                sender.SetDisplayStatus(args.SelectedDevice, "connecting", DevicePickerDisplayStatusOptions.ShowProgress);

                // 取得遠端設備中支援指定 app name 的 App
                DialDevice dialDevice = await DialDevice.FromIdAsync(args.SelectedDevice.Id);

                DialApp app = dialDevice.GetDialApp("castingsample");

                if (app == null)
                {
                    // 嘗試建立 DIAL device,如果失敗代表那個設備不支援 DIAL
                    sender.SetDisplayStatus(args.SelectedDevice, "The app is not exist in the device.", DevicePickerDisplayStatusOptions.ShowRetryButton);
                }
                else
                {
                    // 請求送出參數到遠端設備的 App
                    DialAppLaunchResult result = await app.RequestLaunchAsync("Test");

                    if (result == DialAppLaunchResult.Launched)
                    {
                        activeDevice = args.SelectedDevice;
                        sender.SetDisplayStatus(args.SelectedDevice, "connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton);
                        sender.Hide();
                    }
                    else
                    {
                        sender.SetDisplayStatus(args.SelectedDevice, "Device Error", DevicePickerDisplayStatusOptions.ShowRetryButton);
                    }
                }
            }
            catch (Exception ex)
            {
                sender.SetDisplayStatus(args.SelectedDevice, ex.Message, DevicePickerDisplayStatusOptions.None);
            }
        }
        private async Task CastingVideoToScreen(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                activeDevice = args.SelectedDevice;
                CastingDevice device =await  CastingDevice.FromIdAsync(args.SelectedDevice.Id);
                castingConnection = device.CreateCastingConnection();
                
                //Hook up the casting events
                //castingConnection.ErrorOccurred += Connection_ErrorOccurred;
                //castingConnection.StateChanged += Connection_StateChanged;

                // Get the casting source from the MediaElement
                CastingSource source = null;

                try
                {
                    // Get the casting source from the Media Element
                    source = player.GetAsCastingSource();

                    // Start Casting
                    CastingConnectionErrorStatus status = await castingConnection.RequestStartCastingAsync(source);

                    if (status == CastingConnectionErrorStatus.Succeeded)
                    {
                        player.Play();
                    }
                }
                catch
                {

                }
            });
        }
        private async void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            string deviceId = args.SelectedDevice.Id;

            //Casting must occur from the UI thread.  This dispatches the casting calls to the UI thread.
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                //Update the display status for the selected device to connecting.
                try { picker.SetDisplayStatus(args.SelectedDevice, "Connecting", DevicePickerDisplayStatusOptions.ShowProgress); } catch { }

                //The selectedDeviceInfo instance is needed to be able to update the picker.
                DeviceInformation selectedDeviceInfo = args.SelectedDevice;
#if DEBUG
                // The args.SelectedCastingDevice is proxied from the picker process. The picker process is 
                // dismissmed as soon as you break into the debugger. Creating a non-proxied version 
                // allows debugging since the proxied version stops working once the picker is dismissed.
                selectedDeviceInfo = await DeviceInformation.CreateFromIdAsync(args.SelectedDevice.Id);
#endif

                bool castSucceeded = false;

                // If the ProjectionManager API did not work and the device id will have 'dial' in it.
                castSucceeded = await TryLaunchDialAppAsync(selectedDeviceInfo);

                // If it doesn't try the ProjectionManager API.
                if (!castSucceeded)
                    castSucceeded = await TryProjectionManagerCastAsync(selectedDeviceInfo);

                //If DIAL and ProjectionManager did not work for the selected device, try the CAST API
                if (!castSucceeded)
                    castSucceeded = await TryCastMediaElementAsync(selectedDeviceInfo);

                if (castSucceeded)
                {
                    //Update the display status for the selected device.  Try Catch in case the picker is not visible anymore.
                    try { picker.SetDisplayStatus(selectedDeviceInfo, "Connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton); } catch { }

                    // Hide the picker now that all the work is completed. Try Catch in case the picker is not visible anymore.
                    try { picker.Hide(); } catch { }
                }
                else
                {
                    //Show a retry button when connecting to the selected device failed.
                    try { picker.SetDisplayStatus(selectedDeviceInfo, "Connecting failed", DevicePickerDisplayStatusOptions.ShowRetryButton); } catch { }
                }
            });
        }
        private async void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            //Casting must occur from the UI thread.  This dispatches the casting calls to the UI thread.
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    // Set status to Connecting
                    picker.SetDisplayStatus(args.SelectedDevice, "Connecting", DevicePickerDisplayStatusOptions.ShowProgress);

                    // Getting the selected device improves debugging
                    DeviceInformation selectedDevice = args.SelectedDevice;

                    thisViewId = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().Id;

                    // If projection is already in progress, then it could be shown on the monitor again
                    // Otherwise, we need to create a new view to show the presentation
                    if (rootPage.ProjectionViewPageControl == null)
                    {
                        // First, create a new, blank view
                        var thisDispatcher = Window.Current.Dispatcher;
                        await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            // ViewLifetimeControl is a wrapper to make sure the view is closed only
                            // when the app is done with it
                            rootPage.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();

                            // Assemble some data necessary for the new page
                            pvb.MainPageDispatcher        = thisDispatcher;
                            pvb.ProjectionViewPageControl = rootPage.ProjectionViewPageControl;
                            pvb.MainViewId = thisViewId;

                            // Display the page in the view. Note that the view will not become visible
                            // until "StartProjectingAsync" is called
                            var rootFrame = new Frame();
                            rootFrame.Navigate(typeof(ProjectionViewPage), pvb);
                            Window.Current.Content = rootFrame;

                            Window.Current.Activate();
                        });
                    }

                    try
                    {
                        // Start/StopViewInUse are used to signal that the app is interacting with the
                        // view, so it shouldn't be closed yet, even if the user loses access to it
                        rootPage.ProjectionViewPageControl.StartViewInUse();

                        try
                        {
                            await ProjectionManager.StartProjectingAsync(rootPage.ProjectionViewPageControl.Id, thisViewId, selectedDevice);
                        }
                        catch (Exception ex)
                        {
                            if (!ProjectionManager.ProjectionDisplayAvailable || pvb.ProjectedPage == null)
                            {
                                throw ex;
                            }
                        }

                        // ProjectionManager currently can throw an exception even when projection has started.\
                        // Re-throw the exception when projection has not been started after calling StartProjectingAsync
                        if (ProjectionManager.ProjectionDisplayAvailable && pvb.ProjectedPage != null)
                        {
                            this.player.Pause();
                            await pvb.ProjectedPage.SetMediaSource(this.player.Source, this.player.Position);
                            activeDevice = selectedDevice;
                            // Set status to Connected
                            picker.SetDisplayStatus(args.SelectedDevice, "Connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton);
                            picker.Hide();
                        }
                        else
                        {
                            rootPage.NotifyUser(string.Format("Projection has failed to '{0}'", selectedDevice.Name), NotifyType.ErrorMessage);
                            // Set status to Failed
                            picker.SetDisplayStatus(args.SelectedDevice, "Connection Failed", DevicePickerDisplayStatusOptions.ShowRetryButton);
                        }
                    }
                    catch (Exception)
                    {
                        rootPage.NotifyUser(string.Format("Projection has failed to '{0}'", selectedDevice.Name), NotifyType.ErrorMessage);
                        // Set status to Failed
                        try { picker.SetDisplayStatus(args.SelectedDevice, "Connection Failed", DevicePickerDisplayStatusOptions.ShowRetryButton); } catch { }
                    }
                }
                catch (Exception ex)
                {
                    UnhandledExceptionPage.ShowUnhandledException(ex);
                }
            });
        }
Пример #18
0
        // Method for when the user selects the UART device from the UI
        private async void OnDeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            // Convert MAC Address to BluetoothAddress
            // remove the colons
            macAddress = macAddress.Replace(":", "");
            Debug.WriteLine("Formatted MAC Address " + macAddress);
            bluetoothAddress = ulong.Parse(macAddress, System.Globalization.NumberStyles.HexNumber);
            Debug.WriteLine("Converted Bluetooth Address is " + bluetoothAddress);

            // Connect via the BluetoothAddress

            leDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(bluetoothAddress);

            Debug.WriteLine("============");
            Debug.WriteLine("============");
            Debug.WriteLine("============");

            Debug.WriteLine("Made it past BluetoothLEDevice");
            Debug.WriteLine("Name is " + leDevice.Name);
            Debug.WriteLine("ConnectionStatus is " + leDevice.ConnectionStatus);
            Debug.WriteLine("DeviceId is " + leDevice.DeviceId);
            Debug.WriteLine("Number of GattServices are " + leDevice.GattServices.Count);

            Debug.WriteLine("=GATT SERVICES=");
            GattDeviceService selectedService = null;

            foreach (GattDeviceService gds in leDevice.GattServices)
            {
                Debug.WriteLine("GattDeviceService.uuid: " + gds.Uuid);
                selectedService = gds;
            }

            Debug.WriteLine("============");
            Debug.WriteLine("============");
            Debug.WriteLine("============");

            Debug.WriteLine("=GATT CHARACTERISTICS FOR " + selectedService.Uuid + " =");

            var allCharacteristics = selectedService.GetAllCharacteristics();
            GattCharacteristic selectedCharacteristic = null;

            foreach (GattCharacteristic gc in allCharacteristics)
            {
                Debug.WriteLine("GattCharacteristic.Uuid: " + gc.Uuid);
                Debug.WriteLine("GattCharacteristic.UserDescriptions: " + gc.UserDescription);
                Debug.WriteLine("GattCharacteristic.AttributeHandle: " + gc.AttributeHandle);
                Debug.WriteLine("GattCharacteristic.CharacteristicProperties: " + gc.CharacteristicProperties);
                Debug.WriteLine("***");

                selectedCharacteristic = gc;
            }

            Debug.WriteLine("Selected Characteristic: " + selectedCharacteristic.Uuid);

            // There are two things to take care of before getting notifications:
            // 1. Write to Client Characteristic Configuration Description (CCCD)

            GattCommunicationStatus status = await selectedCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

            if (status == GattCommunicationStatus.Success)
            {
                Debug.WriteLine("Successfully wrote to CCCD");
                selectedCharacteristic.ValueChanged += Characteristic_ValueChanged;
            }
            else
            {
                Debug.WriteLine("Unsuccessful writing to CCCD");
            }

            // 2. Handle the Characteristic.valueChanged event



            // MAYBE OBSOLETE: InitializeRingSensor(selectedService);
        }
		//void XmlExplorerClick(DeviceLinkEventArgs evarg) {
		//    var view = container.Resolve<XMLExplorerView>();
		//    var viewModel = view.DataContext as XMLExplorerViewModel;
		//    if (viewModel != null) {
		//        viewModel.Init(evarg.session, evarg.currentAccount);
		//    }
		//    ShowView(view, "xmlexplorer_view", RegionNames.reg_property);
		//}

		#endregion DeviceLinks

		void OnSelectedDeviceChanged(DeviceSelectedEventArgs evArgs) {
			if (evArgs.devHolder == null) {
				return;
			}
			//var view = container.Resolve<DeviceView>();
			//view.Init(evArgs.devHolder, evArgs.sessionFactory);

			var view = container.Resolve<OnvifEntityPanel>();
			view.Init(evArgs.devHolder, evArgs.sessionFactory, container);

			//var viewModel = view.DataContext as DeviceViewModel;
			//if (viewModel != null) {
			//    viewModel.Init(evArgs.devHolder, evArgs.sessionFactory);
			//}
			ReleaseUI();
			ShowView(view, RegionNames.reg_entity_view, RegionNames.reg_device);
		}
        private async void Picker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {       
            //Casting must occur from the UI thread.  This dispatches the casting calls to the UI thread.
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                { 
                // Set status to Connecting
                picker.SetDisplayStatus(args.SelectedDevice, "Connecting", DevicePickerDisplayStatusOptions.ShowProgress);
                
                // Getting the selected device improves debugging
                DeviceInformation selectedDevice = args.SelectedDevice;

                thisViewId = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().Id;

                // If projection is already in progress, then it could be shown on the monitor again
                // Otherwise, we need to create a new view to show the presentation
                if (rootPage.ProjectionViewPageControl == null)
                {
                    // First, create a new, blank view
                    var thisDispatcher = Window.Current.Dispatcher;
                    
                    await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        // ViewLifetimeControl is a wrapper to make sure the view is closed only
                        // when the app is done with it
                        rootPage.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();

                        // Assemble some data necessary for the new page
                        pvb.MainPageDispatcher = thisDispatcher;
                        pvb.ProjectedPageDispatcher = this.Dispatcher; // Hold a reference to this new UI thread Dispatcher object
                        pvb.ProjectionViewPageControl = rootPage.ProjectionViewPageControl;
                        pvb.MainViewId = thisViewId;

                        // Display the page in the view. Note that the view will not become visible
                        // until "StartProjectingAsync" is called
                        var rootFrame = new Frame();
                        rootFrame.Navigate(typeof(ProjectionViewPage), pvb);
                        Window.Current.Content = rootFrame;

                        Window.Current.Activate();
                    });
                }

                try
                {
                    // Start/StopViewInUse are used to signal that the app is interacting with the
                    // view, so it shouldn't be closed yet, even if the user loses access to it
                    rootPage.ProjectionViewPageControl.StartViewInUse();

                    try
                    {
                        await ProjectionManager.StartProjectingAsync(rootPage.ProjectionViewPageControl.Id, thisViewId, selectedDevice);

                    }
                    catch (Exception ex)
                    {
                        if (!ProjectionManager.ProjectionDisplayAvailable || pvb.ProjectedPage == null)
                            throw ex;
                    }

                    // ProjectionManager currently can throw an exception even when projection has started.
                    // Re-throw the exception when projection has not been started after calling StartProjectingAsync 
                    if (ProjectionManager.ProjectionDisplayAvailable && pvb.ProjectedPage != null)
                    {
                        this.player.Pause();
                        await pvb.ProjectedPage.SetMediaSource(this.player.Source, this.player.Position);
                        activeDevice = selectedDevice;
                        // Set status to Connected
                        picker.SetDisplayStatus(args.SelectedDevice, "Connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton);
                        picker.Hide(); 
                    }
                    else
                    {
                        rootPage.NotifyUser(string.Format("Projection has failed to '{0}'", selectedDevice.Name), NotifyType.ErrorMessage);
                        // Set status to Failed
                        picker.SetDisplayStatus(args.SelectedDevice, "Connection Failed", DevicePickerDisplayStatusOptions.ShowRetryButton);
                    }
                }
                catch (Exception)
                {
                    rootPage.NotifyUser(string.Format("Projection has failed to '{0}'", selectedDevice.Name), NotifyType.ErrorMessage);
                    // Set status to Failed
                    try { picker.SetDisplayStatus(args.SelectedDevice, "Connection Failed", DevicePickerDisplayStatusOptions.ShowRetryButton); } catch { }
                }
                }
                catch (Exception ex)
                {
                    UnhandledExceptionPage.ShowUnhandledException(ex);
                }
            });
        }
        private async void DevicePicker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                DeviceInformation selectedDevice = args.SelectedDevice;

#if DEBUG
                // The args.SelectedCastingDevice is proxied from the picker process. The picker process is 
                // dismissmed as soon as you break into the debugger. Creating a non-proxied version 
                // allows debugging since the proxied version stops working once the picker is dismissed.
                selectedDevice = await DeviceInformation.CreateFromIdAsync(args.SelectedDevice.Id);
#endif

                if (await DialDevice.DeviceInfoSupportsDialAsync(selectedDevice))
                {
                    await SendDialParameter(sender, args);
                }
                else if (await CastingDevice.DeviceInfoSupportsCastingAsync(selectedDevice))
                {
                    await CastingVideoToScreen(sender, args);
                }
                else if (ProjectionManager.ProjectionDisplayAvailable)
                {
                    await ProjectioinViewToScreen(sender, args);
                }
            });
        }
        private async Task ProjectioinViewToScreen(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            // 更新 picker 上設備的 status
            sender.SetDisplayStatus(args.SelectedDevice, "Connecting", DevicePickerDisplayStatusOptions.ShowProgress);

            // 取得目前選到設備的資訊
            activeDevice = args.SelectedDevice;

            // 現在 view 的 Id 與 CoreDispatcher
            int currentViewId = ApplicationView.GetForCurrentView().Id;
            CoreDispatcher currentDispatcher = Window.Current.Dispatcher;

            // 建立新的 view,
            if (projectionInstance.ProjectionViewPageControl == null)
            {
                await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // 建立新 viewe 的生命管理器
                    projectionInstance.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();
                    projectionInstance.MainViewId = currentViewId;

                    var rootFrame = new Frame();
                    rootFrame.Navigate(typeof(ProjectionPage), projectionInstance);

                    // 這裏的 Window 代表是新建立這個 view 的 Window
                    // 但是要等到呼叫 ProjectionManager.StartProjectingAsync 才會顯示
                    Window.Current.Content = rootFrame;
                    Window.Current.Activate();
                });
            }

            // 直接切換到指定的 view id
            //bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(projectionInstance.ProjectionViewPageControl.Id);

            // 通知要使用新的 view
            projectionInstance.ProjectionViewPageControl.StartViewInUse();
            await ProjectionManager.SwapDisplaysForViewsAsync(projectionInstance.ProjectionViewPageControl.Id, currentViewId);
            try
            {
                await ProjectionManager.StartProjectingAsync(projectionInstance.ProjectionViewPageControl.Id, currentViewId, activeDevice);

                player.Pause();

                sender.SetDisplayStatus(args.SelectedDevice, "connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton);
            }
            catch (Exception ex)
            {
                sender.SetDisplayStatus(args.SelectedDevice, ex.Message, DevicePickerDisplayStatusOptions.ShowRetryButton);
                if (ProjectionManager.ProjectionDisplayAvailable == false)
                {
                    throw;
                }
            }
        }
        private async Task SendDialParameter(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            try
            {
                // 設定遠端設備現在要準備連綫
                sender.SetDisplayStatus(args.SelectedDevice, "connecting", DevicePickerDisplayStatusOptions.ShowProgress);

                // 取得遠端設備中支援指定 app name 的 App              
                DialDevice dialDevice = await DialDevice.FromIdAsync(args.SelectedDevice.Id);
                DialApp app = dialDevice.GetDialApp("castingsample");

                if (app == null)
                {
                    // 嘗試建立 DIAL device,如果失敗代表那個設備不支援 DIAL
                    sender.SetDisplayStatus(args.SelectedDevice, "The app is not exist in the device.", DevicePickerDisplayStatusOptions.ShowRetryButton);
                }
                else
                {
                    // 請求送出參數到遠端設備的 App 
                    DialAppLaunchResult result = await app.RequestLaunchAsync("Test");

                    if (result == DialAppLaunchResult.Launched)
                    {
                        activeDevice = args.SelectedDevice;
                        sender.SetDisplayStatus(args.SelectedDevice, "connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton);
                        sender.Hide();
                    }
                    else
                    {
                        sender.SetDisplayStatus(args.SelectedDevice, "Device Error", DevicePickerDisplayStatusOptions.ShowRetryButton);
                    }
                }
            }
            catch (Exception ex)
            {
                sender.SetDisplayStatus(args.SelectedDevice, ex.Message, DevicePickerDisplayStatusOptions.None);
            }
        }