Esempio n. 1
0
        private async void Picker_DisconnectButtonClicked(DialDevicePicker sender, DialDisconnectButtonClickedEventArgs 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
                {
                    rootPage.NotifyUser(string.Format("Picker DisconnectButtonClicked event fired for device '{0}'", activeDeviceInformation.Name), NotifyType.StatusMessage);

                    // Get the DialDevice instance for the selected device
                    DialDevice selectedDialDevice = await DialDevice.FromIdAsync(args.Device.Id);
                    // Update the picker status
                    picker.SetDisplayStatus(selectedDialDevice, DialDeviceDisplayStatus.Connecting);

                    DialApp app = selectedDialDevice.GetDialApp(this.dial_appname_textbox.Text);

                    //Get the current application state
                    //DialAppStateDetails stateDetails = await app.GetAppStateAsync();

                    DialAppStopResult result = await app.StopAsync();

                    if (result == DialAppStopResult.Stopped)
                    {
                        // In case getting the application state failed because of a network failure, you could add retry logic
                        rootPage.NotifyUser("Application stopped successfully.", NotifyType.StatusMessage);
                        picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Disconnected);
                        activeDialDevice        = null;
                        activeDeviceInformation = null;
                        picker.Hide();
                    }
                    else
                    {
                        if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure)
                        {
                            // In case getting the application state failed because of a network failure, you could add retry logic
                            rootPage.NotifyUser(string.Format("Error occured trying to stop application. Status: '{0}'", result.ToString()), NotifyType.StatusMessage);
                            picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Error);
                        }
                        else //in case of DialAppStopResult.OperationNotSupported, there is not much more you can do. You could implement your own
                             // mechanism to stop the application on that device.
                        {
                            // In case getting the application state failed because of a network failure, you could add retry logic
                            rootPage.NotifyUser(string.Format("Stop is not supported by device: '{0}'", activeDeviceInformation.Name), NotifyType.ErrorMessage);
                            activeDialDevice        = null;
                            activeDeviceInformation = null;
                        }
                    }
                }
                catch (Exception ex)
                {
                    UnhandledExceptionPage.ShowUnhandledException(ex);
                }
            });
        }
        private async void Picker_DisconnectButtonClicked(DialDevicePicker sender, DialDisconnectButtonClickedEventArgs args)
        {
            // casting 必須在 UI Thread 下執行
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                {                    
                    // 取得被選擇的 dial device
                    DialDevice selectedDialDevice = await DialDevice.FromIdAsync(args.Device.Id);
                    // 更新 picker status
                    picker.SetDisplayStatus(selectedDialDevice, DialDeviceDisplayStatus.Connecting);
                    // 取得 dial app 
                    DialApp app = selectedDialDevice.GetDialApp(txtAppName.Text);
                  
                    // 請求斷綫
                    DialAppStopResult result = await app.StopAsync();

                    if (result == DialAppStopResult.Stopped)
                    {
                        picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Disconnected);
                        activeDialDevice = null;
                        activeDeviceInformation = null;
                        picker.Hide();
                        tblMsg.Text += "Stoped, success";
                    }
                    else
                    {
                        if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure)
                        {
                            // 如果失敗的話要記得多 retry 的機制
                            picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Error);
                            tblMsg.Text += $"Stoped, {result}";
                        }
                        else
                        {
                            // 如果設備沒有支援 Stop 機制,則直接清楚連綫就好
                            activeDialDevice = null;
                            activeDeviceInformation = null;
                            tblMsg.Text += "the device does not support Stop";
                        }
                    }
                }
                catch (Exception ex)
                {
                    tblMsg.Text += ex.Message;
                }
            });
        }
