private async void DequeueTransfer() { //Get the next transfer in the queue var transfer = _queued.Dequeue(); //Wait for the transfer try { await Transfer(transfer); } catch (TransferException ex) { if (ex.InnerException.GetType() == typeof(IOException) && RequeueOnError && ex.Message.EndsWith("is being used by another process")) { transfer.State = TransferState.Requeued; _queued.Enqueue(transfer); } TransferFailed.Invoke(ex); } catch (Exception) { throw; } if (_queued.Count > 0) { DequeueTransfer(); } }
public void DequeueItem() { _handle = new EventWaitHandle(false, EventResetMode.ManualReset); var test = new ObservableQueue<string>(); test.Enqueue("test"); test.ItemDequeued += Queue_ItemDequeued; test.Dequeue(); Assert.IsTrue(_handle.WaitOne(10)); }
public void DequeueItem() { _handle = new EventWaitHandle(false, EventResetMode.ManualReset); var test = new ObservableQueue <string>(); test.Enqueue("test"); test.ItemDequeued += Queue_ItemDequeued; test.Dequeue(); Assert.IsTrue(_handle.WaitOne(10)); }
public void ShouldNotDequeueItemWhenEmpty() { // arrange var target = new ObservableQueue<string>(); // act Assert.Throws<InvalidOperationException>( () => target.Dequeue() ); // assert }
public bool MoveNext() { if (_queue.Count == 0) { return(false); } Current = _queue.Dequeue(); _dequeuedItems.Add(Current); return(true); }
private void DequeueSolution() { if (_solutionQueue.Count > 0) { Solution completed = _solutionQueue.Dequeue(); FinishedItems.Add(completed); Settings.Default.UnfinishedSolutionFileNames.Remove(completed.FilePath); Settings.Default.Save(); } }
public IMessage GetOutgoingMessage() { if (outgoingMessages.Count == 0) { return(null); } else { return(outgoingMessages.Dequeue()); } }
public void ObserveCollectionChanged() { var queue = new ObservableQueue <string>(); var args = new List <NotifyCollectionChangedEventArgs>(); queue.CollectionChanged += (o, e) => args.Add(e); queue.Enqueue("A"); args .Should().ContainSingle() .Which .Should().BeEquivalentTo( new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, "A", 0) ); args.Clear(); queue.Enqueue("B"); args .Should().ContainSingle() .Which .Should().BeEquivalentTo( new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, "B", 1) ); args.Clear(); queue.Enqueue("C"); args .Should().ContainSingle() .Which .Should().BeEquivalentTo( new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, "C", 2) ); args.Clear(); queue.Dequeue(); args .Should().ContainSingle() .Which .Should().BeEquivalentTo( new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, "A", 0) ); args.Clear(); queue.Clear(); args .Should().ContainSingle() .Which .Should().BeEquivalentTo( new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset) ); }
void HandleQueue(object sender, ConnectivityChangedEventArgs e) { if (!e.IsConnected) { System.Diagnostics.Debug.WriteLine("all the calls will be redirected to the queue"); } else { System.Diagnostics.Debug.WriteLine("....connection restabilished: ........pushing the changes to the server........"); while (Queue.Count > 0) { Queue.Dequeue(); // on dequeue() attach method for remote calls } } }
public void ShouldDequeueItemWithEvents() { // arrange var expected = "1"; string actual = null; var target = new ObservableQueue<string>(); target.Enqueue( expected ); // act Assert.PropertyChanged( target, "Count", () => actual = target.Dequeue() ); // assert Assert.Equal( 0, target.Count ); Assert.Equal( expected, actual ); }
private void Handler_IncomingMessages() { while (!roomClosing) { if (incomingMessages.Count > 0) { IMessage msg = incomingMessages.Dequeue(); if (gameObjects.ContainsKey(msg.ID)) { gameObjects[msg.ID]?.Update(msg); } } else { Thread.Sleep(1); } } }
public void DequeueItem() { // Arrange var queue = new ObservableQueue <string>(); var itemOne = "One"; var itemTwo = "Two"; var itemThree = "Three"; // Act queue.Enqueue(itemOne); queue.Enqueue(itemTwo); queue.Enqueue(itemThree); // Assert var dequeudItem = queue.Dequeue(); Assert.AreEqual(itemThree, dequeudItem, "The de-queued item was incorrect. The last item queued should have been the deqeued."); }
public void ObservePropertyChanged() { var queue = new ObservableQueue <int>(); var props = new List <string>(); var itemQuery = props.Where(p => p == "Item[]"); var countQuery = props.Where(p => p == "Count"); queue.PropertyChanged += (o, e) => props.Add(e.PropertyName); queue.Enqueue(1); itemQuery .Should().HaveCount(1); countQuery .Should().HaveCount(1); queue.Enqueue(2); itemQuery .Should().HaveCount(2); countQuery .Should().HaveCount(2); queue.Enqueue(3); itemQuery .Should().HaveCount(3); countQuery .Should().HaveCount(3); queue.Dequeue(); itemQuery .Should().HaveCount(4); countQuery .Should().HaveCount(4); queue.Clear(); itemQuery .Should().HaveCount(5); countQuery .Should().HaveCount(5); }
private ISearchFactory DequeueSettings() { return(_searchQueue.Dequeue()); }
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); } } }