static public void CloseBrowser(this BlazorSession session) { RunBrowser(session, browser => { browser.Agent.Dispose(); }); }
static public void ShowDevTools(this BlazorSession session) { RunBrowser(session, browser => { browser.Agent.ShowDevTools(); }); }
static public void RunBrowser(this BlazorSession session, Action <ICefWinBrowser> action) { var browser = FindBrowser(session); CefWin.PostToAppThread(delegate { action(browser); }); }
private void WorkLoop(BlazorSession bses, string guid) { this.client.ErrorOccurred += (sender, args) => { this.viewmode = "login"; bses.InvokeInRenderThread(delegate { BlazorSession.Current.Alert("Error", args.Exception.ToString()); this.StateHasChanged(); }); this.client.Dispose(); }; using System.IO.StreamReader sr = new System.IO.StreamReader(this.shellstream); while (!this.isdisposed && this.client.IsConnected) { System.Threading.Thread.Sleep(10); //TODO:??? if (guid != this.client_guid) { return; } string line = sr.ReadLine(); if (line == null) { continue; } if (guid != this.client_guid) { return; } lock (this.linequeue) { this.linequeue.Enqueue(line); } this.notifylineready?.Invoke(); } }
static public ICefWinBrowser FindBrowser(this BlazorSession session) { WebCustomizeSession wcs = (WebCustomizeSession)session; long CefWinBrowserId; if (!long.TryParse(wcs.HttpContextAccessor.HttpContext.Request.Cookies["CefWinBrowserId"], out CefWinBrowserId)) { //BlazorSession.Current.Toast("Failed to get browserid"); return(CefWin.MainBrowser); } ICefWinBrowser browser = CefWin.FindBrowser(CefWinBrowserId); if (browser == null) { //BlazorSession.Current.Toast("Failed to find browser : " + CefWinBrowserId); return(CefWin.MainBrowser); } return(browser); }
private void BDTReady(BlazorDomTree bdt) { BlazorSession ses = BlazorSession.Current; PlusControl resultdiv = bdt.Root.Create("div style='margin:8px 0;max-width:100%;height:400px;background-color:black;color:white;overflow-y:scroll;padding:5px 5px 15px;'"); PlusControl div1 = bdt.Root.Create("div style='display:flex;'"); // div1.Create("label style='width:100px").InnerText("Command:"); PlusControl inpword = div1.Create("input type='text' style='flex:99;padding:0 5px'"); PlusControl button = div1.Create("button").InnerText("Send"); div1.Create("button").InnerText("^C").OnClick(delegate { this.shellstream.WriteByte(3); this.shellstream.Flush(); }); string _lastcolor = null; PlusControl SetLastColor(PlusControl span) { if (_lastcolor != null) { span.Style("color", _lastcolor); if (_lastcolor == "black") { span.Style("background-color", "white"); } } return(span); } void SendLine(string line, string color) { ses.ConsoleLog("line", System.Text.Json.JsonSerializer.Serialize(line)); var d = resultdiv.Create("div style='color:" + color + "'"); if (string.IsNullOrEmpty(line)) { d.InnerHTML("<br/>"); return; } if (line.IndexOf("\x1b[") == -1) { if (color == null) { SetLastColor(d); } d.InnerText(line); return; } //parse ssh color: int pos = 0; while (pos < line.Length) { int p33 = line.SafeIndexOf("\x1b[", pos); if (p33 == -1) { string laststr = line[pos..]; if (!string.IsNullOrEmpty(laststr)) { //ses.ConsoleLog("last", System.Text.Json.JsonSerializer.Serialize(laststr)); SetLastColor(d.Create("span")).InnerText(laststr); } break; }