Ver código fonte

PRS MOBILE - login error login, more retrys for connection settings and clock on required data

Nick-PRSDigital@bitbucket.org 2 anos atrás
pai
commit
d58d30ef9f

+ 13 - 4
prs.mobile/comal.timesheets/Data Classes/DataModel.cs

@@ -31,7 +31,7 @@ namespace comal.timesheets
         {
         }
 
-        public void Refresh(bool canbypassgates)
+        public void Refresh(bool canbypassgates = true)
         {
             CanBypassGates = canbypassgates;
 
@@ -70,7 +70,10 @@ namespace comal.timesheets
                     DataChanged?.Invoke(this, typeof(TimeSheet));
                     DataRefreshed?.Invoke();
                 }
-                catch { }
+                catch (Exception ex)
+                {
+                    var log = new MobileLogging(LogType.Query, "Data model RefreshTimeSheet()", ex.Message + ex.StackTrace, this.GetType().Name);
+                }
             });
         }
 
@@ -93,7 +96,10 @@ namespace comal.timesheets
                         DataRefreshed?.Invoke();
                     }
                 }
-                catch { }
+                catch (Exception ex)
+                {
+                    var log = new MobileLogging(LogType.Query, "Data model RefreshEmployee()", ex.Message + ex.StackTrace, this.GetType().Name);
+                }
             });
         }
 
@@ -141,7 +147,10 @@ namespace comal.timesheets
                         }
                     }
                 }
-                catch { }
+                catch (Exception ex)
+                {
+                    var log = new MobileLogging(LogType.Query, "Data model RefreshJobs()", ex.Message + ex.StackTrace, this.GetType().Name);
+                }
             });
         }
     }

+ 4 - 2
prs.mobile/comal.timesheets/Data Classes/GlobalVariables.cs

@@ -71,8 +71,9 @@ namespace comal.timesheets
                 String employeeName = new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid), new Columns<Employee>(x => x.Name)).Rows.First().ToObject<Employee>().Name;
                 return employeeName;
             }
-            catch
+            catch (Exception ex)
             {
+                var log = new MobileLogging(LogType.Query, "GetEmployeeName", ex.Message + ex.StackTrace, "GlobalVariables.GetEmployeeName()");
                 return "";
             }
         }
@@ -84,8 +85,9 @@ namespace comal.timesheets
                 Guid employeeID = new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid), new Columns<Employee>(x => x.ID)).Rows.First().ToObject<Employee>().ID;
                 return employeeID;
             }
-            catch
+            catch(Exception ex)
             {
+                var log = new MobileLogging(LogType.Query, "GetEmployeeID", ex.Message + ex.StackTrace, "GlobalVariables.GetEmployeeID()");
                 return Guid.Empty;
             }
         }

+ 18 - 5
prs.mobile/comal.timesheets/Main/App.xaml.cs

@@ -92,12 +92,25 @@ namespace comal.timesheets
             if (CheckLoadFromLink())
                 return;
 
+            string result = "";
             try
             {
-                var result = JsonClient<User>.Ping(DBSettings.URLs, out DatabaseInfo info);
-                ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + DeviceString, result, true);
+                result = JsonClient<User>.Ping(App.DBSettings.URLs, out DatabaseInfo info);
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.BackgroundProcess, "JsonClient.Ping()", ex.Message + ex.StackTrace, this.GetType().Name);
+                if (App.DBSettings.URLs[0].ToUpper().Contains("COM-AL"))
+                    result = "remote.com-al.com.au:8000";
+            }
+            try
+            {
+                ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + App.DeviceString, result, true);
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.BackgroundProcess, "Client Factory SetClientType", ex.Message + ex.StackTrace, this.GetType().Name);
             }
-            catch { }
         }
 
         private bool CheckLoadFromLink()
