Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .vs/API-NG-sample-code/v17/.wsuo
Binary file not shown.
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\Api-ng-sample-code.sln",
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33 changes: 17 additions & 16 deletions loginCode/Interactive-cSharp/SampleAPI/SampleAPI/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 62 additions & 68 deletions loginCode/Interactive-cSharp/SampleAPI/SampleAPI/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Text;
using System.Windows.Forms;
using System.Net;

using Microsoft.Web.WebView2.Core;

namespace SampleAPI
{
Expand Down Expand Up @@ -36,38 +36,39 @@ public Form1()
tt.InitialDelay = 0;
tt.ShowAlways = true;
tt.SetToolTip(this.grpAppKey, "Please enter your developer Appkey");

}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
private async void webview2_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
{
string c = "";
if (webview2.Source.IdnHost == "www.betfair.com")
{
List<CoreWebView2Cookie> cookies = await this.webview2.CoreWebView2.CookieManager.GetCookiesAsync(KeepAliveURL);

//On embeded web browser response get cookie
string cookie = this.webBrowser1.Document.Cookie;
foreach (var cookie in cookies)
{
c += cookie.Name + "=" + cookie.Value + ";";
}
}


if (cookie != null)
this.ParseCookie(cookie);
if (c != "")
this.ParseCookie(c);

//If successfull login start KeepAlive
if (!m_LoggedOut && !m_KeepAliveTimer.Enabled)
{
webBrowser1.Visible = false;
SetMessage("Logon successfull\r\n SSOID=" + m_SSOID);

SetMessage("Logged In");


this.StartKeepAlive();
}
}

private void ParseCookie(string p_Cookie)
{

//If logon on OK get SSOID
if (m_LoggedOut && p_Cookie.IndexOf("loggedIn=true;") >= 0)
{

int SSOIDIndex = p_Cookie.IndexOf("ssoid=");

if (SSOIDIndex >= 0)
Expand All @@ -80,87 +81,80 @@ private void ParseCookie(string p_Cookie)
m_SSOID = "SSOID Not present";
}
}



private void btnLogout_Click(object sender, EventArgs e)
{
m_KeepAliveTimer.Enabled = false;
m_KeepAliveTimer.Close();
m_LoggedOut = true;

System.Uri u = new Uri(LogoutURL);
this.webBrowser1.Url = u;
this.webBrowser1.Navigate(u);
webview2.Source = u;
webview2.NavigateToString(LogoutURL);

SetMessage("Logged out");



}

private void StartKeepAlive()
{
{
m_KeepAliveTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnKeepAliveTimer);
// Set the Interval to 15 mins.
m_KeepAliveTimer.Interval = 1000 * 60 * 15;
m_KeepAliveTimer.Enabled = true;


}

private void OnKeepAliveTimer(object source, System.Timers.ElapsedEventArgs e)
private void OnKeepAliveTimer(object source, System.Timers.ElapsedEventArgs e)
{

System.Uri u = new Uri(KeepAliveURL);
this.webBrowser1.Url = u;
this.webBrowser1.Navigate(u);
this.Invoke((MethodInvoker)delegate {
webview2.Source = u;
webview2.NavigateToString(KeepAliveURL);
});

m_KeepAliveCount++;
SetMessage("Keep Alive sent " + m_KeepAliveCount);
}

//Thread safe TextBox Set text
delegate void SetTextCallback(string p_Text);
private void SetMessage(string p_Text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.txtMessage.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetMessage);
this.Invoke(d, new object[] { p_Text });
}
else
{
this.txtMessage.Text = p_Text;
}
}

private void btnLogon_Click(object sender, EventArgs e)
{
//Put Appkey in Logon anf Logout URLs
LogonURL = LogonURL.Replace("[APPKEY]", this.txtAppKey.Text);
LogoutURL = LogoutURL.Replace("[APPKEY]", this.txtAppKey.Text);

//Give embeded web browser Betfair api login page URL
System.Uri u = new Uri(LogonURL);

this.webview2.Source = u;

this.btnLogout.Enabled = true;
}

private void txtAppKey_KeyUp(object sender, KeyEventArgs e)
{
this.btnLogon.Enabled = true;
}

private void webview2_Click(object sender, EventArgs e)
{

//Thread safe TextBox Set text
delegate void SetTextCallback(string p_Text);
private void SetMessage(string p_Text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.txtMessage.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetMessage);
this.Invoke(d, new object[] { p_Text });
}
else
{
this.txtMessage.Text = p_Text;
}
}


private void btnLogon_Click(object sender, EventArgs e)
{
//Put Appkey in Logon anf Logout URLs
LogonURL = LogonURL.Replace("[APPKEY]", this.txtAppKey.Text);
LogoutURL = LogoutURL.Replace("[APPKEY]", this.txtAppKey.Text);

//Give embeded web browser Betfair api login page URL
System.Uri u = new Uri(LogonURL);

this.webBrowser1.Url = u;

this.btnLogout.Enabled = true;

}

private void txtAppKey_KeyUp(object sender, KeyEventArgs e)
{
this.btnLogon.Enabled = true;
}


}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading