Ejemplo n.º 1
0
        public async void SearchChromecasts()
        {
            IChromecastLocator locator = new MdnsChromecastLocator();
            var chromecasts            = await locator.FindReceiversAsync();

            Assert.NotEmpty(chromecasts);
        }
Ejemplo n.º 2
0
        public async static Task <ChromecastReceiver> FindChromecast()
        {
            IChromecastLocator locator = new MdnsChromecastLocator();
            var chromecasts            = await locator.FindReceiversAsync();

            return(chromecasts.First());
        }
Ejemplo n.º 3
0
        public async void SearchChromecastsCancellationToken()
        {
            IChromecastLocator locator = new MdnsChromecastLocator();
            var source      = new CancellationTokenSource(TimeSpan.FromMilliseconds(1500));
            var chromecasts = await locator.FindReceiversAsync(source.Token);

            Assert.NotEmpty(chromecasts);
        }
Ejemplo n.º 4
0
        public async void SearchChromecastsWithTooShortTimeout()
        {
            IChromecastLocator      locator = new MdnsChromecastLocator();
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(0));
            var chromecasts = await locator.FindReceiversAsync(cancellationTokenSource.Token);

            Assert.Empty(chromecasts);
        }
Ejemplo n.º 5
0
        public async static Task <ChromecastReceiver> FindChromecast(string name, double timeoutSeconds)
        {
            IChromecastLocator locator = new MdnsChromecastLocator();
            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(timeoutSeconds));
            var chromecasts = await locator.FindReceiversAsync(cts.Token);

            return(chromecasts.First(x => x.Name == name));
        }
Ejemplo n.º 6
0
        public async void SearchChromecastsTrickerEvent()
        {
            int counter = 0;
            IChromecastLocator locator = new MdnsChromecastLocator();

            locator.ChromecastReceivedFound += delegate(object sender, ChromecastReceiver e)
            {
                counter++;
            };
            var chromecasts = await locator.FindReceiversAsync();

            Assert.NotEmpty(chromecasts);
            Assert.NotEqual(0, counter);
        }
Ejemplo n.º 7
0
        public async Task LoadChromecasts()
        {
            try
            {
                LoadingChromecasts = true;
                IChromecastLocator locator = new MdnsChromecastLocator();
                Chromecasts                   = new ObservableCollection <ChromecastReceiver>(await locator.FindReceiversAsync());
                LoadingChromecasts            = false;
                AnyChromecast                 = Chromecasts.Any();
                ChooseChromecastDeviceCommand = new RelayCommand <ChromecastReceiver>(device =>
                {
                    ConnectingToChromecast      = true;
                    _message.ChromecastReceiver = device;
                    _message.CloseCastDialog    = () =>
                    {
                        ConnectingToChromecast = false;
                        ConnectedToChromecast  = true;
                        CloseCommand.Execute(null);
                    };

                    Task.Run(async() =>
                    {
                        await _message.StartCast.Invoke(device);
                    });
                });
            }
            catch (Exception ex)
            {
                LoadingChromecasts = false;
                AnyChromecast      = false;
                Logger.Error(ex);
                Messenger.Default.Send(
                    new UnhandledExceptionMessage(
                        new PopcornException(LocalizationProviderHelper.GetLocalizedValue <string>("CastFailed"))));
                CloseCommand.Execute(null);
            }
        }