@@ -127,8 +140,8 @@ namespace comal.timesheets
                 List<string> list = new List<string>
             {
                 "remote.com-al.com.au:8000",
-                //"remote2.com-al.com.au:8000",
-                //"remote3.com-al.com.au:8000"
+                "remote2.com-al.com.au:8000",
+                "remote3.com-al.com.au:8000"
             };
 
                 DBSettings.URLs = list.ToArray();

+ 35 - 114
prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

@@ -54,7 +54,7 @@ namespace comal.timesheets
         }
         private void RunCustomScript()
         {
-            
+
         }
 
         private void InitItems()
@@ -238,14 +238,18 @@ namespace comal.timesheets
                         GlobalVariables.EmpID = GlobalVariables.GetEmployeeID();
                         GlobalVariables.EmpName = GlobalVariables.GetEmployeeName();
                     }
+
                     clockOnButton.IsEnabled = false;
 
                     bool PRSReady = (App.Data.Employee != null) && (App.Data.TimeSheets != null) && (GlobalVariables.EmpID != Guid.Empty);
+                    if (!PRSReady)
+                        App.Data.Refresh();
 
                     bool GateReady = CheckLocation();
 
                     CurrentLocation.Text = DisplayAddress();
-                    if (CurrentLocation.Text.Contains("ERROR"))
+
+                    if (CurrentLocation.Text.ToUpper().Contains("ERROR"))
                         CurrentLocation.Text = "Unknown Address";
 
                     Title = null;
@@ -287,27 +291,31 @@ namespace comal.timesheets
 
         private void CheckClockOnRequired()
         {
-            if (GlobalVariables.IsJobOnlyEmployee)
-            {
-                clockOnButton.IsVisible = false;
-                CurrentLocation.IsVisible = false;
-                buttonsGrid.IsVisible = false;
-                taskBtn.IsVisible = false;
-                row0.Height = 0;
-                row1.Height = 0;
-                row2.Height = 150;
-                Image img = new Image { Source = "logo.png" };
-                img.Margin = 15;
-                Grid.SetRow(img, 2);
-                homeScreenGrid.Children.Add(img);
-            }
-            else
+            try
             {
-                clockOnButton.IsVisible = true;
-                CurrentLocation.IsVisible = true;
-                buttonsGrid.IsVisible = true;
-                taskBtn.IsVisible = true;
+                if (GlobalVariables.IsJobOnlyEmployee)
+                {
+                    clockOnButton.IsVisible = false;
+                    CurrentLocation.IsVisible = false;
+                    buttonsGrid.IsVisible = false;
+                    taskBtn.IsVisible = false;
+                    row0.Height = 0;
+                    row1.Height = 0;
+                    row2.Height = 150;
+                    Image img = new Image { Source = "logo.png" };
+                    img.Margin = 15;
+                    Grid.SetRow(img, 2);
+                    homeScreenGrid.Children.Add(img);
+                }
+                else
+                {
+                    clockOnButton.IsVisible = true;
+                    CurrentLocation.IsVisible = true;
+                    buttonsGrid.IsVisible = true;
+                    taskBtn.IsVisible = true;
+                }
             }
+            catch { }
         }
 
         private void Job_OnJobNumberChanged(string jobnumber)
@@ -343,18 +351,6 @@ namespace comal.timesheets
         #endregion
 
         #region Clock on/off
-        private void DataChanged(object sender, Type type, Exception e)
-        {
-            RefreshScreen();
-        }
-
-        private void DataRefreshed()
-        {
-            //if (bSharedDevice)
-            //    return;
-            Device.BeginInvokeOnMainThread(() => { RefreshScreen(); });
-        }
-
         bool bBusy = false;
 
         async void ClockOnOff_Clicked(object sender, System.EventArgs e)
@@ -552,85 +548,6 @@ namespace comal.timesheets
 
         }
 
