private void TreeViewItem_OnItemSelected(object sender, RoutedEventArgs e) { var tree = sender as TreeView; if (tree.SelectedItem is string) { // Convert to actual string string selectedItem = tree.SelectedItem as string; // Get corresponding file name from dictionary string path = BrowserEngine.GetTreeItemNameInDict(selectedItem, repoContent); // Get file's uri from dictionary using path/key string uri = BrowserEngine.GetUriFromDict(repoContent, path); // Assemble download path string fName = BrowserEngine.GenerateFileName(selectedItem); // Download file from URI at file location just defined BrowserEngine.DownlodFileAtLocation(uri, fName); // Pass path to downloaded file to main Dynamo method toOpen = fName; // And close window Close(); } }
public P2PPeerClass(string roomName) { this.roomName = roomName; mainEngine = new BrowserEngine(); bool RandomMemoryFile = true; if (RandomMemoryFile) { Guid memid = Guid.NewGuid(); MemoryFile = memid.ToString(); } bool RandomPort = true; if (RandomPort) { System.Random r = new System.Random(); Port = 8000 + r.Next(1000); } mainEngine.InitPlugin(10, 10, MemoryFile, Port, "https://phylliida.github.io", true); mainEngine.OnJavaScriptDialog += MainEngine_OnJavaScriptDialog; mainEngine.OnPageLoaded += MainEngine_OnPageLoaded; //run initialization //if (JSInitializationCode.Trim() != "") // mainEngine.RunJSOnce(JSInitializationCode); }
public void Run() { using (loadLog = new StreamWriter("catbrowser.log", false)) { engine = new BrowserEngine(basePath); engine.LoadProgress += LoadProgress; engine.Error += Error; engine.Warning += Error; engine.Notice += Error; engine.Load(); while (true) { Console.Write("> "); string command = Console.ReadLine(); if (command == null) { break; } command = command.Trim(); if (!ProcessCommand(command)) { break; } } } }
public ChromiumCapture(int width, int height, string url, bool enableWebRTC = true) { mainEngine = new BrowserEngine(); bool RandomMemoryFile = true; if (RandomMemoryFile) { Guid memid = Guid.NewGuid(); MemoryFile = memid.ToString(); } bool RandomPort = true; if (RandomPort) { System.Random r = new System.Random(); Port = 8000 + r.Next(1000); } mainEngine.InitPlugin(width, height, MemoryFile, Port, url, enableWebRTC); //run initialization //if (JSInitializationCode.Trim() != "") // mainEngine.RunJSOnce(JSInitializationCode); }
void OnDisable() { Debug.Log("browser 2d disable"); if (_mainEngine != null) { _mainEngine.Shutdown(); _mainEngine = null; } }
public void TemporaryRedirectWithAutoFollowRedirects() { _browser = new BrowserEngine(new WebRequester() .AutomaticallyFollowRedirects(true)); _browser.Load("http://localhost:9001/TestSite/TemporaryRedirectToAnotherPage.aspx"); Assert.That(_browser.ResponseStatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(_browser.Page.Title(), Is.EqualTo("Another Page")); Assert.That(_browser.Location.AbsoluteUri, Is.StringContaining("/TestSite/AnotherPage.aspx")); }
public void PermanentRedirect() { _browser = new BrowserEngine(new WebRequester() .AutomaticallyFollowRedirects(false)); _browser.Load("http://localhost:9001/TestSite/PermanentRedirectToAnotherPage.aspx"); Assert.That(_browser.ResponseStatusCode, Is.EqualTo(HttpStatusCode.MovedPermanently)); Assert.That(_browser.Location.AbsoluteUri, Is.EqualTo("http://localhost:9001/TestSite/PermanentRedirectToAnotherPage.aspx")); }
public void ShouldSetCookie() { var cookie = new Cookie("ChocolateChip", "", "", ""); _requester.AddCookie(cookie); var browser = new BrowserEngine(_requester); browser.Load("http://www.totaljobs.com/"); Assert.That(browser.Cookies.AllCookies.Count, Is.EqualTo(1)); Assert.That(browser.Cookies.AllCookies[0].Name, Is.EqualTo(cookie.Name)); }
public void TemporaryRedirect() { _browser = new BrowserEngine(new WebRequester() .AutomaticallyFollowRedirects(false)); _browser.Load("http://localhost:9001/TestSite/TemporaryRedirectToAnotherPage.aspx"); Assert.That(_browser.ResponseStatusCode, Is.EqualTo(HttpStatusCode.Found)); Assert.That(_browser.Page.Title(), Is.EqualTo("Object moved")); Assert.That(_browser.Location.AbsoluteUri, Is.EqualTo("http://localhost:9001/TestSite/TemporaryRedirectToAnotherPage.aspx")); }
private async void OnSelectedAsync(object sender, SelectionChangedEventArgs e) { string selectionString = null; selectionString = selectReposCB.SelectedItem.ToString(); // Show text in combobox selectReposCB.Text = selectionString; // Get repository object from user selection // It's supposed that the user has only one repo with that path (GH rule) GitHubInfo.selectedRepo = localReposList.Where(r => r.FullName == selectionString).First(); // Initialize process to get repo's content Task <SortedDictionary <string, string> > repoContentTask = GitHubInfo.GetRepoContentAsync(GitHubInfo.selectedRepo, ".dyn"); // Get async result repoContent = await repoContentTask; BrowserEngine.PopulateTree(repoContent, filesTree); }
public void BeforeEachTest() { _engine = new BrowserEngine(new WebRequester()); }
public void BeforeEachTest() { _browser = new BrowserEngine(new FakeWebRequester("")); }
void Start() { Debug.Log("Browser2d start"); if (AutoFitParent) { var pixsource = transform as RectTransform; var rect = pixsource.rect; Width = (int)rect.width; Height = (int)rect.height; Debug.LogFormat("Browser2d resize to {0}x{1}", Width, Height); } _mainEngine = new BrowserEngine { dynamicRequestHandler = gameObject.GetComponent <IDynamicRequestHandler>() }; if (RandomMemoryFile) { var memid = Guid.NewGuid(); MemoryFile = memid.ToString(); } //run initialization if (JSInitializationCode.Trim() != "") { _mainEngine.RunJSOnce(JSInitializationCode); } if (UIEnabled) { InitPrefabLinks(); if (mainUIPanel != null) { mainUIPanel.InitPrefabLinks(); } } var parentcanvas = GetComponentInParent <Canvas>(); if (parentcanvas != null) { _mainCamera = parentcanvas.worldCamera; //get camera assigned to parent canvas } if (_mainCamera == null) //try to get default but this completely wrong { _mainCamera = GameObject.Find("Main Camera").GetComponent <Camera>(); } if (mainUIPanel != null) { mainUIPanel.KeepUIVisible = KeepUIVisible; if (!KeepUIVisible) { mainUIPanel.Hide(); } } //attach dialogs and querys _mainEngine.OnJavaScriptDialog += _mainEngine_OnJavaScriptDialog; _mainEngine.OnJavaScriptQuery += _mainEngine_OnJavaScriptQuery; _mainEngine.OnPageLoaded += _mainEngine_OnPageLoaded; _mainEngine.OnTextureObjectUpdated += OnTextureObjectUpdated; _mainEngine.StreamingResourceName = StreamingResourceName; if (DialogPanel != null) { DialogPanel.SetActive(false); } IEnumerator initCoroutine = _mainEngine.InitPlugin(Width, Height, MemoryFile, InitialURL, EnableWebRTC, EnableGPU); StartCoroutine(initCoroutine); }
private bool ProcessCommand(string command) { string[] split = command.Split(' '); string cmd0 = split.Length > 0 ? split[0] : ""; if (command.Length == 0) { // do nothing } else if (command == "quit" || command == "exit" || command == "bye") { return(false); } else if (cmd0 == "page") { LoadCatLinks(); string name = String.Join("_", split, 1, split.Length - 1); if (name.Length == 0) { Console.Write("Name: "); name = Console.ReadLine(); } Page page; Namespace ns; string title; Page.ParseTitle(name, out ns, out title); if (!engine.PagesByName.TryGetValue(new Pair <Namespace, string>(ns, title), out page)) { Console.WriteLine("No such page"); return(true); } Console.WriteLine("ID = {0}", page.Id); Console.Write("Categories: "); bool first = true; foreach (Category cat in page.Categories) { if (!first) { Console.Write(", "); } first = false; Console.Write(cat.Title); } if (page.Categories.Count == 0) { Console.Write("(uncategorized)"); } Console.WriteLine(); } else if (cmd0 == "category" || cmd0 == "cat") { LoadCatLinks(); string name = String.Join("_", split, 1, split.Length - 1); if (name.Length == 0) { Console.Write("Name: "); name = Console.ReadLine(); } Page page; if (!engine.PagesByName.TryGetValue(new Pair <Namespace, string>(Namespace.Category, name), out page)) { Console.WriteLine("No such category"); return(true); } var cat = (Category)page; Console.WriteLine("ID = {0}", page.Id); Console.Write("Categories: "); bool first = true; foreach (Category supercat in page.Categories) { if (!first) { Console.Write(", "); } first = false; Console.Write(supercat.Title); } if (page.Categories.Count == 0) { Console.Write("(uncategorized)"); } Console.WriteLine(); if (cat.Subcategories.Count > 0) { Console.Write("Subcategories: "); first = true; foreach (Category subcat in cat.Subcategories) { if (!first) { Console.Write(", "); } first = false; Console.Write(subcat.Title); } Console.WriteLine(); } if (cat.Articles.Count > 0) { Console.Write("Pages: "); first = true; foreach (Page subpage in cat.Articles) { if (!first) { Console.Write(", "); } first = false; Console.Write(subpage.Title); } Console.WriteLine(); } } else if (cmd0 == "+" || cmd0 == "-" || cmd0 == "~" || cmd0 == "=" || cmd0 == "*" || cmd0 == "?") { char op = cmd0[0]; bool restrictingOp = op == '*' || op == '-'; if (restrictingOp && engine.Count == 0) { Console.WriteLine("Current result set is empty, no point in doing that operation"); return(true); } if (split.Length < 2) { Console.WriteLine("Missing set specifier (category, categoryre template, namespace, pagelink, extlink, duplicates)"); return(true); } string set = split[1]; string name = String.Join("_", split, 2, split.Length - 2); if (name.Length == 0) { Console.Write("Name: "); name = Console.ReadLine(); if (name == null) { return(false); } } Selector selector; if (set == "category" || set == "cat") { LoadCatLinks(); selector = Selector.PagesInsideCategory(name); } else if (set == "categoryre" || set == "catre") { LoadCatLinks(); selector = Selector.PagesInCategoryRE(name); } else if (set == "dupes" || set == "duplicates") { LoadCatLinks(); selector = Selector.PagesDuplicateWithinCategory(name); } else if (set == "template") { selector = Selector.LinkingToTemplate(name); } else if (set == "ns" || set == "namespace") { Namespace ns; try { int nsint; if (Int32.TryParse(name, out nsint)) { ns = (Namespace)nsint; } else { ns = (Namespace)Enum.Parse(typeof(Namespace), name.Replace(' ', '_'), true); } } catch (ArgumentException) { Console.WriteLine("Unknown namespace"); return(true); } selector = Selector.PagesInNamespace(ns); } else if (set == "pagelink") { try { Pair <Namespace, string> title = BrowserEngine.ParseTitle(name); selector = Selector.LinkingToPage(title.First, title.Second); } catch (Exception e) { Console.WriteLine(e.Message); return(true); } } else if (set == "extlink") { selector = Selector.WithExtLinkRE(name); } else { Console.WriteLine("Unknown set specifier"); return(true); } Operator operation; switch (op) { case '=': operation = Operator.Replace; break; case '+': operation = Operator.Add; break; case '-': operation = Operator.Subtract; break; case '~': operation = Operator.ReverseSubtract; break; case '*': operation = Operator.Intersect; break; case '?': Console.WriteLine("Set {0} contains {1} pages", name, engine.ComputeCount(selector)); return(true); default: Console.WriteLine("Unknown operator"); return(true); } int result; try { result = engine.Operate(operation, selector); } catch (Exception e) { Console.WriteLine(e.Message); return(true); } Console.WriteLine("Set {0} contains {1} pages; current result size: {2}", name, result, engine.Count); } else if (command == "count") { Console.WriteLine("Current result size: " + engine.Count); } else if (cmd0 == "list") { if (split.Length > 2) { Console.WriteLine("Too many parameters"); return(true); } int limit; if (split.Length > 1) { Int32.TryParse(split[1], out limit); } else { limit = 0; } int count = 0; if (sortingRegex != null) { var outputList = new SortedDictionary <Pair <string, string>, string>(); foreach (Page page in engine) { string title = page.ToString(); Match sortKeyMatch = sortingRegex.Match(title); string sortKey = (sortKeyMatch.Success && sortKeyMatch.Value.Length > 0) ? sortKeyMatch.Value : title; outputList.Add(new Pair <string, string>(sortKey, title), title); } foreach (string title in outputList.Values) { if (limit > 0 && ++count > limit) { break; } string t = title; if (transformRegex != null) { t = transformRegex.Replace(t, transformReplacement); } Console.WriteLine(t); } } else { foreach (Page page in engine) { if (limit > 0 && ++count > limit) { break; } string title = page.ToString(); if (transformRegex != null) { title = transformRegex.Replace(title, transformReplacement); } Console.WriteLine(title); } } } else if (cmd0 == "set") { string name = String.Join(" ", split, 1, split.Length - 1); if (name.Length == 0) { Console.Write("Name: "); name = Console.ReadLine(); } engine.StoreVariable(name); } else if (cmd0 == "get") { string name = String.Join(" ", split, 1, split.Length - 1); if (name.Length == 0) { Console.Write("Name: "); name = Console.ReadLine(); } if (engine.LoadVariable(name)) { Console.WriteLine(String.Format("Current result size: {0}", engine.Count)); } else { Console.WriteLine("Variable not found"); } } else if (command == "unset") { string name = String.Join(" ", split, 1, split.Length - 1); if (name.Length == 0) { Console.Write("Name: "); name = Console.ReadLine(); } if (!engine.UnsetVariable(name)) { Console.WriteLine("Variable not found"); } } else if (command == "transform") { Console.Write("Search: "); string search = Console.ReadLine(); if (search == null) { return(false); } if (search.Length == 0) { transformRegex = null; transformReplacement = null; return(true); } try { transformRegex = new Regex(search); } catch (ArgumentException e) { Console.WriteLine(e.Message); transformRegex = null; transformReplacement = null; return(true); } Console.Write("Replace: "); transformReplacement = Console.ReadLine(); } else if (cmd0 == "sort") { string regex = String.Join(" ", split, 1, split.Length - 1); if (regex.Length == 0) { sortingRegex = null; } else { try { sortingRegex = new Regex(regex); } catch (ArgumentException e) { Console.WriteLine(e.Message); sortingRegex = null; return(true); } } } else if (command == "vars") { foreach (string var in engine.VariableNames) { Console.WriteLine(var); } } else if (cmd0 == "cycles") { LoadCatLinks(); string name = String.Join("_", split, 1, split.Length - 1); if (name.Length == 0) { Console.Write("Name: "); name = Console.ReadLine(); } Page page; if (!engine.PagesByName.TryGetValue(new Pair <Namespace, string>(Namespace.Category, name), out page)) { Console.WriteLine("No such category"); return(true); } List <List <Category> > cycles = engine.FindCategoryCycles((Category)page); int lastCount = -1; foreach (List <Category> cycle in cycles.OrderBy(c => c.Count)) { if (lastCount != cycle.Count) { lastCount = cycle.Count; Console.WriteLine(); Console.WriteLine("{0}", lastCount); Console.WriteLine(); } bool first = true; foreach (Category cat in cycle) { if (!first) { Console.Write(" ← "); } first = false; Console.Write(cat.Title); } Console.WriteLine(); } } else if (cmd0 == "furthestfrom") { string name = String.Join("_", split, 1, split.Length - 1); if (name.Length == 0) { Console.Write("Name: "); name = Console.ReadLine(); } Page page; if (!engine.PagesByName.TryGetValue(new Pair <Namespace, string>(Namespace.Main, name), out page)) { Console.WriteLine("No such page"); return(true); } var longestPath = engine.LongestPathTo(page); Console.WriteLine("Longest path: {0}", longestPath.First); foreach (var furthestPage in longestPath.Second) { Console.Write("* "); foreach (var step in furthestPage) { Console.Write(" {0}", step.Title); } Console.WriteLine(); } } else if (command == "longestpaths") { var longestPaths = engine.GloballyLongestPaths(); Console.WriteLine("Longest path: {0}", longestPaths.Item1); foreach (var longestPath in longestPaths.Item2) { Console.Write("* "); foreach (var step in longestPath) { Console.Write(" {0}", step.Title); } Console.WriteLine(); } } else if (command == "wantedarticles") { var redlinks = engine.FindRedlinks(); using (var fs = new StreamWriter("wantedarticles.csv")) { foreach (var wanted in redlinks.OrderByDescending(w => w.Value)) { fs.WriteLine("{0};{1}", wanted.Value, wanted.Key); } } } else if (cmd0 == "popular") { string limitStr, projectNames; if (split.Length < 2) { Console.Write("Limit: "); limitStr = Console.ReadLine(); } else { limitStr = split[1]; } if (split.Length < 3) { Console.Write("Project names: "); projectNames = Console.ReadLine(); } else { projectNames = String.Join(" ", split.Skip(2)); } int limit = Int32.Parse(limitStr); engine.LoadPageViews(new HashSet <string>(projectNames.Split(' '))); var outputList = new SortedDictionary <Pair <int, string>, string>(); foreach (Page page in engine) { int views; var title = page.ToString(); engine.PageViews.TryGetValue(page, out views); outputList[new Pair <int, string>(-views, title)] = title; } int count = 0; foreach (var key in outputList.Keys) { if (limit > 0 && ++count > limit || key.First == 0) { break; } var title = outputList[key]; string t = title; if (transformRegex != null) { t = transformRegex.Replace(t, transformReplacement); } Console.WriteLine("{0}: {1}", -key.First, t); } } else if (command == "help") { Console.WriteLine("Known commands: quit, page, category, +, -, ~, *, =, ?, list, count, set, get, vars, cycles, furthestfrom, longestpaths, wantedarticles, popular, transform, sort"); } else { Console.WriteLine("Invalid command"); } return(true); }
public void SubmitFormUsingPost() { var browser = new BrowserEngine(new FakeWebRequester("<html><form method=\"post\" action=\"http://totaljobs.com/results\"><input type=\"submit\" id=\"save-button\" value=\"save\"></form></html>")); browser.Load("http://totaljobs.com/"); var saveButton = browser.Page.FindById("save-button"); saveButton.Click(); Assert.That(browser.Location.ToString(), Is.EqualTo("http://totaljobs.com/results")); }
public void BeforeEachTest() { _requester = new FakeWebRequester("<p>Hello world</p>"); _browser = new BrowserEngine(_requester); }