Kaynağa Gözat

PRS MOBILE - Connection Test app: multiple connection testing

Nick-PRSDigital@bitbucket.org 2 yıl önce
ebeveyn
işleme
6afc4a963f

+ 5 - 0
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest/ConnectionTest.csproj

@@ -23,6 +23,11 @@
     <ProjectReference Include="..\..\..\..\..\inabox\inabox.logging.shared\InABox.Logging.Shared.csproj" />
     <ProjectReference Include="..\..\..\..\..\inabox\inabox.logging.shared\InABox.Logging.Shared.csproj" />
     <ProjectReference Include="..\..\..\..\..\inabox\inabox.websocket.shared\InABox.WebSocket.Shared.csproj" />
     <ProjectReference Include="..\..\..\..\..\inabox\inabox.websocket.shared\InABox.WebSocket.Shared.csproj" />
   </ItemGroup>
   </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Update="ConnectionTestUnit.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+  </ItemGroup>
   <Import Project="..\..\..\inabox\InABox.Remote.Shared\InABox.Remote.Shared.projitems" Label="Shared" Condition="Exists('..\..\..\inabox\InABox.Remote.Shared\InABox.Remote.Shared.projitems')" />
   <Import Project="..\..\..\inabox\InABox.Remote.Shared\InABox.Remote.Shared.projitems" Label="Shared" Condition="Exists('..\..\..\inabox\InABox.Remote.Shared\InABox.Remote.Shared.projitems')" />
   <Import Project="..\..\..\inabox\InABox.Client.Remote.Shared\InABox.Client.Remote.Shared.projitems" Label="Shared" Condition="Exists('..\..\..\inabox\InABox.Client.Remote.Shared\InABox.Client.Remote.Shared.projitems')" />
   <Import Project="..\..\..\inabox\InABox.Client.Remote.Shared\InABox.Client.Remote.Shared.projitems" Label="Shared" Condition="Exists('..\..\..\inabox\InABox.Client.Remote.Shared\InABox.Client.Remote.Shared.projitems')" />
 </Project>
 </Project>

+ 15 - 0
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest/ConnectionTestUnit.xaml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
+             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+             x:Class="ConnectionTest.ConnectionTestUnit">
+  <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>
+        </Frame>
+    </ContentView.Content>
+</ContentView>

+ 73 - 0
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest/ConnectionTestUnit.xaml.cs

@@ -0,0 +1,73 @@
+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;
+
+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(3000);
+                StartTest();
+            });
+        }
+
+        private async void EmailBtn_Clicked(object sender, EventArgs e)
+        {
+            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 + Environment.NewLine + result.ToString();
+                        count++;
+                    });
+                }
+                catch (Exception ex)
+                {
+                    log = log + "Attempt number: " + count
+                        + Environment.NewLine
+                        + ex.Message + ex.StackTrace;
+                    crashcount++;
+                    count++;
+                    Device.BeginInvokeOnMainThread(() => { crashNoLbl.Text = "Crash Count: " + crashcount; });
+
+                }
+            }
+        }
+    }
+}

+ 16 - 12
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest/MainPage.xaml

@@ -3,17 +3,21 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              x:Class="ConnectionTest.MainPage">
              x:Class="ConnectionTest.MainPage">
 
 
-    <StackLayout HorizontalOptions="Center">
-        <Label x:Name="urlLbl" HorizontalOptions="Center" FontAttributes="Bold" Margin="0,100,0,0"/>
-        <Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0" VerticalOptions="Center" Margin="5">
-            <Label Text="Welcome to Xamarin.Forms!" x:Name="lbl"
-
-                   HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
-        </Frame>
-        <Label HorizontalOptions="Center" x:Name="crashcountlbl" Text="crash count"/>
-        <Button Text="Email logs" Clicked="Button_Clicked" HorizontalOptions="Center" CornerRadius="10" BorderColor="Gray"/>
-        <Button Text="Start test" Clicked="Button_Clicked_1" HorizontalOptions="Center" CornerRadius="10" BorderColor="Gray"/>
-    </StackLayout>
-
+    <ScrollView>
+        <StackLayout x:Name="stacklayout">
+            <Frame Padding="2" BackgroundColor="LightYellow" Margin="2" CornerRadius="5">
+                <Grid>
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="auto"/>
+                        <ColumnDefinition Width="*"/>
+                        <ColumnDefinition Width="auto"/>
+                    </Grid.ColumnDefinitions>
+                    <Label Text="Add URL: " Grid.Column="0" VerticalOptions="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>
+            </Frame>
+        </StackLayout>
+    </ScrollView>
 </ContentPage>
 </ContentPage>
 
 

+ 18 - 51
prs.mobile/ConnectionTestApp/ConnectionTest/ConnectionTest/MainPage.xaml.cs

@@ -13,64 +13,31 @@ namespace ConnectionTest
 {
 {
     public partial class MainPage : ContentPage
     public partial class MainPage : ContentPage
     {
     {
-        string url = "remote.com-al.com.au:8000";
-        string log = "";
-
+        List<string> urls = new List<string>
+        { 
+            "remote.com-al.com.au:8000",
+            "remote2.com-al.com.au:8000",
+            "remote.prsdigital.com.au:8005",
+            "remote2.prsdigital.com.au:8005",
+        };
         public MainPage()
         public MainPage()
         {
         {
             InitializeComponent();
             InitializeComponent();
-            urlLbl.Text = url;
-        }
-
-
-        private void Load()
-        {
-            ClientFactory.SetClientType(typeof(JsonClient<>), "Test app", "1.0", url, true);
-            int count = 1;
-            int crashcount = 0;
-                while (true)
-                {
-                    try
-                    {
-                    Thread.Sleep(100);
-                    var result = ClientFactory.Validate("TAN", "nictan");
-                        Device.BeginInvokeOnMainThread(() => {
-                        lbl.Text = "Attempt: " + count + Environment.NewLine + result.ToString();
-                        count++;
-                    });
-                    
-                    }
-                    catch (Exception e)
-                    {                       
-                        log = log + "Attempt number: " + count
-                        + Environment.NewLine
-                        + e.Message + e.StackTrace;
-                        crashcount++;
-                        count++;
-                    Device.BeginInvokeOnMainThread(() => { crashcountlbl.Text = "Crash Count: " + crashcount; });
-                        
-
-                    }
-                }
-            
-        }
-
-        async void Button_Clicked(System.Object sender, System.EventArgs e)
-        {
-            var message = new EmailMessage
+            foreach (var url in urls) 
             {
             {
-                Subject = "Crash logs",
-                Body = log,
-                To = new List<string> { "nick@prsdigital.com.au" }
-            };
-
-            await Email.ComposeAsync(message);
+                var test = new ConnectionTestUnit(url);
+                stacklayout.Children.Add(test);
+            }
         }
         }
 
 
-        void Button_Clicked_1(System.Object sender, System.EventArgs e)
+        private void AddButton_Clicked(object sender, EventArgs e)
         {
         {
-            Task.Run(() => { Load(); });
-            
+            if (!string.IsNullOrWhiteSpace(urlEnt.Text))
+            {
+                var test = new ConnectionTestUnit(urlEnt.Text);
+                stacklayout.Children.Add(test);
+                urlEnt.Text = "";
+            }
         }
         }
     }
     }
 }
 }