public MainViewModel()
 {
     var events = new EventAggregator();
     var config = new Configuration(events: events).WithCss().WithDefaultLoader(m => 
     {
         m.IsNavigationEnabled = true;
         m.IsResourceLoadingEnabled = true;
     });
     context = BrowsingContext.New(config);
     profiler = new ProfilerViewModel(events);
     errors = new ErrorsViewModel(events);
     dom = new DOMViewModel();
     query = new QueryViewModel();
     repl = new ReplViewModel();
     settings = new SettingsViewModel();
     statistics = new StatisticsViewModel();
     tree = new TreeViewModel();
     sheets = new SheetViewModel();
     cts = new CancellationTokenSource();
     views = new ITabViewModel[] 
     {
         dom,
         query,
         repl,
         statistics,
         tree,
         sheets
     };
     logs = new IEventViewModel[]
     {
         profiler,
         errors
     };
 }
Esempio n. 2
0
 public void CreateConfig()
 {
     configuration = new Configuration();
     scripting = new TestScriptEngine();
     configuration.IsScripting = true;
     configuration.Register(scripting);
 }
        public static string Execute(string html, IParserProvider parser, Uri page, CookieContainer cookies)
        {
            if (GhostConfiguration.ScriptEngine != null)
            {
                var config = new Configuration();
                var internalparse = new DocumentBuilder(config);
                var document = internalparse.FromHtml(html);

                //var scriptInitialize = document.CreateElement("script");
                //scriptInitialize.TextContent = string.Format(@"document.location.href='{0}';", page.OriginalString);
                //document.Head.Append(scriptInitialize);

                var scripts = document.Scripts.Where(x => x.Attributes.Any(i => i.Name == "src")).ToList();
                var styles = document.QuerySelectorAll("link[href]").Cast<IElement>().ToList();
                var iframes = document.QuerySelectorAll("iframe[src]").Cast<IElement>().ToList();
                foreach (var script in scripts)
                    ResolveUrls(page, script, "src");

                foreach (var script in styles)
                    ResolveUrls(page, script, "href");

                foreach (var script in iframes)
                    ResolveUrls(page, script, "src");

                var htmlParsed = document.ToHtml();
                return GhostConfiguration.ScriptEngine.Run(htmlParsed, cookies);
            }
            return html;
        }
Esempio n. 4
0
 public IDocument GetSourceCodeFromUrl(String url)
 {
     lock (lockThis) {
         var config = new AngleSharp.Configuration().WithDefaultLoader();
         var source = BrowsingContext.New(config).OpenAsync(url).Result;
         return(source);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Gets all the tests from the url given below.
        /// </summary>
        public static void CreateCssSelectorTests()
        {
            var url = "http://www.w3.org/Style/CSS/Test/CSS3/Selectors/current/xml/full/flat/index.html";
            var config = new Configuration().WithDefaultLoader();
            var context = BrowsingContext.New(config);
            var document = context.OpenAsync(url).Result;
            var links = document.QuerySelectorAll("body > ul > li > a");
            var methods = new List<String>();

            foreach (IHtmlAnchorElement link in links)
                CreateCssSelectorTest(context, link.Href, methods);
        }
Esempio n. 6
0
        public static async Task MainAsync(string[] args)
        {
            // setup
            var httpClient = new HttpClient();
            var requester = new HttpClientRequester(httpClient);
            var configuration = new Configuration(new[] { new LoaderService(new[] { requester }) });
            var context = BrowsingContext.New(configuration);

            // request
            var request = DocumentRequest.Get(Url.Create("http://httpbin.org/html"));
            var response = await context.Loader.LoadAsync(request, CancellationToken.None);

            // parse
            var document = await context.OpenAsync(response, CancellationToken.None);

            // interact
            Console.WriteLine(document.QuerySelector("h1").ToHtml());
        }
 public AngleSharpProvider()
 {
     var config = new Configuration();
     _builder = new DocumentBuilder(config);
 }
 public void DestroyConfig()
 {
     configuration = null;
     scripting = null;
 }
 public void CreateConfig()
 {
     scripting = new TestScriptEngine();
     configuration = Configuration.Default.With(new TestScriptService(scripting));
 }
Esempio n. 10
0
        public async Task LoadFromStringAndLoadFromUrlShouldResultInSameDom()
        {
            if (Helper.IsNetworkAvailable())
            {
                var config = new Configuration().WithDefaultLoader();
                var url = "http://imama.shop.by/kolyaski/detskaya_kolyaska_tutis_zippy_2_v_1_cvet_12_shokoladnyy223222222/";
                var client = new HttpClient();
                var message = new HttpRequestMessage(HttpMethod.Get, url);
                var response = await client.SendAsync(message);
                var html = await response.Content.ReadAsStringAsync();

                var documentStr = await BrowsingContext.New(config).OpenAsync(m => m.Content(html));
                var titleStr = documentStr.Title;

                var documentUri = await BrowsingContext.New(config).OpenAsync(url);
                var titleUri = documentUri.Title;

                Assert.AreEqual(titleUri, titleStr);
            }
        }
        public async Task EndToEnd()
        {
            // ARRANGE
            var httpClient = new HttpClient();
            var requester = new HttpClientRequester(httpClient);
            var configuration = new Configuration(new[] { new LoaderService(new[] { requester }) });
            var context = BrowsingContext.New(configuration);
            var request = DocumentRequest.Get(Url.Create("http://httpbin.org/html"));

            // ACT
            var response = await context.Loader.LoadAsync(request, CancellationToken.None);
            var document = await context.OpenAsync(response, CancellationToken.None);

            // ASSERT
            document.QuerySelector("h1").ToHtml().Should().Be("<h1>Herman Melville - Moby-Dick</h1>");
        }