本文整理汇总了C#中CsQuery.CQ类的典型用法代码示例。如果您正苦于以下问题:C# CQ类的具体用法?C# CQ怎么用?C# CQ使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CQ类属于CsQuery命名空间,在下文中一共展示了CQ类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildBundleData
public void BuildBundleData(ContentFragmentPageControl contentFragmentPage, CQ parsedContent)
{
if (Configuration.OptomizeGlobalCss)
{
//Get the themes CSS files
CQ elements = parsedContent.Select(BuildSelector);
foreach (IDomObject element in elements)
{
string mediaType = element.GetAttribute("media") ?? "screen";
if (mediaType.IndexOf("screen", StringComparison.OrdinalIgnoreCase) > -1)
{
string src = element.GetAttribute("href");
if (!string.IsNullOrEmpty(src) && mediaType.IndexOf("dynamic-style.aspx", StringComparison.OrdinalIgnoreCase) < 0 && src.EndsWith(".css"))
{
IBundledFile file = _bundledFileFactory.GetBundleFile("css", src, contentFragmentPage, "");
if (file != null)
{
HandleLayoutCssPath(file);
Include(file);
}
}
}
}
}
}
示例2: RunPattern
private static void RunPattern(IYateDataContext dataContext, object model, CQ domObjects, IPattern pattern)
{
//try/finally leaves the data context in the same state as when we started with it hopefully.
try
{
dataContext.PushValue(model);
foreach (var domObject in domObjects)
{
var htmlFragment = CQ.CreateFragment(pattern.HtmlFragment);
foreach (var atRule in pattern.AtRules)
{
atRule.Render(htmlFragment, dataContext);
}
foreach (var ruleSet in pattern.RuleSets)
{
ruleSet.Render(htmlFragment, dataContext);
}
//append those mama jammas
foreach(var frag in htmlFragment)
{
domObject.AppendChild(frag);
}
}
}
finally
{
dataContext.PopValue();
}
}
示例3: Document
public Document(FetchResult result)
{
_result = result;
_document = CQ.CreateDocument(result.Content);
_baseUri = new Lazy<Uri>(GetBaseUri);
}
示例4: PreMailer
/// <summary>
/// Constructor for the PreMailer class
/// </summary>
/// <param name="html">The HTML input.</param>
public PreMailer(string html)
{
_document = CQ.CreateDocument(html);
_warnings = new List<string>();
_cssParser = new CssParser();
_cssSelectorParser = new CssSelectorParser();
}
示例5: Render
public void Render(CQ html, string selector)
{
foreach (var property in Properties)
{
property.Render(html, selector);
}
}
示例6: Render
public void Render(CQ dom)
{
foreach (var selector in _renderingParameters.Selectors)
{
////todo: figure out prepend and such
//if (renderingParameters.Expressions.Count() > 1)
//{
// var method = renderingParameters.Expressions[1].ToLower();
// if (method == "append")
// {
// dom.Select(selector).Text(dom.Select(selector).Text() + renderingParameters.Expressions.FirstOrDefault());
// }
// else if (method == "prepend")
// {
// dom.Select(selector).Text(renderingParameters.Expressions.FirstOrDefault() + dom.Select(selector).Text());
// }
// else
// {
// dom.Select(selector).Text(renderingParameters.Expressions.FirstOrDefault());
// }
//}
//else
//{
dom.Select(selector).Text(_renderingParameters.Expressions.FirstOrDefault());
//}
}
}
示例7: GetDefensiveTDs
public static void GetDefensiveTDs(NPGGFFLDataContext context, Games game)
{
var foxSeasonType = (game.SeasonWeeks.SeasonTypeId == 1 ? 3 : (game.SeasonWeeks.SeasonTypeId == 2 ? 1 : 2)); //preseason = 3, reg season = 1, postseason = 2
var foxScheduleUrl = string.Format("{0}?season={1}&seasonType={2}&week={3}", new string[] { SCHEDULE_URL, game.SeasonWeeks.SeasonYear.ToString(), foxSeasonType.ToString(), game.SeasonWeeks.WeekNum.ToString() });
var foxLeagueUrl = string.Format("{0}?season={1}", new string[] { LEAGUE_URL, game.SeasonWeeks.SeasonYear.ToString() });
var leagueJson = JObject.Parse(HelperMethods.GetJsonFromUrl(foxLeagueUrl));
var scheduleJson = JArray.Parse(HelperMethods.GetJsonFromUrl(foxScheduleUrl));
var awayTeam = GetFoxTeam(leagueJson, game.AwayTeam.FoxAbbreviation.ToUpper());
var homeTeam = GetFoxTeam(leagueJson, game.HomeTeam.FoxAbbreviation.ToUpper());
var gameUrl = string.Format("{0}{1}&type=3", HOST, GetFoxBoxscoreUrl(scheduleJson, awayTeam, homeTeam));
var html = HelperMethods.LoadHtmlFromUrl(gameUrl);
var dom = new CQ(html, HtmlParsingMode.Document);
var dTDs = dom["div[class*='wisfb_bsTeamStats']"].Find("tr[class*='wisfb_bstsTotal wisfb_bstsGroupTop']:contains('DEF TDs')");
if (dTDs.Length > 0)
{
var awayDefensiveTDs = Convert.ToInt32(dTDs.Find("td[class*='wisfb_bstsStat']")[0].Cq().Html());
var homeDefensiveTDs = Convert.ToInt32(dTDs.Find("td[class*='wisfb_bstsStat']")[1].Cq().Html());
context.PlayerStats.Where(ps => ps.GameId == game.GameId && ps.PlayerId == game.AwayTeamId).First().DefensiveTDs = awayDefensiveTDs;
context.PlayerStats.Where(ps => ps.GameId == game.GameId && ps.PlayerId == game.HomeTeamId).First().DefensiveTDs = homeDefensiveTDs;
context.SubmitChanges();
}
}
示例8: OnResultExecuted
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
if (sb == null)
{
base.OnResultExecuted(filterContext);
return;
}
if (filterContext.Exception != null)
{
filterContext.RequestContext.HttpContext.Response.Output = output;
base.OnResultExecuted(filterContext);
return;
}
if (filterContext.HttpContext.Items.DocTransforms().Any())
{
string response = sb.ToString();
//response processing
var doc = new CsQuery.CQ(response);
try
{
foreach (var transform in filterContext.HttpContext.Items.DocTransforms())
{
transform(doc);
}
output.Write(doc.Render());
}
catch (Exception ex)
{
output.Write(ex.ToString());
throw;
}
}
base.OnResultExecuted(filterContext);
}
示例9: Not
/// <summary>
/// Selects all elements except those passed as a parameter.
/// </summary>
///
/// <param name="elements">
/// The elements to be excluded.
/// </param>
///
/// <returns>
/// A new CQ object.
/// </returns>
///
/// <url>
/// http://api.jquery.com/not/
/// </url>
public CQ Not(IEnumerable<IDomObject> elements)
{
CQ csq = new CQ(SelectionSet);
csq.SelectionSet.ExceptWith(elements);
csq.Selector = Selector;
return csq;
}
示例10: PreMailer
/// <summary>
/// Constructor for the PreMailer class
/// </summary>
/// <param name="html">The HTML input.</param>
/// <param name="parsingMode">(optional) the mode.</param>
public PreMailer(string html,HtmlParsingMode parsingMode)
{
_document = CQ.Create(html, parsingMode);
_warnings = new List<string>();
_cssParser = new CssParser();
_cssSelectorParser = new CssSelectorParser();
}
示例11: ToTomboyXml
public static string ToTomboyXml(this string html_body)
{
var body = html_body.Replace ("<br>", "\n");
CQ html = body;
html["b"].ReplaceOuterWithTag("<bold/>");
html["i"].ReplaceOuterWithTag ("<i/>");
html["ul"].ReplaceOuterWithTag ("<list/>");
html["li"].ReplaceOuterWithTag ("<list-item />");
html["h1"].ReplaceOuterWithTag ("<size:huge/>");
html["h2"].ReplaceOuterWithTag ("<size:large/>");
html["small"].ReplaceOuterWithTag ("<size:small/>");
html["strike"].ReplaceOuterWithTag ("<strikethrough/>");
html["pre"].ReplaceOuterWithTag ("<monospace/>");
html["a[class='internal']"].ReplaceOuterWithTag ("<link:internal/>");
html["a[class='url']"].ReplaceOuterWithTag ("<link:url/>");
html["a"].ReplaceOuterWithTag ("<link:url/>");
html["span[class='highlight']"].ReplaceOuterWithTag ("<highlight/>");
// hack replace <div> which get inserted by the wysihtml5
html["div"].Each (domobj => {
CQ e = new CQ (domobj);
var all = new CQ(e.Html());
e.ReplaceWith(all);
});
var render = html.Render ();
// maybe bug int tomboy - </list-items> need a single \n in from of them
render = Regex.Replace (render, @"(?!\n)</list-item>", "\n</list-item>", RegexOptions.ExplicitCapture);
return render;
}
示例12: UnquotedAttributeHandling
public void UnquotedAttributeHandling()
{
CQ doc = new CQ("<div custattribute=10/23/2012 id=\"tableSample\"><span>sample text</span></div>");
IDomElement obj = doc["#tableSample"].FirstElement();
Assert.AreEqual("10/23/2012", obj["custattribute"]);
}
示例13: ReadLargeDoc
public static void ReadLargeDoc(TestContext context)
{
// CsQuery (version 1.3.0 and above) uses this code.
Dom = CQ.Create(
CsQuery.Utility.Support.GetFile("HtmlParserSharp.Tests\\Resources\\html standard.htm")
);
}
示例14: ParseEventDate
static DateTimeOffset ParseEventDate(CQ dom, IDomObject @event)
{
var date = dom.Select("td.date", @event).Text().Trim();
DateTimeOffset eventDate;
DateTimeOffset.TryParse(date, out eventDate);
return eventDate;
}
示例15: TestObtainAccessTokenWithoutAuthenticating
public void TestObtainAccessTokenWithoutAuthenticating()
{
var collection = new CollectionState(new Uri(SANDBOX_URI));
var response = new WebClient().DownloadString("http://checkip.dyndns.com/");
var ip = new CQ(response).Select("body").Text().Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
var state = collection.UnauthenticatedAccess(ip, "WCQY-7J1Q-GKVV-7DNM-SQ5M-9Q5H-JX3H-CMJK");
Assert.AreEqual(HttpStatusCode.OK, state.Response.StatusCode);
Assert.IsNotNullOrEmpty(state.CurrentAccessToken);
}