예제 #1
0
        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();
            }
        }
예제 #2
0
 /// <summary>
 ///     Initializes a new instance of the MainViewModel class.
 /// </summary>
 public MainViewModel()
 {
     _finishedItems = new ObservableCollection <Solution>();
     if (IsInDesignMode)
     {
         _solutionQueue.Enqueue(new Solution("Solution1.sln")
         {
             Status = SolutionStatus.Running
         });
         _solutionQueue.Enqueue(new Solution("Bla.sln")
         {
             Status = SolutionStatus.Running
         });
         _solutionQueue.Enqueue(new Solution("Test Project.sln"));
         _solutionQueue.Enqueue(new Solution("Price Management.sln"));
     }
     else
     {
         Settings settings = Settings.Default;
         settings.Upgrade();
         if (settings.UnfinishedSolutionFileNames != null)
         {
             foreach (string unfinishedSolutionFileName in settings.UnfinishedSolutionFileNames)
             {
                 if (File.Exists(unfinishedSolutionFileName))
                 {
                     SolutionQueue.Enqueue(new Solution(unfinishedSolutionFileName));
                 }
             }
         }
         Run();
     }
 }
예제 #3
0
 /// <summary>
 /// Создает игроков и добавляет их на карту в список игроков и список игрвовых объектов
 /// </summary>
 private void CreatePlayers(int gamersInRoom, List <RectangleF> occupiedArea)
 {
     for (int i = 0; i < gamersInRoom; i++)
     {
         //создаем игрока
         RectangleF newShape = CreateAndAddNewUniqueShape(occupiedArea, BuilderGameObject.SizeGamer);
         var        gamer    = BuilderGameObject.CreateGamer(this, newShape.Location);
     }
     outgoingMessages.Enqueue(new ChangeCountPlayersInGame(0, Players.Count));
 }
        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)
                );
        }
예제 #5
0
        private void processOngoingTransfer()
        {
            // If key exists, we know we have need to process a download request.
            if (m_applicationSettings.Contains(App.LSKEY_PODCAST_EPISODE_DOWNLOADING_ID))
            {
                Debug.WriteLine("Found a episode download that we need to process.");
                int downloadingEpisodeId = (int)m_applicationSettings[App.LSKEY_PODCAST_EPISODE_DOWNLOADING_ID];
                m_currentEpisodeDownload = null;
                using (var db = new PodcastSqlModel())
                {
                    m_currentEpisodeDownload = db.episodeForEpisodeId(downloadingEpisodeId);
                }

                if (m_currentEpisodeDownload == null)
                {
                    Debug.WriteLine("Something went wrong. Got NULL episode when asking for episode id " + downloadingEpisodeId);

                    m_applicationSettings.Remove(App.LSKEY_PODCAST_EPISODE_DOWNLOADING_ID);
                    m_applicationSettings.Save();
                    return;
                }

                if (BackgroundTransferService.Requests.Count() > 0)
                {
                    // Found an ongoing request.
                    Debug.WriteLine("Found an ongoing transfer...");
                    m_currentBackgroundTransfer = BackgroundTransferService.Requests.ElementAt(0);
                    m_currentBackgroundTransfer.TransferStatusChanged += new EventHandler <BackgroundTransferEventArgs>(backgroundTransferStatusChanged);

                    m_currentEpisodeDownload.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Downloading;
                    m_currentEpisodeDownload.DownloadRequest      = m_currentBackgroundTransfer;

                    m_episodeDownloadQueue.Enqueue(m_currentEpisodeDownload);

                    ProcessTransfer(m_currentBackgroundTransfer);

                    saveEpisodeInfoToDB(m_currentEpisodeDownload);
                }
                else
                {
                    // No ongoing requests found. Then we need to process a finished request.
                    // Probably happened in the background while we were suspended.
                    Debug.WriteLine("Found a completed request.");
                    updateEpisodeWhenDownloaded(m_currentEpisodeDownload);
                    m_applicationSettings.Remove(App.LSKEY_PODCAST_EPISODE_DOWNLOADING_ID);
                    m_applicationSettings.Save();
                }
            }
        }
예제 #6
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 );
        }
예제 #7
0
        public override void OnItemAdded(SpreadValue item)
        {
            if (strategyHeader.Amount <= Math.Abs(tradingData.GetAmount(strategyHeader)))
            {
                return;
            }

            if (tradingData.UnfilledExists(strategyHeader, OrderType.Market))
            {
                return;
            }

            TradeAction?action = GetTradeAction(item);

            if (action == null)
            {
                return;
            }

            Signal signal = MakeSignal(item, action.Value);

            this.logger.Log(String.Format("{0:dd/MM/yyyy H:mm:ss.fff}, {1}, сгенерирован {2}.", DateTime.Now, this.GetType().Name, signal.ToString()));

            signalQueue.Enqueue(signal);
        }
예제 #8
0
        private void AddToQueueCommandHandler()
        {
            var search = SearchViewModel.SearchFactory;

            search.SetOutput(OutputFile);

            _searchQueue.Enqueue(search);
        }
 public void EnqueueItem()
 {
   _handle = new EventWaitHandle(false, EventResetMode.ManualReset);
   var test = new ObservableQueue<string>();
   test.ItemEnqueued += Queue_ItemEnqueued;
   test.Enqueue("test");
   Assert.IsTrue(_handle.WaitOne(10));
 }
