Exemplo n.º 1
0
        public void ShouldEnqueueItemWithEvents()
        {
            // arrange
            var expected = "1";
            var target = new ObservableQueue<string>();

            // act
            Assert.PropertyChanged( target, "Count", () => target.Enqueue( expected ) );

            // assert
            Assert.Equal( 1, target.Count );
            Assert.Equal( expected, target.Peek() );
        }
Exemplo n.º 2
0
        public void ShouldPeekItem()
        {
            // arrange
            var target = new ObservableQueue<string>();

            target.Enqueue( "2" );
            target.Enqueue( "1" );
            target.Enqueue( "3" );

            // act
            var actual = target.Peek();

            // assert
            Assert.Equal( "2", actual );
        }
Exemplo n.º 3
0
        private async void Run()
        {
            while (true)
            {
                if (_solutionQueue.Count > 0)
                {
                    _cts = new CancellationTokenSource();
                    Solution solution = _solutionQueue.Peek();
                    await solution.AnalyzeAsync(_cts.Token);

                    DequeueSolution();
                    _cts = null;
                }
                else
                {
                    await Task.Delay(500);
                }
            }
        }
Exemplo n.º 4
0
        public SpeechSynthManager()
        {
            TTSQueue     = new ObservableQueue <SpeechString>();
            TTSHistory   = new ObservableQueue <SpeechString>();
            _queueTaskCt = new CancellationTokenSource();
            var token = _queueTaskCt.Token;

            _queueTask = Task.Run(async() =>
            {
                while (true)
                {
                    // cancel if requested.
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    // if the queue has entries, play the next one.
                    if (TTSQueue.Count > 0)
                    {
                        // this will await until the TTS clip has finished playing.
                        SpeechString str = TTSQueue.Peek();
                        await Application.Current.Dispatcher.BeginInvoke(new Action(() => this.TTSQueue.Dequeue()));
                        await Speak(str);
                    }
                }
            }, token);

            // hack method to get installed voices because there's no direct method of getting these
            var tmp = new SpeechSynthesizer();

            Voices = tmp.GetInstalledVoices();
            tmp.Dispose();

            Instance = this;
        }
Exemplo n.º 5
0
        public void ShoulNotPeekItemWhenEmpty()
        {
            // arrange
            var target = new ObservableQueue<string>();

            // act
            Assert.Throws<InvalidOperationException>( () => target.Peek() );

            // assert
        }
Exemplo n.º 6
0
        private void startNextEpisodeDownload(TransferPreferences useTransferPreferences = TransferPreferences.AllowCellularAndBattery)
        {
            if (BackgroundTransferService.Requests.Count() > 0)
            {
                // For some reason there are still old requests in the background transfer service.
                // Let's clean everything and start over.
                foreach (BackgroundTransferRequest t in BackgroundTransferService.Requests.AsEnumerable())
                {
                    BackgroundTransferService.Remove(t);
                }
            }

            if (m_episodeDownloadQueue.Count > 0)
            {
                m_currentEpisodeDownload = m_episodeDownloadQueue.Peek();
                Uri downloadUri;
                try
                {
                    downloadUri = new Uri(m_currentEpisodeDownload.EpisodeDownloadUri, UriKind.Absolute);
                }
                catch (Exception e)
                {
                    App.showErrorToast("Cannot download the episode.");
                    Debug.WriteLine("Cannot download the episode. URI exception: " + e.Message);
                    m_currentEpisodeDownload.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Idle;
                    m_episodeDownloadQueue.Dequeue();
                    saveEpisodeInfoToDB(m_currentEpisodeDownload);
                    startNextEpisodeDownload();
                    return;
                }

                m_currentEpisodeDownload.EpisodeFile = generateLocalEpisodeFileName(m_currentEpisodeDownload);
                if (string.IsNullOrEmpty(m_currentEpisodeDownload.EpisodeFile))
                {
                    App.showErrorToast("Cannot download the episode.");
                    Debug.WriteLine("Cannot download the episode. Episode file name is null or empty.");
                    m_currentEpisodeDownload.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Idle;
                    m_episodeDownloadQueue.Dequeue();
                    saveEpisodeInfoToDB(m_currentEpisodeDownload);
                    startNextEpisodeDownload();
                    return;
                }

                // Create a new background transfer request for the podcast episode download.
                m_currentBackgroundTransfer = new BackgroundTransferRequest(downloadUri,
                                                                            new Uri(m_currentEpisodeDownload.EpisodeFile, UriKind.Relative));
                if (useTransferPreferences == TransferPreferences.None)
                {
                    m_currentBackgroundTransfer.TransferPreferences = TransferPreferences.None;
                }
                else if (canAllowCellularDownload(m_currentEpisodeDownload))
                {
                    bool settingsAllowCellular = false;
                    using (var db = new PodcastSqlModel())
                    {
                        settingsAllowCellular = db.settings().IsUseCellularData;
                    }

                    Debug.WriteLine("Settings: Allow cellular download: " + settingsAllowCellular);

                    if (settingsAllowCellular && canDownloadOverCellular())
                    {
                        m_currentBackgroundTransfer.TransferPreferences = TransferPreferences.AllowCellularAndBattery;
                    }
                    else
                    {
                        m_currentBackgroundTransfer.TransferPreferences = TransferPreferences.AllowBattery;
                    }
                }
                else
                {
                    m_currentBackgroundTransfer.TransferPreferences = TransferPreferences.None;
                }

                Debug.WriteLine("m_currentBackgroundTransfer.TransferPreferences = " + m_currentBackgroundTransfer.TransferPreferences.ToString());

                m_currentBackgroundTransfer.TransferStatusChanged += new EventHandler <BackgroundTransferEventArgs>(backgroundTransferStatusChanged);

                // Store request to the episode.
                m_currentEpisodeDownload.DownloadRequest = m_currentBackgroundTransfer;

                m_applicationSettings.Remove(App.LSKEY_PODCAST_EPISODE_DOWNLOADING_ID);
                m_applicationSettings.Add(App.LSKEY_PODCAST_EPISODE_DOWNLOADING_ID, m_currentEpisodeDownload.EpisodeId);
                m_applicationSettings.Save();

                try
                {
                    BackgroundTransferService.Add(m_currentBackgroundTransfer);
                }
                catch (InvalidOperationException)
                {
                    foreach (BackgroundTransferRequest r in BackgroundTransferService.Requests)
                    {
                        BackgroundTransferService.Remove(r);
                    }

                    BackgroundTransferService.Add(m_currentBackgroundTransfer);
                }
            }
        }