Example #1
0
        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();
            }
        }
Example #2
0
        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;
        }
Example #3
0
		/// <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();
		}
        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();
            }
        }
Example #5
0
        public Document(FetchResult result)
        {
            _result = result;
            _document = CQ.CreateDocument(result.Content);

            _baseUri = new Lazy<Uri>(GetBaseUri);
        }
        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);
        }
Example #7
0
	    /// <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();
		}
Example #8
0
 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());
         //}
     }
 }
Example #9
0
        /// <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;
        }
Example #10
0
 public void Render(CQ html, string selector)
 {
     foreach (var property in Properties)
     {
         property.Render(html, selector);
     }
 }
Example #11
0
        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")
            );
        }
Example #12
0
        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"]);
        }
Example #13
0
        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;
        }
Example #14
0
 public static DateTime GetGameDate(int gameId)
 {
     var url = string.Format("{0}{1}", BOXSCORE_URL, string.Format("?gameId={0}", gameId.ToString()));
     var html = HelperMethods.LoadHtmlFromUrl(url);
     CQ dom = new CQ(html, HtmlParsingMode.Document);
     var gameTime = dom["div[class*='game-status']"].Find("span[data-date]").First().Attr("data-date");
     var gameDtm = DateTime.Parse(gameTime);
     return gameDtm;
 }
 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);
 }
Example #16
0
        internal object Result()
        {
            var s = new CQ(compareSource);
            var w = new CQ(compareWith);

            

            throw new NotImplementedException();
        }
Example #17
0
 static string[] ParseCommandsNames(CQ dom, IDomObject @event)
 {
     var commands =
         dom.Select(
             "td.today-name > span.command > div.today-member-name, td.name > span.command div.member-name",
             @event).Map(node => node.Cq().Text().Trim().Replace(Nbsp, ' ')).ToArray();
     Debug.Assert(commands.Count() == 2, "Teams names have not been recognized: " + @event.InnerHTML);
     return commands;
 }
 private IEnumerable<SteamGame> ParseWishlistPage(CQ dom)
 {
     foreach (var wishlistNode in dom[".wishlistRow"])
     {
         CQ wishlistNodeDom = CQ.Create(wishlistNode);
         string name = wishlistNodeDom["h4.ellipsis"].Text();
         string url = wishlistNodeDom[".storepage_btn_ctn a"].Attr("href");
         yield return new SteamGame(name, url);
     }
 }
Example #19
0
 public virtual void Render(CQ html, IYateDataContext dataContext)
 {
     foreach (var declaration in Properties)
     {
         foreach (var selector in Selectors)
         {
             declaration.Render(html, selector, dataContext);
         }
     }
 }
 private void InitializeDomFromTemplate()
 {
     using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ApiExplorer.Core.Template.html"))
     {
         using (StreamReader reader = new StreamReader(stream))
         {
             Dom = CQ.Create(reader.ReadToEnd());
         }
     }
 }
Example #21
0
		private PreMailer(string html, bool removeStyleElements = false, string ignoreElements = null)
		{
			_document = CQ.CreateDocument(html);
			_removeStyleElements = removeStyleElements;
			_ignoreElements = ignoreElements;
			_warnings = new List<string>();

			_cssParser = new CssParser();
			_cssSelectorParser = new CssSelectorParser();
		}
        public string Format(CQ selection)
        {
            stringInfo = CharacterData.CreateStringInfo();

            StringBuilder sb = new StringBuilder();
            foreach (IDomObject obj in selection) {
                AddContents(sb,obj);
            }
            return sb.ToString();
        }
Example #23
0
 static IEnumerable<ParsedEventData> ParseEvents(CQ dom, IDomObject @event)
 {
     return dom.Select("td.js-price", @event)
               .Map(node =>
                        {
                            var domNode = node.Cq();
                            var coefficient = double.Parse(domNode.Find("span.selection-link").Text().Trim());
                            var specification = domNode.Children().Remove().End().Text().Trim();
                            return new ParsedEventData {Coefficient = coefficient, Specification = specification};
                        });
 }
Example #24
0
 /// <summary>
 /// Create a new CQ object from a single element. Unlike the constructor method <see cref="CsQuery.CQ"/>
 /// this new objet is not bound to any context from the element.
 /// </summary>
 ///
 /// <param name="element">
 /// The element to wrap
 /// </param>
 ///
 /// <returns>
 /// A new CQ object
 /// </returns>
 
 public static CQ Create(IDomObject element)
 {
     CQ csq = new CQ();
     if (element is IDomDocument) {
         csq.Document = (IDomDocument)element;
         csq.AddSelection(csq.Document.ChildNodes);
     } else {
         csq.CreateNewFragment(Objects.Enumerate(element));
     }
     return csq;
 }