Esempio n. 3
0
        private async void Picker_DisconnectButtonClicked(DialDevicePicker sender, DialDisconnectButtonClickedEventArgs args)
        {
            // casting 必須在 UI Thread 下執行
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    // 取得被選擇的 dial device
                    DialDevice selectedDialDevice = await DialDevice.FromIdAsync(args.Device.Id);
                    // 更新 picker status
                    picker.SetDisplayStatus(selectedDialDevice, DialDeviceDisplayStatus.Connecting);
                    // 取得 dial app
                    DialApp app = selectedDialDevice.GetDialApp(txtAppName.Text);

                    // 請求斷綫
                    DialAppStopResult result = await app.StopAsync();

                    if (result == DialAppStopResult.Stopped)
                    {
                        picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Disconnected);
                        activeDialDevice        = null;
                        activeDeviceInformation = null;
                        picker.Hide();
                        tblMsg.Text += "Stoped, success";
                    }
                    else
                    {
                        if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure)
                        {
                            // 如果失敗的話要記得多 retry 的機制
                            picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Error);
                            tblMsg.Text += $"Stoped, {result}";
                        }
                        else
                        {
                            // 如果設備沒有支援 Stop 機制,則直接清楚連綫就好
                            activeDialDevice        = null;
                            activeDeviceInformation = null;
                            tblMsg.Text            += "the device does not support Stop";
                        }
                    }
                }
                catch (Exception ex)
                {
                    tblMsg.Text += ex.Message;
                }
            });
        }
        private async void Picker_DisconnectButtonClicked(DialDevicePicker sender, DialDisconnectButtonClickedEventArgs 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
                {
                    rootPage.NotifyUser(string.Format("Picker DisconnectButtonClicked event fired for device '{0}'", activeDeviceInformation.Name), NotifyType.StatusMessage);

                    // Get the DialDevice instance for the selected device
                    DialDevice selectedDialDevice = await DialDevice.FromIdAsync(args.Device.Id);
                    // Update the picker status
                    picker.SetDisplayStatus(selectedDialDevice, DialDeviceDisplayStatus.Connecting);

                    DialApp app = selectedDialDevice.GetDialApp(this.dial_appname_textbox.Text);

                    //Get the current application state
                    //DialAppStateDetails stateDetails = await app.GetAppStateAsync();

                    DialAppStopResult result = await app.StopAsync();

                    if (result == DialAppStopResult.Stopped)
                    {
                        // In case getting the application state failed because of a network failure, you could add retry logic
                        rootPage.NotifyUser("Application stopped successfully.", NotifyType.StatusMessage);
                        picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Disconnected);
                        activeDialDevice = null;
                        activeDeviceInformation = null;
                        picker.Hide(); 
                    }
                    else
                    {
                        if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure)
                        {
                            // In case getting the application state failed because of a network failure, you could add retry logic
                            rootPage.NotifyUser(string.Format("Error occured trying to stop application. Status: '{0}'", result.ToString()), NotifyType.StatusMessage);
                            picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Error);
                        }
                        else //in case of DialAppStopResult.OperationNotSupported, there is not much more you can do. You could implement your own
                             // mechanism to stop the application on that device.
                        {
                            // In case getting the application state failed because of a network failure, you could add retry logic
                            rootPage.NotifyUser(string.Format("Stop is not supported by device: '{0}'", activeDeviceInformation.Name), NotifyType.ErrorMessage);
                            activeDialDevice = null;    
                            activeDeviceInformation = null;
                            
                        }
                    }
                }
                catch (Exception ex)
                {
                    UnhandledExceptionPage.ShowUnhandledException(ex);
                }

            });
        }
Esempio n. 5
0
        private async void Picker_DisconnectButtonClicked(DialDevicePicker sender, DialDisconnectButtonClickedEventArgs 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() =>
            {
                // 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.
                DialDevice selectedDevice = await DialDevice.FromIdAsync(args.Device.Id);

                // Get the DeviceInformation instance for the the selected device
                DeviceInformation selectedDeviceInfo = await DeviceInformation.CreateFromIdAsync(selectedDevice.Id);

                // Update the picker status
                try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Disconnecting); } catch { }

                DialApp app = args.Device.GetDialApp(this.dial_appname_textbox.Text);

                //Get the current application state
                DialAppStateDetails stateDetails = await app.GetAppStateAsync();

                switch (stateDetails.State)
                {
                case DialAppState.NetworkFailure:
                    {
                        // In case getting the application state failed because of a network failure, you could add retry logic
                        rootPage.NotifyUser("Network Failure while getting application state", NotifyType.ErrorMessage);
                        // Update the picker status
                        try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Error); } catch { }
                        break;
                    }

                case DialAppState.Stopped:
                    {
                        // In case getting the application state failed because of a network failure, you could add retry logic
                        rootPage.NotifyUser("Application was already stopped.", NotifyType.StatusMessage);
                        try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Disconnected); } catch { }
                        break;
                    }

                default:
                    {
                        DialAppStopResult result = await app.StopAsync();

                        if (result == DialAppStopResult.Stopped)
                        {
                            // In case getting the application state failed because of a network failure, you could add retry logic
                            rootPage.NotifyUser("Application stopped successfully.", NotifyType.StatusMessage);
                            try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Disconnected); } catch { }
                        }
                        else
                        {
                            if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure)
                            {
                                // In case getting the application state failed because of a network failure, you could add retry logic
                                rootPage.NotifyUser(string.Format("Error occured trying to stop application. Status: '{0}'", result.ToString()), NotifyType.StatusMessage);
                                try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Error); } catch { }
                            }
                            else     //in case of DialAppStopResult.OperationNotSupported, there is not much more you can do. You could implement your own
                                     // mechanism to stop the application on that device.
                            {
                                // In case getting the application state failed because of a network failure, you could add retry logic
                                rootPage.NotifyUser(string.Format("Stop is not supported by device: '{0}'", selectedDeviceInfo.Name), NotifyType.ErrorMessage);
                            }
                        }
                        break;
                    }
                }
            });
        }