public override Request Poll() { return(NetworkCenter.Current.Execute("rds-pl", () => { return RetryExecutor.Execute(30, () => { RedisValue value; if (DepthFirst) { value = RedisConnection.Database.ListRightPop(_queueKey); } else { value = RedisConnection.Database.ListLeftPop(_queueKey); } if (!value.HasValue) { return null; } string field = value.ToString(); string json = RedisConnection.Database.HashGet(_itemKey, field); if (!string.IsNullOrEmpty(json)) { var result = JsonConvert.DeserializeObject <Request>(json); RedisConnection.Database.HashDelete(_itemKey, field); return result; } return null; }); })); }
public WebDriver( IWebDriver driver, Func <Uri> rootUrl, SeleniumGridConfiguration configuration, RetryExecutor retryExecutor, SelectorFactory selectorFactory, ElementFactory elementFactory, XpathProvider xpathProvider, MovieLogger movieLogger, IEnumerable <SelectorPrefix> prefixes = null) { Driver = driver; SuccessfulSearchers = new List <Searcher>(); RootUrl = rootUrl; SeleniumGridConfiguration = configuration; RetryExecutor = retryExecutor; SelectorFactory = selectorFactory; MovieLogger = movieLogger; Prefixes = prefixes?.ToList() ?? new List <SelectorPrefix>() { new EmptySelectorPrefix() }; Children = new List <WebDriver>(); Screenshots = new List <byte[]>(); ElementFactory = elementFactory; XpathProvider = xpathProvider; }
public WebDriver Prefix(SelectorPrefix prefix) { var p = new ValidatedPrefix(); var l = Prefixes.Concat(prefix); var possibles = l.CrossMultiply(); RetryExecutor.RetryFor(() => { var iframes = SeleniumDriver.FindElements(By.XPath("//iframe")); var valid = possibles.AsParallel().AsOrdered().Where(xpath => SeleniumDriver.FindElements(By.XPath(xpath)).Any()).ToList(); if (valid.Any()) { p.Init("filtered", valid); } else if (iframes.Any()) { foreach (var iframe in iframes) { try { SeleniumDriver.SwitchTo().Frame(iframe); valid = possibles.AsParallel().AsOrdered().Where(xpath => SeleniumDriver.FindElements(By.XPath(xpath)).Any()).ToList(); if (valid.Any()) { p.Init("filtered", valid); } } catch { } } SeleniumDriver.SwitchTo().DefaultContent(); } if (!p.IsInitialized) { throw new Exception($"Was unable to find any that matched prefix, tried:{possibles.LogFormat()}"); } }, TimeSpan.FromMilliseconds(SeleniumGridConfiguration.RetryMs)); var wdm = new WebDriver( SeleniumDriver, RootUrl, SeleniumGridConfiguration, RetryExecutor, SelectorFactory, ElementFactory, XpathProvider, MovieLogger, WebElementSourceLog, new List <SelectorPrefix> { p } ); Children.Add(wdm); return(wdm); }
protected override void PushWhenNoDuplicate(Request request) { RetryExecutor.Execute(30, () => { RedisConnection.Database.ListRightPush(_queueKey, request.Identity); string field = request.Identity; string value = JsonConvert.SerializeObject(request); RedisConnection.Database.HashSet(_itemKey, field, value); }); }
public bool IsDuplicate(Request request) { return(RetryExecutor.Execute(30, () => { bool isDuplicate = RedisConnection.Database.SetContains(_setKey, request.Identity); if (!isDuplicate) { RedisConnection.Database.SetAdd(_setKey, request.Identity); } return isDuplicate; })); }
public bool IsDuplicate(Request request) { return(RetryExecutor.Execute(30, () => { bool isDuplicate = _db.SetContains(_setKey, request.Identity); if (!isDuplicate) { _db.SetAdd(_setKey, request.Identity); } return isDuplicate; })); }
public IEnumerable <Element> SelectMany(Selector selector) => RetryExecutor.RetryFor(() => { var loggingWebdriver = new LoggingWebDriver(SeleniumDriver, MovieLogger, WebElementSourceLog); try { var elements = FindElements(selector, loggingWebdriver); if (elements != null) { return(elements); } //iframes ? var iframes = SeleniumDriver.FindElements(By.XPath("//iframe")); foreach (var iframe in iframes) { try { loggingWebdriver.Log($"Trying iframe:{iframe}"); SeleniumDriver.SwitchTo().Frame(iframe); elements = FindElements(selector, loggingWebdriver); if (elements != null) { return(elements); } } catch { } } SeleniumDriver.SwitchTo().DefaultContent(); return(new List <Element>()); } finally { if (loggingWebdriver.Screenshots.Any()) { Screenshots = loggingWebdriver.Screenshots.Select(x => x.AsByteArray).ToList(); } } }, TimeSpan.FromMilliseconds(SeleniumGridConfiguration.RetryMs));
public Element Select(Selector selector, TimeSpan?retryDuration = null, int?index = null) => RetryExecutor.RetryFor(() => { var loggingWebdriver = new LoggingWebDriver(SeleniumDriver, MovieLogger, WebElementSourceLog); try { var element = FindElement(selector, loggingWebdriver, index); if (element != null) { return(element); } //iframes ? var iframes = SeleniumDriver.FindElements(By.XPath("//iframe")); foreach (var iframe in iframes) { try { loggingWebdriver.Log($"Trying iframe:{iframe}"); SeleniumDriver.SwitchTo().Frame(iframe); element = FindElement(selector, loggingWebdriver, index); if (element != null) { return(element); } } catch { } } SeleniumDriver.SwitchTo().DefaultContent(); throw new Exception($"element was not found; tried:\n{loggingWebdriver.GetLogs()}, maybe try one of these identifiers {GetIdentifiers().Take(10).LogFormat()}"); } finally { if (loggingWebdriver.Screenshots.Any()) { Screenshots = loggingWebdriver.Screenshots.Select(x => x.AsByteArray).ToList(); } } }, retryDuration ?? TimeSpan.FromMilliseconds(SeleniumGridConfiguration.RetryMs));
private Request PollRequest() { return(RetryExecutor.Execute(30, () => { var value = DepthFirst ? RedisConnection.Database.ListRightPop(_queueKey) : RedisConnection.Database.ListLeftPop(_queueKey); if (!value.HasValue) { return null; } string field = value.ToString(); string json = RedisConnection.Database.HashGet(_itemKey, field); if (!string.IsNullOrEmpty(json)) { var result = JsonConvert.DeserializeObject <Request>(json); RedisConnection.Database.HashDelete(_itemKey, field); return result; } return null; })); }
public WebDriver Prefix(SelectorPrefix prefix) { var p = new ValidatedPrefix(); var l = Prefixes.Concat(prefix); var possibles = l.CrossMultiply(); RetryExecutor.RetryFor(() => { var valid = possibles.AsParallel().AsOrdered().Where(xpath => Driver.FindElements(By.XPath(xpath)).Any()).ToList(); if (valid.Any()) { p.Init("filtered", valid); } else { throw new Exception($"Was unable to find any that matched prefix, tried:{possibles.LogFormat()}"); } }, TimeSpan.FromMilliseconds(SeleniumGridConfiguration.RetryMs)); var wdm = new WebDriver( Driver, RootUrl, SeleniumGridConfiguration, RetryExecutor, SelectorFactory, ElementFactory, XpathProvider, MovieLogger, new List <SelectorPrefix> { p } ); Children.Add(wdm); return(wdm); }
private async Task DownloadArtifacts(IExecutionContext executionContext, List<AgentArtifactDefinition> agentArtifactDefinitions, string artifactsWorkingFolder) { Trace.Entering(); foreach (AgentArtifactDefinition agentArtifactDefinition in agentArtifactDefinitions) { // We don't need to check if its old style artifact anymore. All the build data has been fixed and all the build artifact has Alias now. ArgUtil.NotNullOrEmpty(agentArtifactDefinition.Alias, nameof(agentArtifactDefinition.Alias)); var extensionManager = HostContext.GetService<IExtensionManager>(); IArtifactExtension extension = (extensionManager.GetExtensions<IArtifactExtension>()).FirstOrDefault(x => agentArtifactDefinition.ArtifactType == x.ArtifactType); if (extension == null) { throw new InvalidOperationException(StringUtil.Loc("RMArtifactTypeNotSupported")); } Trace.Info($"Found artifact extension of type {extension.ArtifactType}"); executionContext.Output(StringUtil.Loc("RMStartArtifactsDownload")); ArtifactDefinition artifactDefinition = ConvertToArtifactDefinition(agentArtifactDefinition, executionContext, extension); executionContext.Output(StringUtil.Loc("RMArtifactDownloadBegin", agentArtifactDefinition.Alias)); executionContext.Output(StringUtil.Loc("RMDownloadArtifactType", agentArtifactDefinition.ArtifactType)); // Get the local path where this artifact should be downloaded. string downloadFolderPath = Path.GetFullPath(Path.Combine(artifactsWorkingFolder, agentArtifactDefinition.Alias ?? string.Empty)); // Create the directory if it does not exist. if (!Directory.Exists(downloadFolderPath)) { // TODO: old windows agent has a directory cache, verify and implement it if its required. Directory.CreateDirectory(downloadFolderPath); executionContext.Output(StringUtil.Loc("RMArtifactFolderCreated", downloadFolderPath)); } // download the artifact to this path. RetryExecutor retryExecutor = new RetryExecutor(); retryExecutor.ShouldRetryAction = (ex) => { executionContext.Output(StringUtil.Loc("RMErrorDuringArtifactDownload", ex)); bool retry = true; if (ex is ArtifactDownloadException) { retry = false; } else { executionContext.Output(StringUtil.Loc("RMRetryingArtifactDownload")); } return retry; }; await retryExecutor.ExecuteAsync( async () => { //TODO:SetAttributesToNormal var releaseFileSystemManager = HostContext.GetService<IReleaseFileSystemManager>(); releaseFileSystemManager.CleanupDirectory(downloadFolderPath, executionContext.CancellationToken); if (agentArtifactDefinition.ArtifactType == AgentArtifactType.GitHub || agentArtifactDefinition.ArtifactType == AgentArtifactType.TFGit || agentArtifactDefinition.ArtifactType == AgentArtifactType.Tfvc) { throw new NotImplementedException(); } else { await extension.DownloadAsync(executionContext, artifactDefinition, downloadFolderPath); } }); executionContext.Output(StringUtil.Loc("RMArtifactDownloadFinished", agentArtifactDefinition.Alias)); } executionContext.Output(StringUtil.Loc("RMArtifactsDownloadFinished")); }
public TableElement GetTables(IEnumerable <string> headers, StringComparison comparison = StringComparison.CurrentCulture, int?index = null) => RetryExecutor.RetryFor(() => { var loggingWebdriver = new LoggingWebDriver(SeleniumDriver, MovieLogger, WebElementSourceLog); try { var possilbeTables = GetTables(headers.Count()).ToList(); Func <string, string, bool> comparer = (s1, s2) => s1.Equals(s2, comparison); var tableElements = possilbeTables.Where(t => headers.Where(h => !string.IsNullOrEmpty(h)).Except(t.Header.Keys, new Core.EqualityComparer <string>(comparer)).None()); if (tableElements.One()) { return(tableElements.First()); } //Exact match overrides in case of multiples. if (tableElements.Where(x => headers.Count() == x.MaxColumnIndex).One()) { return(tableElements.Where(x => headers.Count() == x.MaxColumnIndex).First()); } if (tableElements.Many()) { if (index == null) { throw new Exception($"multiple talbes matched the definition of {headers.LogFormat()}, table headers were {tableElements.LogFormat(t => $"Table: {t.Header.Keys.LogFormat()}")};"); } if (index >= tableElements.Count()) { throw new Exception($"only found {tableElements.Count()} tables, index of {index} is out of range. (zero based)"); } return(tableElements.ToArray()[index.Value]); } //iframes ? var iframes = SeleniumDriver.FindElements(By.XPath("//iframe")); foreach (var iframe in iframes) { try { loggingWebdriver.Log($"Trying iframe:{iframe}"); SeleniumDriver.SwitchTo().Frame(iframe); possilbeTables = GetTables(headers.Count() - 1).ToList(); tableElements = possilbeTables.Where(t => headers.Where(h => !string.IsNullOrEmpty(h)).Except(t.Header.Keys, new Core.EqualityComparer <string>(comparer)).None()); if (tableElements.One()) { return(tableElements.First()); } if (tableElements.Many()) { if (index == null) { throw new Exception($"multiple talbes matched the definition of {headers.LogFormat()}, table headers were {tableElements.LogFormat(t => $"Table: {t.Header.Keys.LogFormat()}")};"); } if (index >= tableElements.Count()) { throw new Exception($"only found {tableElements.Count()} tables, index of {index} is out of range. (zero based)"); } return(tableElements.ToArray()[index.Value]); } } catch { } } SeleniumDriver.SwitchTo().DefaultContent(); throw new Exception($"table was not found"); } finally { if (loggingWebdriver.Screenshots.Any()) { Screenshots = loggingWebdriver.Screenshots.Select(x => x.AsByteArray).ToList(); } } }, TimeSpan.FromMilliseconds(SeleniumGridConfiguration.RetryMs));
public PremiumPaymentService(RetryStrategy retryStrategy) { _retryExecutor = new RetryExecutor(retryStrategy); }
public CheapPaymentGateway(RetryStrategy retryStrategy) { _retryExecutor = new RetryExecutor(retryStrategy); }
public ExpensivePaymentGateway(RetryStrategy retryStrategy) { _retryExecutor = new RetryExecutor(retryStrategy); }