| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using InABox.Clients;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using Xamarin.Essentials;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using System.Net;
- namespace ConnectionTest
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class ConnectionTestUnit : ContentView
- {
- string URL = "";
- string log = "";
- public ConnectionTestUnit(string url)
- {
- InitializeComponent();
- URL = url;
- urlLbl.Text = URL;
- Task.Run(() =>
- {
- Thread.Sleep(500);
- StartTest();
- });
- Resolve();
- ResolveTimer();
- }
- private void ResolveTimer()
- {
- Task.Run(() =>
- {
- while (true)
- {
- int count = 59;
- while (count != 0)
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- refreshLbl.Text = "(refresh in " + count + " s)";
- });
- Thread.Sleep(1000);
- count--;
- }
- Resolve();
- }
- });
- }
- private void Resolve()
- {
- try
- {
- var ip = Dns.GetHostEntry(URL.Substring(0, URL.Length - 5));
- Device.BeginInvokeOnMainThread(() =>
- {
- ipResolveLbl.Text = ip.AddressList[0].ToString();
- ipResolveLbl.BackgroundColor = Color.LightGreen;
- Task.Run(() =>
- {
- Thread.Sleep(1500);
- Device.BeginInvokeOnMainThread(() =>
- {
- ipResolveLbl.BackgroundColor = Color.Default;
- });
- });
- });
- }
- catch (Exception ex)
- {
- ipResolveLbl.Text = "Resolve error";
- }
- }
- private void EmailBtn_Clicked(object sender, EventArgs e)
- {
- Device.BeginInvokeOnMainThread(async () =>
- {
- var message = new EmailMessage
- {
- Subject = "Crash logs",
- Body = log,
- To = new List<string> { "support@prsdigital.com.au" }
- };
- await Email.ComposeAsync(message);
- });
- }
- private void StartTest()
- {
- int count = 1;
- int crashcount = 0;
- ClientFactory.SetClientType(typeof(JsonClient<>), "Test app", "1.0", URL, true);
- while (true)
- {
- try
- {
- Thread.Sleep(500);
- var result = ClientFactory.Validate("TAN", "nictan");
- Device.BeginInvokeOnMainThread(() =>
- {
- attemptNoLbl.Text = "Attempt: " + count;
- count++;
- });
- }
- catch (Exception ex)
- {
- log = log + "Attempt number: " + count
- + Environment.NewLine
- + ex.Message + ex.StackTrace;
- crashcount++;
- count++;
- Device.BeginInvokeOnMainThread(() => { crashNoLbl.Text = "Crash Count: " + crashcount; });
- }
- }
- }
- }
- }
|