Преглед на файлове

PRS MOBILE - connection test added resolve address

Nick-PRSDigital@bitbucket.org преди 2 години
родител
ревизия
d7c98afb81

+ 6 - 0
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest.Android/Properties/AndroidManifest.xml

@@ -3,4 +3,10 @@
 	<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />
 	<application android:label="ConnectionTest.Android" android:theme="@style/MainTheme"></application>
 	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+	<queries>
+		<intent>
+			<action android:name="android.intent.action.SENDTO" />
+			<data android:scheme="mailto" />
+		</intent>
+	</queries>
 </manifest>

+ 20 - 7
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest/ConnectionTestUnit.xaml

@@ -2,14 +2,27 @@
 <ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              x:Class="ConnectionTest.ConnectionTestUnit">
-  <ContentView.Content>
+    <ContentView.Content>
         <Frame Padding="2" CornerRadius="5" Margin="2" BorderColor="DarkGray">
-        <StackLayout>
-            <Label x:Name="urlLbl" HorizontalOptions="Center" FontAttributes="Bold"/>
-                <Label x:Name="attemptNoLbl" Text="Attempt No: 0" HorizontalOptions="Center"/>
-                <Label x:Name="crashNoLbl" Text= "Crash Count: 0" HorizontalOptions="Center"/>
-            <Button x:Name="emailBtn" Text="Email logs" Clicked="EmailBtn_Clicked"/>
-        </StackLayout>
+            <StackLayout>
+                <Label x:Name="urlLbl" HorizontalOptions="Center" FontAttributes="Bold" FontSize="24"/>
+                <Grid>
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="*"/>
+                        <ColumnDefinition Width="*"/>
+                    </Grid.ColumnDefinitions>
+                    <StackLayout Grid.Column="0">
+                        <Label x:Name="attemptNoLbl" Text="Attempt No: 0" HorizontalOptions="Center" FontSize="20" HorizontalTextAlignment="Center"/>
+                        <Label x:Name="crashNoLbl" Text= "Crash Count: 0" HorizontalOptions="Center" FontSize="20"/>
+                    </StackLayout>
+                    <StackLayout Grid.Column="1">
+                        <Label x:Name="resolveLbl" Text="Resolves to: " HorizontalOptions="Center" FontAttributes="Bold"/>
+                        <Label x:Name="ipResolveLbl" Text="Not resolved" HorizontalOptions="Center"/>
+                        <Label x:Name="refreshLbl" HorizontalOptions="Center"/>
+                    </StackLayout>
+                </Grid>
+                <Button x:Name="emailBtn" Text="Email logs" Clicked="EmailBtn_Clicked"/>
+            </StackLayout>
         </Frame>
     </ContentView.Content>
 </ContentView>

+ 62 - 10
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest/ConnectionTestUnit.xaml.cs

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
 using Xamarin.Essentials;
 using Xamarin.Forms;
 using Xamarin.Forms.Xaml;
+using System.Net;
 
 namespace ConnectionTest
 {
@@ -21,23 +22,74 @@ namespace ConnectionTest
             InitializeComponent();
             URL = url;
             urlLbl.Text = URL;
-            Task.Run(() => 
+            Task.Run(() =>
             {
-                Thread.Sleep(3000);
+                Thread.Sleep(500);
                 StartTest();
             });
+            Resolve();
+            ResolveTimer();
         }
 
-        private async void EmailBtn_Clicked(object sender, EventArgs e)
+        private void ResolveTimer()
         {
-            var message = new EmailMessage
+            Task.Run(() =>
             {
-                Subject = "Crash logs",
-                Body = log,
-                To = new List<string> { "support@prsdigital.com.au" }
-            };
+                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";
+            }
+        }
 
-            await Email.ComposeAsync(message);
+        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()
@@ -53,7 +105,7 @@ namespace ConnectionTest
                     var result = ClientFactory.Validate("TAN", "nictan");
                     Device.BeginInvokeOnMainThread(() =>
                     {
-                        attemptNoLbl.Text = "Attempt: " + count + Environment.NewLine + result.ToString();
+                        attemptNoLbl.Text = "Attempt: " + count;
                         count++;
                     });
                 }

+ 2 - 2
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest/MainPage.xaml

@@ -5,14 +5,14 @@
 
     <ScrollView>
         <StackLayout x:Name="stacklayout">
-            <Frame Padding="2" BackgroundColor="LightYellow" Margin="2" CornerRadius="5">
+            <Frame Padding="2" BackgroundColor="LightYellow" Margin="2, 4, 2, 0" CornerRadius="5" BorderColor="DarkGray">
                 <Grid>
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="auto"/>
                         <ColumnDefinition Width="*"/>
                         <ColumnDefinition Width="auto"/>
                     </Grid.ColumnDefinitions>
-                    <Label Text="Add URL: " Grid.Column="0" VerticalOptions="Center"/>
+                    <Label Text="Add URL: " Grid.Column="0" VerticalOptions="Center" HorizontalOptions="Center"/>
                     <Entry x:Name="urlEnt" Grid.Column="1" HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
                     <Button Text="Add" Grid.Column="2" BackgroundColor="LightGreen" Clicked="AddButton_Clicked" VerticalOptions="Center"/>
                 </Grid>