Esempio n. 1
0
        /// <summary>
        /// Creates a new DOM from an HTML file.
        /// </summary>
        ///
        /// <param name="htmlFile">
        /// The full path to the file
        /// </param>
        ///
        /// <returns>
        /// The new from file.
        /// </returns>

        public static CQ CreateFromFile(string htmlFile)
        {
            using (Stream strm = Support2.GetFileStream(htmlFile))
            {
                return(CQ.Create(strm));
            }
        }
Esempio n. 2
0
        public void Issue28()
        {
            var strFilePath = Support2.GetFilePath(SolutionDirectory + "\\CsQuery.Tests\\Resources\\pupillogin.htm");

            var    objStreamReader = new StreamReader(strFilePath, Encoding.UTF8);
            string str             = objStreamReader.ReadToEnd();
            var    dom             = CQ.Create(str);
        }
Esempio n. 3
0
 public void ToCamelCase()
 {
     Assert.AreEqual("one", Support2.ToCamelCase("one"));
     Assert.AreEqual("One", Support2.ToCamelCase("one", true));
     Assert.AreEqual("oneTwo", Support2.ToCamelCase("one-two"));
     Assert.AreEqual("oneTwo-", Support2.ToCamelCase("one-two-"));
     Assert.AreEqual("oneTwo--", Support2.ToCamelCase("one-two--"));
     Assert.AreEqual("-OneTwo--", Support2.ToCamelCase("-one-two--", true));
 }
Esempio n. 4
0
        public void CopyEntireDom()
        {
            string html = Support2.GetFile(TestDomPath("HTML Standard"));

            var    dom     = CQ.Create(html);
            string output  = dom.Render();
            var    dom2    = CQ.Create(output);
            string output2 = dom2.Render();

            Assert.AreEqual(output, output2, "There's no entropy in reparsing a rendered domain.");
            Debug.Write("HTML5 spec parsing: original was " + html.Length + " bytes. CSQ output was " + output.Length);
        }
Esempio n. 5
0
        public static void AssemblySetup()
        {
            string solutionFolderTry;
            bool   isMSTest = Support2.TryGetFilePath("./TestResults/", out solutionFolderTry);

            if (!isMSTest)
            {
                solutionFolderTry = Support2.GetFilePath("./CsQuery.Tests/");
            }

            CsQueryTest.SolutionDirectory = Support.CleanFilePath(solutionFolderTry + "/../");
        }
Esempio n. 6
0
        /// <summary>
        /// Create a new CQ object from an HTML string.
        /// </summary>
        ///
        /// <param name="html">
        /// The HTML source.
        /// </param>
        /// <param name="parsingMode">
        /// The HTML parsing mode.
        /// </param>
        /// <param name="parsingOptions">
        /// (optional) options for controlling the parsing.
        /// </param>
        /// <param name="docType">
        /// (optional) type of the document.
        /// </param>

        public CQ(string html,
                  HtmlParsingMode parsingMode       = HtmlParsingMode.Auto,
                  HtmlParsingOptions parsingOptions = HtmlParsingOptions.Default,
                  DocType docType = DocType.Default)
        {
            var encoding = new UTF8Encoding(false);

            using (var stream = Support2.GetEncodedStream(html ?? "", encoding))
            {
                CreateNew(this, stream, encoding, parsingMode, parsingOptions, docType);
            }
        }
Esempio n. 7
0
        public void InsertingContent()
        {
            var dom        = TestDom("TestHtml");
            var totalCount = dom["*"].Length;

            string newHtml = Support2.GetFile(TestDomPath("TestHtml"));

            //change it slightly to force the string refs to be offset

            newHtml = newHtml.Insert(newHtml.IndexOf("<body>") + 6, "<div id=\"new-div\">Johnny Come Lately</div>");
            var dom2 = CQ.Create(newHtml);

            Assert.AreEqual(totalCount + 1, dom2["*"].Length, "The new copy was the same as the original");

            var addingCount = dom2["body *"].Length;

            dom2["body"].Children().InsertBefore(dom["#hlinks-user"].Children().First());
            Assert.AreEqual(totalCount + addingCount, dom["*"].Length, "The combined DOM is the right length");

            dom["#hlinks-user .reputation-score"].Clone().AppendTo("body");
            Assert.AreEqual("3,215", dom[".reputation-score"].First().Text(), "Text didn't get mangled on multiple moves (bug 11/11/11)");
            Assert.AreEqual("3,215", dom[".reputation-score"].Last().Text(), "Text didn't get mangled on multiple moves (bug 11/11/11)");
        }
Esempio n. 8
0
        /// <summary>
        /// Registers all classes implementing IPseudoSelector in the namespace CsQuery.Extensions in the
        /// passed assembly. If no assembly is provided, then inspects the calling assembly instead.
        /// </summary>
        ///
        /// <remarks>
        /// This method is called when the LookForExtensions startup option is set. (This is the default
        /// setting).
        /// </remarks>
        ///
        /// <param name="assembly">
        /// The assembly to search.
        /// </param>
        ///
        /// <returns>
        /// The number of extensions added
        /// </returns>

        public int Register(Assembly assembly = null)
        {
            var CallingAssembly = Support2.GetFirstExternalAssembly();

            return(PopulateFromAssembly(CallingAssembly, "CsQuery.Engine.PseudoClassSelectors", "CsQuery.Extensions"));
        }
Esempio n. 9
0
 protected string TestHtml(string name)
 {
     return(Support2.GetFile(TestDomPath(name)));
 }
Esempio n. 10
0
        // Override OnBarUpdate method
        protected override void OnBarUpdate()
        {
            // Protect against too few bars
            if (Bars == null)
            {
                return;
            }
            if (!Data.BarsType.GetInstance(Bars.Period.Id).IsIntraday)
            {
                return;
            }
            if (Bars.Period.Id == PeriodType.Minute && Bars.Period.Value > timeFrame / 2)
            {
                return;
            }
            if (!full && !apt)
            {
                apt        = true;
                periodBars = Data.Bars.GetBars(Bars.Instrument, new Period(PeriodType.Minute, timeFrame, MarketDataType.Last), Bars.From, Bars.To, (Session)Bars.Session.Clone(), Data.Bars.SplitAdjust, Data.Bars.DividendAdjust);
                apt        = false;
                full       = true;
            }

            // Remove calculation for first time span after open
            IBar periodBar;

            Bars.Session.GetNextBeginEnd(Time[0], out sessionBegin, out sessionEnd);
            if (Time[0] >= sessionBegin && Time[0] <= sessionBegin.AddMinutes(timeFrame))
            {
                Pivot.Reset();
                Resistance1.Reset();
                Support1.Reset();
                Resistance2.Reset();
                Support2.Reset();
                Resistance3.Reset();
                Support3.Reset();
                Resistance4.Reset();
                Support4.Reset();
                Resistance5.Reset();
                Support5.Reset();
            }
            else
            {
                // Determine open, high, low, and close
                DateTime intradayBarTime = Time[0].AddMinutes(-timeFrame);
                periodBar = periodBars.Get(periodBars.GetBar(intradayBarTime));
                double Open  = periodBar.Open;
                double High  = periodBar.High;
                double Low   = periodBar.Low;
                double Close = periodBar.Close;
                double pivot = periodBar.Close;

                // Switch central pivot calculation
                switch (centralPivotCalculation)
                {
                // Standard calculation case
                case CentralPivotCalculation.Standard:
                {
                    pivot = (High + Low + Close) / 3;
                    break;
                }

                // Open included calculation case
                case CentralPivotCalculation.OpenIncluded:
                {
                    pivot = (Open + High + Low + Close) / 4;
                    break;
                }

                // Close weighted calculation case
                case CentralPivotCalculation.CloseWeighted:
                {
                    pivot = (High + Low + Close + Close) / 4;
                    break;
                }

                // High weighted calculation case
                case CentralPivotCalculation.HighWeighted:
                {
                    pivot = (High + High + Low + Close) / 4;
                    break;
                }

                // Low weighted calculation case
                case CentralPivotCalculation.LowWeighted:
                {
                    pivot = (High + Low + Low + Close) / 4;
                    break;
                }
                }

                // Switch round to tick option
                switch (roundToTick)
                {
                // Rounding case
                case RoundToTick.Yes:
                {
                    // Set all additional pivots, rounded
                    Pivot.Set(Instrument.MasterInstrument.Round2TickSize(pivot));
                    Resistance1.Set(Instrument.MasterInstrument.Round2TickSize(2 * Pivot[0] - Low));
                    Support1.Set(Instrument.MasterInstrument.Round2TickSize(2 * Pivot[0] - High));
                    Resistance2.Set(Instrument.MasterInstrument.Round2TickSize(Pivot[0] + (High - Low)));
                    Support2.Set(Instrument.MasterInstrument.Round2TickSize(Pivot[0] - (High - Low)));
                    Resistance3.Set(Instrument.MasterInstrument.Round2TickSize(High + 2 * (Pivot[0] - Low)));
                    Support3.Set(Instrument.MasterInstrument.Round2TickSize(Low - 2 * (High - Pivot[0])));
                    Resistance4.Set(Instrument.MasterInstrument.Round2TickSize(Pivot[0] + 2 * (High - Low)));
                    Support4.Set(Instrument.MasterInstrument.Round2TickSize(Pivot[0] - 2 * (High - Low)));
                    Resistance5.Set(Instrument.MasterInstrument.Round2TickSize(2 * (Pivot[0] + High) - 3 * Low));
                    Support5.Set(Instrument.MasterInstrument.Round2TickSize(2 * (Pivot[0] + Low) - 3 * High));
                    break;
                }

                // No rounding case
                case RoundToTick.No:
                {
                    // Set all additional pivots, not rounded
                    Pivot.Set(pivot);
                    Resistance1.Set(2 * Pivot[0] - Low);
                    Support1.Set(2 * Pivot[0] - High);
                    Resistance2.Set(Pivot[0] + (High - Low));
                    Support2.Set(Pivot[0] - (High - Low));
                    Resistance3.Set(High + 2 * (Pivot[0] - Low));
                    Support3.Set(Low - 2 * (High - Pivot[0]));
                    Resistance4.Set(Pivot[0] + 2 * (High - Low));
                    Support4.Set(Pivot[0] - 2 * (High - Low));
                    Resistance5.Set(2 * (Pivot[0] + High) - 3 * Low);
                    Support5.Set(2 * (Pivot[0] + Low) - 3 * High);
                    break;
                }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Convert a string to a stream.
        /// </summary>
        ///
        /// <param name="input">
        /// The input to act on.
        /// </param>
        /// <param name="encoding">
        /// (optional) the encoding of the stream. Defaults to UTF8
        /// </param>
        ///
        /// <returns>
        /// input as a Stream.
        /// </returns>

        public static Stream ToStream(this string input, Encoding encoding = null)
        {
            encoding = encoding ?? new UTF8Encoding(false);
            return(Support2.GetEncodedStream(input ?? "", encoding));
        }