| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- 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;
- using InABox.Core;
- using Comal.Classes;
- using Email = Xamarin.Essentials.Email;
- namespace ConnectionTest
- {
- public delegate void RemoveURL(View view);
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class ConnectionTestUnit : ContentView
- {
- public event RemoveURL OnRemoveURL;
- string URL = "";
- string log = "";
- double interval = 1000;
- static RestClient<User> client;
- public ConnectionTestUnit(string url)
- {
- InitializeComponent();
- URL = url;
- urlLbl.Text = URL;
- Task.Run(() =>
- {
- Thread.Sleep(3000);
- StartTest();
- });
- Resolve();
- ResolveTimer();
- UpdateInterval();
- }
- 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.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).First().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 = 0;
- int crashcount = 0;
- while (true)
- {
- try
- {
-
- Thread.Sleep((int)interval);
- if(client == null)
- client = new RestClient<User>(URL, false, true, BinarySerializationSettings.Latest);
- if(ClientFactory.ClientType == null)
- ClientFactory.SetClientType(typeof(RestClient<>), InABox.Core.Platform.TimeBench, "Connection Test app 2.0 - rest client", URL, true);
- var result = ClientFactory.Validate("TAN", "nictan");
- //var request = WebRequest.Create("http://" + URL);
- //var response = request.GetResponse();
- //var cmd = string.Format(
- // "{0}{1}?format={2}&responseFormat={3}&serializationVersion={4}",
- // "validate",
- // "User",
- // "Json",
- // "Json",
- // "1.0"
- // );
- Device.BeginInvokeOnMainThread(() =>
- {
- count++;
- attemptNoLbl.Text = "Attempt: " + count;
- });
- //CoreTable table = new Client<Product>().Query();
- Device.BeginInvokeOnMainThread(() =>
- {
- count++;
- attemptNoLbl.Text = "Attempt: " + count;
- });
- }
- catch (Exception ex)
- {
- log = log + "Attempt number: " + count
- + Environment.NewLine
- + "Date/time: " + DateTime.Now.ToString("HH:mm dd MMM yy")
- + Environment.NewLine
- + Environment.NewLine
- + ex.Message + ex.StackTrace;
- crashcount++;
- count++;
- Device.BeginInvokeOnMainThread(() =>
- {
- attemptNoLbl.Text = "Attempt: " + count;
- crashNoLbl.Text = "Crash Count: " + crashcount;
- });
- }
- }
- }
- private void CloseButton_Clicked(object sender, EventArgs e)
- {
- OnRemoveURL?.Invoke(this);
- }
- void MinusBtn_Clicked(System.Object sender, System.EventArgs e)
- {
- if (interval > 500)
- {
- interval = interval - 500;
- UpdateInterval();
- }
- else if(interval == 500)
- {
- interval = 100;
- UpdateInterval();
- }
- }
- void PlusButton_Clicked(System.Object sender, System.EventArgs e)
- {
- if (interval >= 500)
- {
- interval = interval + 500;
- UpdateInterval();
- }
- else if(interval == 100)
- {
- interval = 500;
- UpdateInterval();
- }
- }
- private void UpdateInterval()
- {
- intervalLbl.Text = "Interval: " + (interval / 1000) + "s";
- }
- }
- }
|