private void OnRequestComplete() { if (CancellationTokenSource.IsCancellationRequested) { return; } RequestTask task = Tasks.Last(x => x.Response.IsCompleted); if (task.Response.IsCanceled) { CliNotifier.PrinWarning("Cannot load response"); } else if (task.Response.IsFaulted) { CliNotifier.PrinWarning("Server cancel connection"); } else { task.EndedAt = DateTime.Now.TimeOfDay; CliNotifier.PrintInfo($"Request finished by: {task.TotalExecutionTime} with status code: { task.Response.Result.StatusCode}"); Completed.Add(task); if (IsStopSignal(task.Response.Result)) { StopExecution(); } } RuningTasks--; if (RuningTasks < ConfigParser.GetParallel()) { AddTask(); } }
public Block CreateCandidateBlock(string minerAddress) { Block blockCandidate = new Block { Index = _chain.Count, Difficulty = _nodeSettings.CurrentDifficulty, PreviousBlockHash = _chain.Last().MinerProvidedHash, MinedBy = minerAddress }; int blockIndex = _chain.Count; blockCandidate.Transactions.Add( Transaction.CreateCoinbaseTransaction( minerAddress, blockIndex)); foreach (Transaction transaction in _pendingTransactions.Values) { transaction.MinedInBlockIndex = blockIndex; transaction.TransferSuccessful = true; blockCandidate.Transactions.Add(transaction); } _miningJobs.AddOrUpdate( blockCandidate.DataHash.ToHex(), blockCandidate, (address, oldCandidate) => blockCandidate); return(blockCandidate); }
public async Task Then_it_should_wait_for_the_polling_interval_before_polling_again() { await pollingCompleted.Task.TimeoutAfter(30.Seconds()); Result.Dispose(); PollingCall lastButOneCall = pollingTimeStamps.Reverse().Skip(1).Take(1).Single(); PollingCall lastCall = pollingTimeStamps.Last(); lastCall.TimeStampUtc.Should().BeAtLeast(pollingInterval).After(lastButOneCall.TimeStampUtc); lastCall.Checkpoint.Should().Be(lastButOneCall.Checkpoint); }
public long Run(int input) { SequenceInput.Add(input); // Start all amplifiers var tasks = new List <Task>(); Amplifiers.ForEach(amp => tasks.Add(amp.Run())); Task.WaitAll(tasks.ToArray()); return(SequenceOutput.Last()); }
public string SolvePart2(IEnumerable <string> inputs) { var machine = new IntCodeMachine(inputs.First()); var input = new BlockingCollection <int>(new ConcurrentQueue <int>(new[] { 5 })); var output = new BlockingCollection <int>(); machine.Execute(input, output); if (output.Take(output.Count - 1).Any(o => o != 0)) { throw new Exception("Diagnostic failed!"); } return(output.Last().ToString()); }
public bool TryAddBlock(Block block) { var prevBlock = _blocks.Last(); var isValid = _blockValidator.Validate(block, prevBlock); if (isValid) { _blocks.Add(block); _transactionsRepository.AddTransaction(block.Transactions); _pendingTransactionRepository.RemovePending(block.Transactions); var invalidTransaction = _pendingTransactionRepository .GetPending() .Where(tran => !_transactionValidator.Validate(tran)) .ToList(); _pendingTransactionRepository.RemovePending(invalidTransaction); return(true); } return(false); }
private bool UserquakeIsOver(DateTime at) { return(userquakes == null || at.Subtract(userquakes.Last().At).TotalSeconds > 40); }
private void ConvertNewMatch(string data, ref BlockingCollection <MatchDTO> matchsSource) { JArray javaScriptArray = JavaScriptConvert.DeserializeObject(data); //MatchDTO matchDTO; MatchDTO ma = matchsSource.FirstOrDefault(m => m.ID == javaScriptArray[1].ToString()); if (ma == null) { ma = new MatchDTO(); int minute; ma.ID = javaScriptArray[1].ToString(); ma.MatchID = javaScriptArray[0].ToString(); ma.ServerType = eServerType.Ibet; ma.TimeType = ConvertMatchTime(javaScriptArray[12].ToString(), out minute); ma.Minutes = minute; ma.HomeTeamName = CleanTeamName(javaScriptArray[6].ToString()); ma.AwayTeamName = CleanTeamName(javaScriptArray[7].ToString()); ma.Odds = new List <OddDTO>(); if (javaScriptArray[4].ToString() == string.Empty) { var lMa = matchsSource.Last(); ma.LeagueID = lMa.LeagueID; ma.LeagueName = lMa.LeagueName; } else { ma.LeagueID = javaScriptArray[4].ToString(); ma.LeagueName = javaScriptArray[5].ToString(); } matchsSource.Add(ma); } ma.IsDeleted = false; //if (javaScriptArray[3].ToString() == "1") //{ // string objId; // string leagueID; // string leagueName; // int minute; // eTimeMatchType timeType; // if (javaScriptArray[4].ToString() == string.Empty) // { // //MatchOddDTO matchDTO2 = matchsSource[matchsSource.Count - 1]; // //MatchOddDTO matchDTO2 = matchsSource.FirstOrDefault(m => m.ID == javaScriptArray[1].ToString() // // && m.IsDeleted); // //objId = matchDTO2.ID; // //leagueID = matchDTO2.LeagueID; // //leagueName = matchDTO2.LeagueName; // //timeType = matchDTO2.TimeType; // //minute = matchDTO2.Minutes; // } // else // { // leagueID = javaScriptArray[4].ToString(); // leagueName = javaScriptArray[5].ToString(); // timeType = ConvertMatchTime(javaScriptArray[12].ToString(), out minute); // } // matchDTO = new MatchDTO(); // //matchDTO = new MatchDTO(javaScriptArray[1].ToString(), javaScriptArray[0].ToString(), // // eServerType.Ibet, leagueID, leagueName, // // CleanTeamName(javaScriptArray[6].ToString()), CleanTeamName(javaScriptArray[7].ToString()), // // timeType, minute); // //matchsSource.Add(matchDTO); //} //else //{ // matchDTO = new MatchDTO(); // //var oldMatchDTO = matchsSource[matchsSource.Count - 1]; // //matchDTO = new MatchOddDTO(oldMatchDTO.MatchID, oldMatchDTO.ServerType, oldMatchDTO.LeagueID, // // oldMatchDTO.LeagueName, oldMatchDTO.HomeTeamName, oldMatchDTO.AwayTeamName, oldMatchDTO.TimeType, oldMatchDTO.Minutes); // //matchsSource.Add(matchDTO); //} //var newObj = Utils.Clone(matchDTO); ////FULLTIME Chau A if (javaScriptArray[26 + ODD_INDEX].ToString().Length != 0) { UpdateOdd(ma, javaScriptArray[26 + ODD_INDEX].ToString(), eOddType.HCP, javaScriptArray[27 + ODD_INDEX].ToString(), javaScriptArray[28 + ODD_INDEX].ToString(), javaScriptArray[29 + ODD_INDEX].ToString(), javaScriptArray[30 + ODD_INDEX].ToString()); //matchsSource.Add(newObj1); } ////FULLTIME TAI XIU if (javaScriptArray[31 + ODD_INDEX].ToString().Length != 0) { UpdateOdd(ma, javaScriptArray[31 + ODD_INDEX].ToString(), eOddType.OU, javaScriptArray[32 + ODD_INDEX].ToString(), javaScriptArray[33 + ODD_INDEX].ToString(), javaScriptArray[34 + ODD_INDEX].ToString()); //matchsSource.Add(newObj1); } /////H1 Chau A if (javaScriptArray[39 + ODD_INDEX].ToString().Length != 0) { UpdateOdd(ma, javaScriptArray[39 + ODD_INDEX].ToString(), eOddType.HalfHCP, javaScriptArray[40 + ODD_INDEX].ToString(), javaScriptArray[41 + ODD_INDEX].ToString(), javaScriptArray[42 + ODD_INDEX].ToString(), javaScriptArray[43 + ODD_INDEX].ToString()); //matchsSource.Add(newObj1); } /////H1 TAI XIU if (javaScriptArray[44 + ODD_INDEX].ToString().Length != 0) { UpdateOdd(ma, javaScriptArray[44 + ODD_INDEX].ToString(), eOddType.HalfOU, javaScriptArray[45 + ODD_INDEX].ToString(), javaScriptArray[46 + ODD_INDEX].ToString(), javaScriptArray[47 + ODD_INDEX].ToString()); //matchsSource.Add(newObj1); } }