Browse Source

PRS MOBILE - error logging

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
ef07a5855a
1 changed files with 29 additions and 2 deletions
  1. 29 2
      prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

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

@@ -17,6 +17,7 @@ using comal.timesheets.StoreRequis;
 using PRSSecurity = InABox.Core.Security;
 using Plugin.LocalNotification;
 using comal.timesheets.Tasks;
+using System.IO;
 
 namespace comal.timesheets
 {
@@ -89,7 +90,7 @@ namespace comal.timesheets
                 //if (GlobalVariables.EmpID == Guid.Parse("40f6ccd9-5272-4b1a-99bf-de7542205aac"))
                 //    RunCustomScript();
                 NotifyChanges();
-
+                SendErrors();
             }
             catch (Exception e)
             {
@@ -98,6 +99,32 @@ namespace comal.timesheets
             NavigationPage.SetHasBackButton(this, false);
         }
 
+        private void SendErrors()
+        {
+            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);
+
+                Notification n = new Notification();
+                n.Title = "Error log from " + GlobalVariables.EmpName;
+                n.Description = errorText;
+                n.Employee.ID = Guid.Parse("40f6ccd9-5272-4b1a-99bf-de7542205aac");
+
+                new Client<Notification>().Save(n, "Error from mobile");
+
+                File.Delete(errorFilePath);
+            }
+            catch { }
+        }
 
         private void RunCustomScript()
         {
@@ -129,7 +156,7 @@ namespace comal.timesheets
                             {
                                 toDelete.Add(s);
                             }
-                        }                       
+                        }
                     }
                     foreach (string s in toDelete)
                     {