Example #25
0
        private static IEnumerable<ScheduleItem> FromTable(CQ tableElement)
        {
            var itemElements = tableElement.Find("tbody tr .event .event_container");

            for (int i = 0; i < itemElements.Length; i++)
            {
                var item = itemElements.Eq(i);

                yield return ScheduleItem.Parse(item);
            }
        }
 public bool TryGetLinkFile(string linkURL, out CQ doc)
 {
     try {
         doc = CQ.CreateFromUrl(linkURL, null);
         return true;
     }
     catch
     {
         doc = null;
         return false;
     }
 }
        public void LoadDoc(string filepath, string docname, string orgunitid, string docid)
        {
            // Load file into parser
            htmlDoc = new HtmlDocument();
            htmlDoc.Load(filepath);
            dom = CQ.Create(htmlDoc.DocumentNode.OuterHtml);

            // Set variables
            DocName = docname;
            OrgUnitID = orgunitid;
            DocID = docid;
        }
Example #28
0
        public void Render(CQ html, IYateDataContext dataContext)
        {
            foreach (var atRule in AtRules)
            {
                atRule.Render(html, dataContext);
            }

            foreach (var ruleSet in RuleSets)
            {
                ruleSet.Render(html, dataContext);
            }
        }
Example #29
0
		/// <summary>
		/// Returns a list of CSS sources ('style', 'link' tags etc.) based on the elements given.<para/>
		/// These will be returned in their order of definition.
		/// </summary>
		private IEnumerable<ICssSource> ConvertToStyleSources(CQ nodesWithStyles)
		{
			var result = new List<ICssSource>();
			var nodes = nodesWithStyles;
			foreach (var node in nodes)
			{
				if (node.NodeName == "STYLE")
					result.Add(new DocumentStyleTagCssSource(node));
			}

			return result;
		}
Example #30
0
 public override string ToString()
 {
     return(CQ.ToJSON(this));
 }
Example #31
0
        /// <summary>
        /// Create a new CQ object wrapping a single DOM element, in the context of another CQ object.
        /// </summary>
        ///
        /// <remarks>
        /// This differs from the overload accepting a single IDomObject parameter in that it associates
        /// the new object with a previous object, as if it were part of a selector chain. In practice
        /// this will rarely make a difference, but some methods such as <see cref="CQ.End"/> use
        /// this information.
        /// </remarks>
        ///
        /// <param name="element">
        /// The element to wrap.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>

        public CQ(IDomObject element, CQ context)
        {
            ConfigureNewInstance(this, element, context);
        }
Example #32
0
        /// <summary>
        /// Create a new CsQuery object using an existing instance and a selector. if the selector is
        /// null or missing, then it will contain no selection results.
        /// </summary>
        ///
        /// <param name="selector">
        /// A valid CSS selector.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>

        public CQ(string selector, CQ context)
        {
            ConfigureNewInstance(selector, context);
        }
Example #33
0
        /// <summary>
        /// Create a new CsQuery object from a selector HTML, and assign CSS from a JSON string, within a context.
        /// </summary>
        ///
        /// <param name="selector">
        /// The
        /// </param>
        /// <param name="cssJson">
        /// The JSON containing CSS
        /// </param>
        /// <param name="context">
        /// The context
        /// </param>

        public CQ(string selector, string cssJson, CQ context)
        {
            ConfigureNewInstance(selector, context);
            AttrSet(cssJson);
        }
Example #34
0
        /// <summary>
        /// Create a new CsQuery object from a selector or HTML, and assign CSS, within a context.
        /// </summary>
        ///
        /// <param name="selector">
        /// The selector or HTML markup
        /// </param>
        /// <param name="css">
        /// The object whose property names and values map to CSS
        /// </param>
        /// <param name="context">
        /// The context
        /// </param>

        public CQ(string selector, object css, CQ context)
        {
            ConfigureNewInstance(selector, context);
            AttrSet(css);
        }
Example #35
0
        /// <summary>
        /// Create a new CsQuery object from a set of DOM elements, assigning the 2nd parameter as a context for this object.
        /// </summary>
        ///
        /// <param name="elements">
        /// The elements that make up the selection set in the new object
        /// </param>
        /// <param name="context">
        /// A CQ object that will be assigned as the context for this one.
        /// </param>

        public CQ(IEnumerable <IDomObject> elements, CQ context)
        {
            ConfigureNewInstance(this, elements, context);
        }
Example #36
0
        /// <summary>
        /// Configures a new instance for a sequence of elements and an existing context.
        /// </summary>
        ///
        /// <param name="dom">
        /// The dom.
        /// </param>
        /// <param name="elements">
        /// A sequence of elements.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>

        private void ConfigureNewInstance(CQ dom, IEnumerable <IDomObject> elements, CQ context)
        {
            dom.CsQueryParent = context;
            dom.AddSelection(elements);
        }
Example #37
0
 private void ConfigureNewInstance(CQ dom, IDomObject element, CQ context)
 {
     dom.CsQueryParent = context;
     dom.SetSelection(element, SelectionSetOrder.OrderAdded);
 }
Example #38
0
 public IEnumerable <T> Enumerate <T>()
 {
     return(CQ.Enumerate <T>(this));
 }
Example #39
0
 public CrawlResult(Uri uri, CsQuery.CQ dom)
 {
     Uri = uri;
     DOM = dom;
 }
        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);
                            }
                        }
                    }
                }


            }
        }