Beispiel #1
0
        private async void Picker_DeviceSelected(DialDevicePicker sender, DialDeviceSelectedEventArgs 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 DeviceSelected event fired"), NotifyType.StatusMessage);

                    // Set the status to connecting
                    picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Connecting);

                    rootPage.NotifyUser(string.Format("Resolving DialDevice'"), NotifyType.StatusMessage);

                    //Get the DialApp object for the specific application on the selected device
                    DialApp app = args.SelectedDialDevice.GetDialApp(this.dial_appname_textbox.Text);

                    if (app == null)
                    {
                        //Try to create a DIAL device. If it doesn't succeed, the selected device does not support DIAL.
                        //rootPage.NotifyUser(string.Format("'{0}' cannot find app with ID '{1}'", selectedDeviceInformation.Name, this.dial_appname_textbox.Text), NotifyType.StatusMessage);
                        picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Error);
                    }
                    else
                    {
                        rootPage.NotifyUser(string.Format("Attempting to launch '{0}'", app.AppName), NotifyType.StatusMessage);
                        //Launch the application on the 1st screen device
                        DialAppLaunchResult result = await app.RequestLaunchAsync(this.dial_launch_args_textbox.Text);

                        //Verify to see whether the application was launched
                        if (result == DialAppLaunchResult.Launched)
                        {
                            rootPage.NotifyUser(string.Format("Launched '{0}'", app.AppName), NotifyType.StatusMessage);
                            activeDialDevice = args.SelectedDialDevice;
                            DeviceInformation selectedDeviceInformation = await DeviceInformation.CreateFromIdAsync(args.SelectedDialDevice.Id);

                            activeDeviceInformation = selectedDeviceInformation;

                            //This is where you will need to add you application specific communication between your 1st and 2nd screen applications
                            //...
                            //...
                            //...

                            picker.SetDisplayStatus(activeDialDevice, DialDeviceDisplayStatus.Connected);
                            picker.Hide();
                        }
                        else
                        {
                            rootPage.NotifyUser(string.Format("Attempting to launch '{0}'", app.AppName), NotifyType.StatusMessage);
                            picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Error);
                        }
                    }
                }
                catch (Exception ex)
                {
                    UnhandledExceptionPage.ShowUnhandledException(ex);
                }
            });
        }
Beispiel #2
0
        private async void Picker_DialDeviceSelected(DialDevicePicker sender, DialDeviceSelectedEventArgs 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.SelectedDialDevice.Id);

                // Set the status to connecting
                try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Connecting); } catch { }

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

                //Get the DialApp object for the specific application on the selected device
                DialApp app = selectedDevice.GetDialApp(this.dial_appname_textbox.Text);

                if (app == null)
                {
                    //Try to create a DIAL device. If it doesn't succeed, the selected device does not support DIAL.
                    rootPage.NotifyUser(string.Format("'{0}' cannot find app with ID '{1}'", selectedDeviceInfo.Name, this.dial_appname_textbox.Text), NotifyType.StatusMessage);
                    try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Error); } catch { }
                }
                else
                {
                    //Get the current application state
                    DialAppStateDetails stateDetails = await app.GetAppStateAsync();
                    if (stateDetails.State == DialAppState.NetworkFailure)
                    {
                        // In case getting the application state failed because of a network failure
                        rootPage.NotifyUser("Network Failure while getting application state", NotifyType.ErrorMessage);
                        try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Error); } catch { }
                    }
                    else
                    {
                        rootPage.NotifyUser(string.Format("Attempting to launch '{0}'", app.AppName), NotifyType.StatusMessage);
                        //Launch the application on the 1st screen device
                        DialAppLaunchResult result = await app.RequestLaunchAsync(this.dial_launch_args_textbox.Text);

                        //Verify to see whether the application was launched
                        if (result == DialAppLaunchResult.Launched)
                        {
                            rootPage.NotifyUser(string.Format("Launched '{0}'", app.AppName), NotifyType.StatusMessage);
                            //This is where you will need to add you application specific communication between your 1st and 2nd screen applications
                            //...
                            try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Connected); } catch { }
                        }
                        else
                        {
                            rootPage.NotifyUser(string.Format("Attempting to launch '{0}'", app.AppName), NotifyType.StatusMessage);
                            try { picker.SetDisplayStatus(selectedDevice, DialDeviceDisplayStatus.Error); } catch { }
                        }
                    }
                }
            });
        }