-        private void RecentlyUpdatedTilesTimer(object o)
-        {
-            bRecentlyUpdatedTiles = false;
-            App.Data.Refresh(true);
-            MainPageUtils.SearchForNewNotifications();
-        }
-
-        private void LocationFound(LocationServices sender)
-        {
-            //if (bSharedDevice)
-            //    return;
-            if (App.Bluetooth.RecentlyScanned)
-                UploadTiles();
-
-            try
-            {
-                TimeSheet timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
-                if (timesheet != null)
-                {
-                    if (timesheet.StartLocation.Latitude.Equals(0.0F) && timesheet.StartLocation.Longitude.Equals(0.0F))
-                    {
-                        timesheet.StartLocation.Latitude = sender.Latitude;
-                        timesheet.StartLocation.Longitude = sender.Longitude;
-                        timesheet.StartLocation.Timestamp = sender.TimeStamp;
-                        timesheet.Address = sender.Address;
-                        new Client<TimeSheet>().Save(timesheet, "Updating Timesheet with GPS Coordinates", (o, e) => { });
-                    }
-                }
-
-                if (!string.IsNullOrWhiteSpace(matchedDeviceName))
-                {
-                    InABox.Core.Location curlocation = new InABox.Core.Location() { Latitude = App.GPS.Latitude, Longitude = App.GPS.Longitude };
-                    curlocation.Timestamp = DateTime.Now;
-
-                    GPSTrackerLocation gpsTrackerLocation = new GPSTrackerLocation();
-                    gpsTrackerLocation.DeviceID = matchedDeviceName;
-                    gpsTrackerLocation.Location.Timestamp = curlocation.Timestamp;
-                    gpsTrackerLocation.Location = curlocation;
-
-                    new Client<GPSTrackerLocation>().Save(gpsTrackerLocation, "Updated company device location from Timebench");
-                }
-
-                Device.BeginInvokeOnMainThread(() =>
-                {
-                    RefreshScreen();
-                });
-            }
-            catch { }
-
-        }
-
-        private void LocationError(LocationServices sebder, Exception error)
-        {
-
-        }
-
-        private void ScanFinished(Bluetooth sender)
-        {
-            try
-            {
-                //if (bSharedDevice)
-                //    return;
-                Device.BeginInvokeOnMainThread(() =>
-                {
-                    RefreshScreen();
-                    //if (Button2.BackgroundColor == Color.WhiteSmoke)
-                    //    Button2.BackgroundColor = Color.Red;
-                    //else
-                    //    Button2.BackgroundColor = Color.WhiteSmoke;
-                });
-
-
-                if (App.GPS.RecentlyLocated)
-                    UploadTiles();
-            }
-            catch { }
-        }
-
-
 
         #endregion
 
@@ -1177,14 +1094,18 @@ namespace comal.timesheets
             {
                 if (App.Data.CanBypassGates)
                 {
-                    if (App.GPS.TimeStamp > DateTime.Now.Subtract(new TimeSpan(0, 5, 0)))
+                    if (App.GPS.TimeStamp > DateTime.Now.Subtract(new TimeSpan(0, 15, 0)))
                         return true;
                     else
+                    {
+                        App.GPS.GetLocation(true);
                         return false;
+                    }
+
                 }
                 if (App.Data.Gates == null)
                     return false;
-                if (App.Bluetooth.TimeStamp < DateTime.Now.Subtract(new TimeSpan(0, 2, 0)))
+                if (App.Bluetooth.TimeStamp < DateTime.Now.Subtract(new TimeSpan(0, 15, 0)))
                     return false;
                 if (!App.Bluetooth.Devices.Any())
                     return false;

+ 0 - 2
prs.mobile/comal.timesheets/Main/MainPageUtils.cs

@@ -448,8 +448,6 @@ namespace comal.timesheets
         #region Location / Bluetooth
         private static void LocationFound(LocationServices sender)
         {
-            //if (bSharedDevice)
-            //    return;
             if (App.Bluetooth.RecentlyScanned)
                 UploadTiles();
 

+ 42 - 26
prs.mobile/comal.timesheets/Main/PINLoginPage.xaml.cs

@@ -131,7 +131,6 @@ namespace comal.timesheets
                     return false;
                 }
                 return true;
-
             }
             catch
             {
@@ -139,7 +138,7 @@ namespace comal.timesheets
             }
         }
 
