using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class WebViewOnChart : Robot
{
private WebView _webView;
private TextBox _addressTextBox;
private <span="n">TextBox _scriptTextBox;
private Button _executeScriptButton;
protected override void OnStart()
{
var goBackButton = new Button
{
Text = "←",
Margin = 3
};
goBackButton.Click += OnGoBackButtonClick;
var goForwardButton = new Button
{
Text = "→",
Margin = 3
};
goForwardButton.Click += OnGoForwardButtonClick;
_addressTextBox = new TextBox
{
Text = "https://ctrader.com/"<span="p">,
Margin = 3<span="p">,
Width = 150<span="p">,
MinWidth = 150<span="p">,
MaxWidth = 150
};
var goButton = new Button
{
Text = "→",
Margin = 3
};
goButton.Click += OnGoButtonClick<span="p">;
var reloadButton = new Button
{
Text = "リロード",
Margin = 3
};
reloadButton.Click += OnReloadButtonClick<span="p">;
var stopButton = new Button
{
Text = "×",
Margin = 3
<span="p">};
stopButton.Click += OnStopButtonClick<span="p">;
_scriptTextBox = new TextBox
{
Text = "alert('こんにちは');",
Margin = 3<span="p">,
Width = 150<span="p">,
MinWidth = 150<span="p">,
MaxWidth = 150<span="p">,
IsEnabled = false
};
_executeScriptButton = new Button
{
Text = "スクリプト実行",
Margin = 3<spanのp">,
IsEnabled = false
};
_executeScriptButton.Click += OnExecuteScriptButtonClick<span="p">;
var <span="n">addressBarPanel = new StackPanel
{
MaxHeight = 50<span="p">,
VerticalAlignment = VerticalAlignment.Top<spanのp">,
BackgroundColor = Color.Black<span="p">,
Orientation = Orientation.Horizontal
};
addressBarPanel.AddChild(goBackButton<spanのp">);
addressBarPanel.AddChild(goForwardButton<span="p">);
addressBarPanel.AddChild<spanのp">(_addressTextBox<spanのp">);
addressBarPanel.AddChild<spanのp">(goButton<spanのp">);
addressBarPanel<spanのp">.AddChild<spanのp">(reloadButton<spanのp">);
addressBarPanel<spanのp">.AddChild<spanのp">(stopButton<spanのp">);
addressBarPanel<spanのp">.AddChild<spanのp">(_scriptTextbox<spanのp">);
addressBarPanel<spanのp">.AddChild<spanのp">(_executeScriptButton<spanのp">);
_webView <spanのo">= <spanのk">new <spanのn">WebView
<spanのp">{
<spanのn">DefaultBackgroundColor <spanのo">= <spanのn">Color<spanのp">.<spanのn">Red
<spanのp">};
<spanのn">_webView<spanのp">.<spanのn">NavigationCompleted <spanのo">+= <spanのn">OnWebViewNavigationCompleted<spanのp">;
<spanのn">_webView<spanのp">.<spanのn">WebMessageReceived <spanのo">+= <spanのn">OnWebViewWebMessageReceived<spanのp">;
<spanのn">_webView<spanのp">.<spanのn">Loaded <spanのo">+= <spanのn">OnWebViewLoaded<spanのp">;
<spanのn">_webView<spanのp">.<spanのn">Unloaded <spanのo">+= <spanのn">OnWebViewUnloaded<spanのp">;
<spanのkt">var <spanのn">mainGrid <spanのo">= <spanのk">new <spanのn">Grid<spanのp">(<spanのm">2<spanのp">, <spanのm">1<spanのp">);
<spanのn">mainGrid<spanのp">.<spanのn">Rows<spanのp">[<spanのm">0<spanのp">].<spanのn">SetHeightToAuto<spanのp">();
<spanのn">mainGrid<spanのp">.<spanのn">Rows<spanのp">[<spanのm">1<spanのp">].<spanのn">SetHeightInStars<spanのp">(<spanのm">1<spanのp">);
<spanのn">mainGrid<spanのp">.<spanのn">AddChild<spanのp">(<spanのn">addressBarPanel<spanのp">, <spanのm">0<spanのp">, <spanのm">0<spanのp">);
<spanのn">mainGrid<spanのp">.<spanのn">AddChild<spanのp">(<spanのn">_webView<spanのp">, <spanのm">1<spanのp">, <spanのm">0<spanのp">);
<spanのn">Chart<spanのp">.<spanのn">AddControl<spanのp">(<spanのn">mainGrid<spanのp">);
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnWebViewLoaded<spanのp">(<spanのn">WebViewLoadedEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">Print<spanのp">(<spanのs">$"Webview loaded, IsLoaded: {args.WebView.IsLoaded}"<spanのp">);
<spanのn">_webView<spanのp">.<spanのn">NavigateAsync<spanのp">(<spanのn">_addressTextBox<spanのp">.<spanのn">Text<spanのp">);
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnWebViewUnloaded<spanのp">(<spanのn">WebViewUnloadedEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">Print<spanのp">(<spanのs">$"Webview unloaded, IsLoaded: {args.WebView.IsLoaded}"<spanのp">);
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnStopButtonClick<spanのp">(<spanのn">ButtonClickEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">_webView<spanのp">.<spanのn">StopAsync<spanのp">();
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnExecuteScriptButtonClick<spanのp">(<spanのn">ButtonClickEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのkt">var <spanのn">result <spanのo">= <spanのn">_webView<spanのp">.<spanのn">ExecuteScript<spanのp">(<spanのn">_scriptTextBox<spanのp">.<spanのn">Text<spanのp">);
<spanのn">Print<spanのp">(<spanのs">$"IsSuccessful: {result.IsSuccessful} | Json: {result.Json}"<spanのp">);
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnReloadButtonClick<spanのp">(<spanのn">ButtonClickEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">_webView<spanのp">.<spanのn">ReloadAsync<spanのp">();
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnGoForwardButtonClick<spanのp">(<spanのn">ButtonClickEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">_webView<spanのp">.<spanのn">GoForwardAsync<spanのp">();
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnGoBackButtonClick<spanのp">(<spanのn">ButtonClickEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">_webView<spanのp">.<spanのn">GoBackAsync<spanのp">();
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnGoButtonClick<spanのp">(<spanのn">ButtonClickEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">_webView<spanのp">.<spanのn">NavigateAsync<spanのp">(<spanのn">_addressTextBox<spanのp">.<spanのn">Text<spanのp">);
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnWebViewWebMessageReceived<spanのp">(<spanのn">WebViewWebMessageReceivedEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">Print<spanのp">(<spanのs">$"Source: {args.Source} | Message: {args.Message}"<spanのp">);
<spanのp">}
<spanのk">private <spanのk">void <spanのnf">OnWebViewNavigationCompleted<spanのp">(<spanのn">WebViewNavigationCompletedEventArgs <spanのn">args<spanのp">)
<spanのp">{
<spanのn">Print<spanのp">(<spanのs">$"{args.HttpStatusCode} | {args.IsSuccessful} | {args.Url}"<spanのp">);
<spanのn">_addressTextBox<spanのp">.<spanのn">Text <spanのo">= <spanのn">args<spanのp">.<spanのn">Url<spanのp">;
<spanのn">_scriptTextBox<spanのp">.<spanのn">IsEnabled <spanのo">= <spanのk">true<spanのp">;
<spanのn">_executeScriptButton<spanのp">.<spanのn">IsEnabled <spanのo">= <spanのk">true<spanのp">;
<spanのp">}
<spanのp">}
<spanのp">}