Beispiel #3
0
        private async void Picker_DialDeviceSelected(DialDevicePicker sender, DialDeviceSelectedEventArgs args)
        {
            // casting 必須在 UI Thread 下執行
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    // 設定遠端設備現在要準備連綫
                    picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Connecting);

                    // 取得遠端設備中支援指定 app name 的 App
                    DialApp app = args.SelectedDialDevice.GetDialApp(txtAppName.Text);

                    if (app == null)
                    {
                        // 嘗試建立 DIAL device,如果失敗代表那個設備不支援 DIAL
                        picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Error);
                    }
                    else
                    {
                        // 請求送出參數到遠端設備的 App
                        DialAppLaunchResult result = await app.RequestLaunchAsync(txtArgument.Text);

                        if (result == DialAppLaunchResult.Launched)
                        {
                            activeDialDevice = args.SelectedDialDevice;
                            DeviceInformation selectedDeviceInformation = await DeviceInformation.CreateFromIdAsync(args.SelectedDialDevice.Id);

                            activeDeviceInformation = selectedDeviceInformation;
                            picker.SetDisplayStatus(activeDialDevice, DialDeviceDisplayStatus.Connected);
                            picker.Hide();
                            tblMsg.Text += "device connected";
                        }
                        else
                        {
                            picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Error);
                            tblMsg.Text += "device error";
                        }
                    }
                }
                catch (Exception ex)
                {
                    tblMsg.Text += ex.Message;
                }
            });
        }
        private async void Picker_DialDeviceSelected(DialDevicePicker sender, DialDeviceSelectedEventArgs args)
        {
            // casting 必須在 UI Thread 下執行
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                {
                    // 設定遠端設備現在要準備連綫
                    picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Connecting);

                    // 取得遠端設備中支援指定 app name 的 App
                    DialApp app = args.SelectedDialDevice.GetDialApp(txtAppName.Text);

                    if (app == null)
                    {
                        // 嘗試建立 DIAL device,如果失敗代表那個設備不支援 DIAL
                        picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Error);
                    }
                    else
                    {
                        // 請求送出參數到遠端設備的 App 
                        DialAppLaunchResult result = await app.RequestLaunchAsync(txtArgument.Text);
                        
                        if (result == DialAppLaunchResult.Launched)
                        {
                            activeDialDevice = args.SelectedDialDevice;
                            DeviceInformation selectedDeviceInformation = await DeviceInformation.CreateFromIdAsync(args.SelectedDialDevice.Id);

                            activeDeviceInformation = selectedDeviceInformation;
                            picker.SetDisplayStatus(activeDialDevice, DialDeviceDisplayStatus.Connected);
                            picker.Hide();
                            tblMsg.Text += "device connected";
                        }
                        else
                        {
                            picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Error);
                            tblMsg.Text += "device error";
                        }
                    }
                }
                catch (Exception ex)
                {
                    tblMsg.Text += ex.Message;
                }
            });
        }
        private async void Picker_DeviceSelected(DialDevicePicker sender, DialDeviceSelectedEventArgs 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 DeviceSelected event fired"), NotifyType.StatusMessage);

                    // Set the status to connecting
                    picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Connecting);

                    rootPage.NotifyUser(string.Format("Resolving DialDevice'"), NotifyType.StatusMessage);
             
                    //Get the DialApp object for the specific application on the selected device
                    DialApp app = args.SelectedDialDevice.GetDialApp(this.dial_appname_textbox.Text);

                    if (app == null)
                    {
                        //Try to create a DIAL device. If it doesn't succeed, the selected device does not support DIAL.
                        //rootPage.NotifyUser(string.Format("'{0}' cannot find app with ID '{1}'", selectedDeviceInformation.Name, this.dial_appname_textbox.Text), NotifyType.StatusMessage);
                        picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Error);
                    }
                    else
                    {
                        rootPage.NotifyUser(string.Format("Attempting to launch '{0}'", app.AppName), NotifyType.StatusMessage);
                        //Launch the application on the 1st screen device
                        DialAppLaunchResult result = await app.RequestLaunchAsync(this.dial_launch_args_textbox.Text);

                        //Verify to see whether the application was launched
                        if (result == DialAppLaunchResult.Launched)
                        {
                            rootPage.NotifyUser(string.Format("Launched '{0}'", app.AppName), NotifyType.StatusMessage);
                            activeDialDevice = args.SelectedDialDevice;
                            DeviceInformation selectedDeviceInformation = await DeviceInformation.CreateFromIdAsync(args.SelectedDialDevice.Id);

                            activeDeviceInformation = selectedDeviceInformation;

                            //This is where you will need to add you application specific communication between your 1st and 2nd screen applications
                            //...
                            //...
                            //...

                            picker.SetDisplayStatus(activeDialDevice, DialDeviceDisplayStatus.Connected);
                            picker.Hide();
                        }
                        else
                        {
                            rootPage.NotifyUser(string.Format("Attempting to launch '{0}'", app.AppName), NotifyType.StatusMessage);
                            picker.SetDisplayStatus(args.SelectedDialDevice, DialDeviceDisplayStatus.Error);
                        }
                    }
                }
                catch (Exception ex)
                {
                    UnhandledExceptionPage.ShowUnhandledException(ex);
                }
            });
        }