Пример #1
0
        private Action HandlePlayerApiError(string response, Action retryAction)
        {
            return(new Action(
                       async() =>
            {
                dynamic json = JsonConvert.DeserializeObject(response);

                if ("NO_ACTIVE_DEVICE".Equals((string)json.error.reason))
                {
                    DialogResult retryResult;
                    do
                    {
                        PlayerApi playerApi = new PlayerApi()
                        {
                            AuthorizationHeader = new AuthorizationHeader(await this.RunAsync(AccessTokenTask))
                        };

                        ChooseDeviceForm chooseDeviceForm = new ChooseDeviceForm(playerApi);
                        if (chooseDeviceForm.ShowDialog(this) == DialogResult.OK)
                        {
                            await playerApi.TransferPlayback(chooseDeviceForm.SelectedDevice.Id);

                            bool isDeviceActive = false;
                            for (int i = 0; !isDeviceActive && i < 5; i++)
                            {
                                dynamic devicesJson = await playerApi.GetDevices();
                                foreach (dynamic device in devicesJson.devices)
                                {
                                    if ((string)device.id != chooseDeviceForm.SelectedDevice.Id)
                                    {
                                        continue;
                                    }

                                    isDeviceActive = device.is_active;
                                }
                            }

                            if (isDeviceActive)
                            {
                                await Task.Run(retryAction);
                                break;
                            }
                        }

                        retryResult = MessageBox.Show(
                            "Select a device to play to.",
                            "No active device",
                            MessageBoxButtons.RetryCancel,
                            MessageBoxIcon.Error);
                    }while (retryResult == DialogResult.Retry);
                }
            }));
        }
Пример #2
0
        public async Task TransferPlayback_GetDevice1IdPlayTrue_NoException()
        {
            // arrange
            var        http        = new HttpClient();
            IPlayerApi player      = new PlayerApi(http);
            string     accessToken = await TestsHelper.GetUserAccessToken();

            var devices = await player.GetDevices(accessToken : accessToken);

            // act
            if (devices.Any())
            {
                await player.TransferPlayback(devices.Last().Id, play : true, accessToken : accessToken);
            }
        }