예제 #10
0
 public void RecievedMessage(MessageArgs arg)
 {
     m_messages.Enqueue(new MessageVM()
     {
         Text = arg.Message
     });
     OnPropertyChanged(nameof(Messages));
 }
        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 EnqueueItem()
        {
            // 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 firstItem = queue.FirstOrDefault();

            Assert.AreEqual(itemThree, firstItem, "The queue was not in the correct order. The first item int he list should have been the last item added.");
        }
예제 #13
0
        public void EnqueueItem()
        {
            _handle = new EventWaitHandle(false, EventResetMode.ManualReset);
            var test = new ObservableQueue <string>();

            test.ItemEnqueued += Queue_ItemEnqueued;
            test.Enqueue("test");
            Assert.IsTrue(_handle.WaitOne(10));
        }
예제 #14
0
        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);
        }
예제 #15
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() );
        }
예제 #16
0
        public async Task <Guid> Create(User user, string udid)
        {
            var  create = (user.ParentUserEmail == default(string)) ? UserInitiated.Create(user, udid) : UserInitiated.Create(user, user.ParentGuid);
            Guid guid   = default(Guid);

            if (await FinetunerServerReachable())
            {
                guid = await Policy
                       .Handle <WebException>()
                       .WaitAndRetryAsync
                       (
                    retryCount: 5,
                    sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                       )
                       .ExecuteAsync(async() => await create);
            }
            else
            {
                Queue.Enqueue(user);
                System.Diagnostics.Debug.WriteLine(Queue);
            }
            return(guid);
        }
예제 #17
0
        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 );
        }
예제 #18
0
 public void AddIncomingMessage(IMessage message)
 {
     incomingMessages.Enqueue(message);
 }
예제 #19
0
 /// <summary>
 /// Enqueues an action to be committed to the database.
 /// </summary>
 /// <param name="databaseAction"></param>
 public void EnqueueAction(DatabaseAction <T> databaseAction)
 {
     // Don't acquire a write lock, this class can handle the enqueueing of new items while flushing.
     // A lock is only necessary when dequeueing items.
     _actionQueue.Enqueue(databaseAction);
 }
예제 #20
0
        public void ShouldGrowAutomatically()
        {
            var target = new ObservableQueue<string>( 3 );

            for ( var i = 0; i < 10; i++ )
                target.Enqueue( ( i + 1 ).ToString() );

            target.Clear();
            target.TrimExcess();
        }
예제 #21
0
        public void ShouldEnumerate()
        {
            var target = new ObservableQueue<string>();

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

            var items1 = (IEnumerable<string>) target;

            foreach ( var item in items1 )
                Console.WriteLine( item );

            var items2 = (IEnumerable) target;

            foreach ( string item in items2 )
                Console.WriteLine( item );
        }
예제 #22
0
        public void ShouldClearWithEvents()
        {
            // arrange
            var target = new ObservableQueue<string>();

            target.Enqueue( "1" );

            // act
            Assert.PropertyChanged( target, "Count", target.Clear );

            // assert
            Assert.Equal( 0, target.Count );
        }
예제 #23
0
        public void ShouldCopyToWhenICollection()
        {
            // arrange
            var target = new ObservableQueue<string>();
            var collection = (ICollection) target;
            var expected = new[] { "1", "2" };
            var actual = new string[2];

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

            // act
            collection.CopyTo( actual, 0 );

            // assert
            Assert.True( expected.SequenceEqual( actual ) );
        }
예제 #24
0
        public void ShouldCopyToLargeArray()
        {
            // arrange
            var expected = new[] { "1", "2" };
            var target = new ObservableQueue<string>( expected );

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

            var actual = new string[4];

            // act
            target.CopyTo( actual, 2 );

            // assert
            Assert.True( actual.Skip( 2 ).SequenceEqual( expected ) );
        }
예제 #25
0
        public void ShouldCopyToSizedArray()
        {
            // arrange
            var expected = new[] { "1", "2" };
            var target = new ObservableQueue<string>( expected );
            
            target.Enqueue( "1" );
            target.Enqueue( "2" );

            var actual = new string[2];

            // act
            target.CopyTo( actual, 0 );

            // assert
            Assert.True( expected.SequenceEqual( actual ) );
        }
예제 #26
0
        public void ShouldContainItem( string value, bool expected )
        {
            // arrange
            var target = new ObservableQueue<string>();
            
            target.Enqueue( "One" );
            target.Enqueue( "Two" );
            target.Enqueue( "Three" );
            
            // act
            var actual = target.Contains( value );

            // assert
            Assert.Equal( expected, actual );
        }
예제 #27
0
        public void ShouldTrimExcess()
        {
            // arrange
            var target = new ObservableQueue<string>( 10 );
            
            target.Enqueue( "1" );
            target.Enqueue( "2" );
            target.Enqueue( "3" );

            // act
            target.TrimExcess();

            // assert
            // no exception
        }
예제 #28
0
        public void ShouldConvertToArray()
        {
            // arrange
            var target = new ObservableQueue<string>();
            var expected = new[] { "1", "2", "3" };

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

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

            // assert
            Assert.True( expected.SequenceEqual( actual ) );
        }
예제 #29
0
 public void SubmitOrder(OrderViewModel order)
 {
     _orders.Enqueue(order);
 }