private void DownloadNodeCss_(CssTreeNode root, string[] testIds) { if (allImportRules_.Count > 0) { foreach (ImportRule importRule in allImportRules_) { CssTreeNode cssTreeNode = new CssTreeNode(logger_); decendets_.Add(cssTreeNode); string url = importRule.Href; DownloadNodeCss_(root, cssTreeNode, url, testIds); } } }
private static void ParseCss_(CssTreeNode targetCssTreeNode, string css) { Parser parser = new Parser(); StyleSheet stylesheet = parser.Parse(css); StringBuilder sb = new StringBuilder(2048); foreach (RuleSet rule in stylesheet.Rules) { if (rule.RuleType != CssParser.Model.RuleType.Import) { sb.Append(rule.ToString()); } } targetCssTreeNode.allImportRules_ = stylesheet.ImportDirectives; targetCssTreeNode.css_ = sb.ToString(); }
private void OnCssDownloadComplete_(object sender, EventArgs args) { CssTreeNode cssTreeNode = (CssTreeNode)sender; string css = cssTreeNode.CalcCss(); string escapedCss = StringUtils.CleanForJSON(css); string href = cssTreeNode.Href; cssData_[href] = escapedCss; if (waitHandles_.TryGetValue(cssTreeNode, out AutoResetEvent waitHandle)) { waitHandle.Set(); lock (lockObject_) { waitHandles_.Remove(cssTreeNode); } } }
private void FetchCssFiles_(List <string> missingCssList, string[] testIds) { logger_.Log(TraceLevel.Info, testIds, Stage.Check, StageType.DomScript, new { missingCssList }); List <CssTreeNode> cssTreeNodes = new List <CssTreeNode>(); foreach (string missingCssUrl in missingCssList) { if (missingCssUrl.StartsWith("blob:") || missingCssUrl.StartsWith("data:")) { logger_.Log(TraceLevel.Warn, testIds, Stage.Check, StageType.DomScript, new { message = "trying to download something impossible", missingCssUrl }); cssData_.Add(missingCssUrl, string.Empty); continue; } CssTreeNode cssTreeNode = new CssTreeNode(missingCssUrl, logger_, OnCssDownloadComplete_); cssTreeNodes.Add(cssTreeNode); AutoResetEvent waitHandle = new AutoResetEvent(false); waitHandles_[cssTreeNode] = waitHandle; cssTreeNode.Run(testIds); } }
private void OnCssDownloadComplete_(object sender, EventArgs args) { logger_.Verbose("enter"); CssTreeNode cssTreeNode = (CssTreeNode)sender; string css = cssTreeNode.CalcCss(); string escapedCss = StringUtils.CleanForJSON(css); string href = cssTreeNode.Href; cssData_[href] = escapedCss; if (waitHandles_.TryGetValue(cssTreeNode, out AutoResetEvent waitHandle)) { logger_.Verbose("calling 'set' on waithandle {0}", waitHandle.GetHashCode()); waitHandle.Set(); lock (lockObject_) { waitHandles_.Remove(cssTreeNode); } } logger_.Verbose("exit"); }
private void DownloadNodeCss_(CssTreeNode root, CssTreeNode targetCssTreeNode, string url, string[] testIds) { root.IncrementActiveDownloads(); DownloadCssAsync_(url, root.logger_, (object sender, DownloadStringCompletedEventArgs args) => { try { WebClientUserData data = (WebClientUserData)args.UserState; if (args.Error == null) { string css = args.Result; WebClient webClient = (WebClient)sender; logger_.Verbose("download completed for {0}", data.href); logger_.Verbose("download took {0} ms", data.stopwatch.Elapsed.TotalMilliseconds); webClient.Dispose(); ParseCss_(targetCssTreeNode, css); targetCssTreeNode.DownloadNodeCss_(root, testIds); } else { logger_.Log(TraceLevel.Error, testIds, Stage.Check, StageType.DownloadResource, new { args.Error, data.href }); if (retriesCount_ > 0) { retriesCount_--; logger_.Log(TraceLevel.Info, testIds, Stage.Check, StageType.Retry); Thread.Sleep(100); DownloadNodeCss_(root, this, Href, testIds); } } root.DecrementActiveDownloads(); } catch (Exception e) { CommonUtils.LogExceptionStackTrace(logger_, Stage.Check, e, testIds); } }); }
private void DownloadNodeCss_(CssTreeNode root, CssTreeNode targetCssTreeNode, string url) { root.IncrementActiveDownloads(); DownloadCssAsync_(url, root.logger_, (object sender, DownloadStringCompletedEventArgs args) => { try { WebClientUserData data = (WebClientUserData)args.UserState; if (args.Error == null) { string css = args.Result; WebClient webClient = (WebClient)sender; logger_.Verbose("download completed for {0}", data.href); logger_.Verbose("download took {0} ms", data.stopwatch.Elapsed.TotalMilliseconds); webClient.Dispose(); ParseCss_(targetCssTreeNode, css); targetCssTreeNode.DownloadNodeCss_(root); } else { logger_.Log("error downloading css {1}: {0}", args.Error, data.href); if (retriesCount_ > 0) { retriesCount_--; logger_.Log("Retrying..."); Thread.Sleep(100); DownloadNodeCss_(root, this, Href); } } root.DecrementActiveDownloads(); } catch (Exception e) { logger_.Log("Error: " + e); } }); }
private void FetchCssFiles_(List <string> missingCssList) { logger_.Verbose("enter"); List <CssTreeNode> cssTreeNodes = new List <CssTreeNode>(); foreach (string missingCssUrl in missingCssList) { if (missingCssUrl.StartsWith("blob:") || missingCssUrl.StartsWith("data:")) { logger_.Log("trying to download something impossible: {0}", missingCssUrl); cssData_.Add(missingCssUrl, string.Empty); continue; } logger_.Verbose("Downloading {0}", missingCssUrl); CssTreeNode cssTreeNode = new CssTreeNode(missingCssUrl, logger_, OnCssDownloadComplete_); cssTreeNodes.Add(cssTreeNode); AutoResetEvent waitHandle = new AutoResetEvent(false); logger_.Verbose("creating waithandle {0}", waitHandle.GetHashCode()); waitHandles_[cssTreeNode] = waitHandle; cssTreeNode.Run(); } logger_.Verbose("exit"); }