-        public async void RunValidate(bool usePIN = false, string pin = "", bool testingpage = false)
+        public async void RunValidate(bool usePIN = false, string pin = "")
         {
             try
             {
@@ -188,8 +187,7 @@ namespace comal.timesheets
                                 }
                             }
                         }
-                        if (!testingpage)
-                            LaunchMainPage();
+                        LaunchMainPage();
                         return;
                     default:
                         ShowPINPad();
@@ -199,35 +197,53 @@ namespace comal.timesheets
             catch (Exception ex)
             {
                 var log = new MobileLogging(LogType.Validate, "Validation", ex.Message + ex.StackTrace, this.GetType().Name);
-                string chosenOption = await DisplayActionSheet("Connection error - please check your connection. Try again?", "Cancel", null, "Yes", "No");
-                switch (chosenOption)
+                Task.Run(() =>
                 {
-                    case "Yes":
-                        Task.Run(() =>
-                        {
-                            Thread.Sleep(1000);
-                            Device.BeginInvokeOnMainThread(() =>
-                            {
-                                RunValidate();
-                            });
-                        });
-                        break;
-                    default:
-                        break;
-                }
+                    Thread.Sleep(100);
+
+                    string result = "";
+                    try
+                    {
+                        result = JsonClient<User>.Ping(App.DBSettings.URLs, out DatabaseInfo info);
+                    }
+                    catch (Exception ex)
+                    {
+                        var log = new MobileLogging(LogType.BackgroundProcess, "JsonClient.Ping()", ex.Message + ex.StackTrace, this.GetType().Name);
+                        if (App.DBSettings.URLs[0].ToUpper().Contains("COM-AL"))
+                            result = "remote.com-al.com.au:8000";
+                    }
+                    try
+                    {
+                        ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + App.DeviceString, result, true);
+                    }
+                    catch (Exception ex)
+                    {
+                        var log = new MobileLogging(LogType.BackgroundProcess, "Client Factory SetClientType", ex.Message + ex.StackTrace, this.GetType().Name);
+                    }
+                    Device.BeginInvokeOnMainThread(() =>
+                    {
+                        RunValidate();
+                    });
+                });
             }
         }
 
         private async void LaunchMainPage()
         {
-            if (!App.Current.Properties.ContainsKey("SessionID"))
-                App.Current.Properties.Add("SessionID", ClientFactory.SessionID);
-            else
-                App.Current.Properties["SessionID"] = ClientFactory.SessionID;
-            if (timerRunning)
-                timer.Dispose();
+            try
+            {
+                if (!App.Current.Properties.ContainsKey("SessionID"))
+                    App.Current.Properties.Add("SessionID", ClientFactory.SessionID);
+                else
+                    App.Current.Properties["SessionID"] = ClientFactory.SessionID;
+
+                if (timerRunning)
+                    timer.Dispose();
+            }
+            catch { }
+
             App.Data.Refresh(true);
-            Device.BeginInvokeOnMainThread(async () => { await Navigation.PushAsync(new MainPage()); });
+            Device.BeginInvokeOnMainThread(() => { Navigation.PushAsync(new MainPage()); });
         }
 
         private async void Check2FA()

+ 0 - 2
prs.mobile/comal.timesheets/SettingsPage.xaml.cs

@@ -82,8 +82,6 @@ namespace comal.timesheets
                     Navigation.PopToRootAsync(true);
                     PINLoginPage pin = new PINLoginPage();
 
-                    //pin.RunValidate(testingpage:true);
-
                     Navigation.PushAsync(pin, true);
                 }
                 catch (Exception ex)