private async Task <AnimatedThumbnailsResponse> CreateAnimatedThumbnails(long videoId) { Video video = new Video(); while (video.Status != "available") { _sleepService.Sleep(20 * 1000); var response = await _getVideoService.ExecuteAsync(videoId.ToString()); if (response?.Data == null) { _logger.LogError($"Video does not exist on vimeo!"); return(null); } video = response.Data; } var startAnimation = GetRandomStart(video.Duration > 6 ? video.Duration : 0); var addAnimatedThumbnailsToVideoRequest = new AddAnimatedThumbnailsToVideoRequest(videoId, startAnimation, video.Duration >= 6 ? 6 : video.Duration); var addAnimatedThumbnailsToVideoResult = await _addAnimatedThumbnailsToVideoService.ExecuteAsync(addAnimatedThumbnailsToVideoRequest); var pictureId = addAnimatedThumbnailsToVideoResult?.Data?.PictureId; if (string.IsNullOrEmpty(pictureId)) { _logger.LogError($"Creating Animated Thumbnails Error!"); _logger.LogError($"StatusCode: {addAnimatedThumbnailsToVideoResult?.Code}"); _logger.LogError($"Error: {addAnimatedThumbnailsToVideoResult?.Text}"); return(null); } var statusAnimatedThumbnails = string.Empty; var getStatusAnimatedThumbnailRequest = new GetAnimatedThumbnailRequest(videoId, pictureId); while (statusAnimatedThumbnails != "completed") { var statusResult = await _getStatusAnimatedThumbnailService.ExecuteAsync(getStatusAnimatedThumbnailRequest); if (statusResult.Code == System.Net.HttpStatusCode.InternalServerError || statusResult.Code == System.Net.HttpStatusCode.Unauthorized || statusResult.Code == System.Net.HttpStatusCode.NotFound) { statusAnimatedThumbnails = string.Empty; } else { statusAnimatedThumbnails = statusResult.Data.Status; } _sleepService.Sleep(5 * 1000); } var getAnimatedThumbnailResult = await _getAnimatedThumbnailService.ExecuteAsync(getStatusAnimatedThumbnailRequest); _logger.LogInformation($"Creating Animated Thumbnails Done!"); return(getAnimatedThumbnailResult.Data); }
public async Task ManageCloseout(OpenOrderResult openingOrderSummary) { if (openingOrderSummary.OpenOrderRequest.Tracking.HasValue) { _sleepService.Sleep(openingOrderSummary.OpenOrderRequest.Tracking.Value); await CloseoutBet(openingOrderSummary); } else { return; } }
public async Task <OpenOrderResult> PlaceOpeningOrder(TradeDetail trade, IEnumerable <TradeDetail> relatedTrades) { var market = trade.Match.BetfairData.Markets.Single(x => x.MarketName == trade.MarketName); var runnerId = market.Runners.Single(x => x.Name == trade.RunnerName).Id; var latestRunnerBook = await _runnerService.GetRunnerDetails(market.MarketId, runnerId); var orderTick = _orderPriceFinder.GetPrice(trade.Side, latestRunnerBook.ExchangePrices); var openingOrderWrapper = new OrderWrapper(market.MarketId, runnerId, trade.Side, orderTick, PersistenceType.LAPSE); var policy = Policy.Handle <MarketSuspendedException>().Or <OrderActionErrorException>().Or <OrderNotPlaceableException>().WaitAndRetry(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt * 4))); var betReport = await policy.Execute(() => _orderPlacer.PlaceOrder(openingOrderWrapper)); var betId = betReport.InstructionReports.Single().BetId; openingOrderWrapper.AddBetId(betId); _sleepService.Sleep(5000); var matchReport = await _runnerService.GetRunnerDetails(market.MarketId, runnerId); var orderReport = matchReport.Orders.Where(x => x.BetId == betId).Sum(x => x.SizeRemaining); if (orderReport != 0) { var cancelReport = await _orderPlacer.CancelOrder(betId, market.MarketId); if (cancelReport.Status == ExecutionReportStatus.SUCCESS) { throw new OrderCancelledException(betId); } } return(new OpenOrderResult(trade, openingOrderWrapper)); }
public void DoSomething(int interval) { while (true) { _sleepService.Sleep(interval); break; } }
public void DoSomething(int millisecondsTimeout) { while (true) { _sleepService.Sleep(millisecondsTimeout); break; } }
private async Task SleepBeforeNextRetry(int timesRetried, string url) { var timeToSleep = _retryStrategy.GetTimeToWaitBeforeNextRetry(timesRetried); await _sleepService.Sleep(Convert.ToInt32(Math.Floor(timeToSleep.TotalMilliseconds))); }
public void ProcessCustomer(Customer customer, int processTimeInSeconds) { sleepService.Sleep(processTimeInSeconds * 1000); customer.Finished = DateTime.Now; }