Browse Source

PRS MOBILE - error logging changes

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
4541d1b3a0

+ 6 - 0
prs.mobile/comal.timesheets.Android/Properties/AndroidManifest.xml

@@ -30,4 +30,10 @@
 			<data android:scheme="tel" />
 		</intent>
 	</queries>
+	<queries>
+		<intent>
+			<action android:name="android.intent.action.SENDTO" />
+			<data android:scheme="mailto" />
+		</intent>
+	</queries>
 </manifest>

+ 7 - 2
prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

@@ -120,15 +120,20 @@ namespace comal.timesheets
             {
                 if (App.Current.Properties.Count > 0)
                 {
+                    List<string> toDelete = new List<string>();
                     foreach (string s in App.Current.Properties.Keys)
                     {
                         if (s.Contains("NotifiedOfChanges"))
                         {
                             if (!s.Equals("NotifiedOfChanges" + MobileUtils.AppVersion.InstalledVersionNumber))
                             {
-                                App.Current.Properties.Remove(s);
+                                toDelete.Add(s);
                             }
-                        }
+                        }                       
+                    }
+                    foreach (string s in toDelete)
+                    {
+                        App.Current.Properties.Remove(s);
                     }
                 }
                 if (!App.Current.Properties.ContainsKey("NotifiedOfChanges" + MobileUtils.AppVersion.InstalledVersionNumber))

+ 3 - 1
prs.mobile/comal.timesheets/Main/Settings.xaml

@@ -132,7 +132,9 @@
             <!--<Label Text="Shared Device" Grid.Row="10" Grid.Column="0" FontSize="Small" VerticalOptions="Center" VerticalTextAlignment="Center"/>
             <CheckBox Grid.Row="10" Grid.Column="1" x:Name="sharedDeviceRb" VerticalOptions="Center"
                       CheckedChanged="sharedDeviceRb_Changed"/>-->
-
+            <!--row 11-->
+            <Button Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2" x:Name="sendErrorsBtn" IsEnabled="False" Clicked="SendErrorsBtn_Clicked" VerticalOptions="Start"
+               Text="Email Error Log" Padding="3" FontSize="Medium" TextColor="White" BackgroundColor="#15C7C1" FontAttributes="Bold" CornerRadius="10"/>
         </Grid>
     </ScrollView>
 </ContentPage>

+ 42 - 1
prs.mobile/comal.timesheets/Main/Settings.xaml.cs

@@ -1,4 +1,6 @@
 using System;
+using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
@@ -57,7 +59,7 @@ namespace comal.timesheets
         }
 
         private async void ExitBtn_Clicked(object sender, EventArgs e)
-        {           
+        {
             using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Working"))
             {
                 //Syncfusion Masked editor still needs access before popping the page       
@@ -122,6 +124,15 @@ namespace comal.timesheets
                 updateVersionBtn.Text = "Update App Version (" + latestVersionNumber + ")";
             }
 
+            const string errorFilename = "Fatal.log";
+            var libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
+            var errorFilePath = Path.Combine(libraryPath, errorFilename);
+
+            if (File.Exists(errorFilePath))
+            {
+                sendErrorsBtn.IsEnabled = true;
+            }
+
             //if (Application.Current.Properties.ContainsKey("IsSharedDevice"))
             //{
             //    if (Application.Current.Properties["IsSharedDevice"].Equals("True"))
@@ -329,5 +340,35 @@ namespace comal.timesheets
         //        DisplayAlert("Success", "", "OK");
         //    }
         //}
+
+        private async void SendErrorsBtn_Clicked(object sender, EventArgs e)
+        {
+            try
+            {
+                const string errorFilename = "Fatal.log";
+                var libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
+                var errorFilePath = Path.Combine(libraryPath, errorFilename);
+
+                if (!File.Exists(errorFilePath))
+                {
+                    return;
+                }
+
+                var errorText = File.ReadAllText(errorFilePath);
+
+                var message = new EmailMessage
+                {
+                    Subject = "Error Logs from " + GlobalVariables.EmpName,
+                    Body = errorText,
+                    To = new List<string> { "nick@prsdigital.com.au" }
+                };
+
+                await Email.ComposeAsync(message);
+
+                File.Delete(errorFilePath);
+            }
+            catch { }
+        }
+
     }
 }