|
@@ -1,17 +1,12 @@
|
|
|
using System;
|
|
|
using System.Linq;
|
|
|
-using System.Net;
|
|
|
-using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Collections.Generic;
|
|
|
-
|
|
|
+using System.Threading;
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
-using RestSharp;
|
|
|
using Plugin.Permissions;
|
|
|
using Plugin.Permissions.Abstractions;
|
|
|
-
|
|
|
-using Syncfusion.Licensing;
|
|
|
using comal.timesheets;
|
|
|
using Xamarin.Essentials;
|
|
|
using PermissionStatus = Plugin.Permissions.Abstractions.PermissionStatus;
|
|
@@ -19,6 +14,7 @@ using InABox.Core;
|
|
|
using InABox.Clients;
|
|
|
using InABox.Configuration;
|
|
|
using Comal.Classes;
|
|
|
+using InABox.Rpc;
|
|
|
|
|
|
namespace InABox.Mobile
|
|
|
{
|
|
@@ -61,30 +57,7 @@ namespace InABox.Mobile
|
|
|
}
|
|
|
|
|
|
public static IAppVersion AppVersion { get { return DependencyService.Get<IAppVersion>(); } }
|
|
|
-
|
|
|
- public static void SaveToSecureStorage()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (!string.IsNullOrWhiteSpace(App.Settings.UserID))
|
|
|
- SecureStorage.SetAsync(GlobalVariables.CacheUserIDString, App.Settings.UserID);
|
|
|
-
|
|
|
- if (!string.IsNullOrWhiteSpace(App.Settings.Password))
|
|
|
- SecureStorage.SetAsync(GlobalVariables.CachePasswordString, App.Settings.Password);
|
|
|
-
|
|
|
- if (App.DBSettings.URLs.Count() > 0)
|
|
|
- {
|
|
|
- int count = 0;
|
|
|
- foreach (string url in App.DBSettings.URLs)
|
|
|
- {
|
|
|
- SecureStorage.SetAsync(GlobalVariables.CacheSettingsURL + count, url);
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch { }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
public static void LoadFromLink()
|
|
|
{
|
|
|
try
|
|
@@ -94,14 +67,16 @@ namespace InABox.Mobile
|
|
|
var s = arr.Item2;
|
|
|
if (!CheckExpiry(array))
|
|
|
{
|
|
|
- GlobalVariables.LoadFromLinkString = "Link has expired";
|
|
|
+ App.Data.LoadFromLinkString = "Link has expired";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
SetDBSettings(array, s);
|
|
|
SaveSettings();
|
|
|
RemoveSessionID();
|
|
|
- PingAndSetClient();
|
|
|
+
|
|
|
+ SetupClient();
|
|
|
+
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
@@ -109,17 +84,40 @@ namespace InABox.Mobile
|
|
|
LoadDemoSettings(App.DBSettings);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private static void PingAndSetClient()
|
|
|
+
|
|
|
+ public static IRpcClientTransport Transport { get; private set; }
|
|
|
+
|
|
|
+ public static bool SetupClient()
|
|
|
{
|
|
|
- var result = RestClient<User>.Ping(App.DBSettings.URLs, out DatabaseInfo info);
|
|
|
+ if (!App.DBSettings.URLs.Any())
|
|
|
+ return false;
|
|
|
|
|
|
- ClientFactory.SetClientType(typeof(RestClient<>), InABox.Core.Platform.Mobile, MobileUtils.AppVersion.InstalledVersionNumber + App.DeviceString, result, true);
|
|
|
+ List<Task<String>> pings = new List<Task<String?>>();
|
|
|
+ foreach (var url in App.DBSettings.URLs)
|
|
|
+ pings.Add(Task.Run<String?>(() =>
|
|
|
+ {
|
|
|
+ int iRetry = 0;
|
|
|
+ while (!new RpcClientSocketTransport(url).Ping() && (iRetry < 10))
|
|
|
+ {
|
|
|
+ Thread.Sleep(1000);
|
|
|
+ iRetry++;
|
|
|
+ }
|
|
|
+ return iRetry < 10 ? url : "";
|
|
|
+ }));
|
|
|
+ var index = Task.WaitAny(pings.ToArray<Task>());
|
|
|
+ var result = pings[index].Result;
|
|
|
+
|
|
|
+ if (String.IsNullOrWhiteSpace(result))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ Transport = new RpcClientSocketTransport(result);
|
|
|
+ ClientFactory.SetClientType(typeof(RpcClient<>), InABox.Core.Platform.TimeBench, MobileUtils.AppVersion.InstalledVersionNumber + App.Data.DeviceString, Transport);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
private static Tuple<string[], string> GetArray()
|
|
|
{
|
|
|
- var s = Encryption.Decrypt(GlobalVariables.LoadFromLinkString, "logindetailslink");
|
|
|
+ var s = Encryption.Decrypt(App.Data.LoadFromLinkString, "logindetailslink");
|
|
|
var index = s.IndexOf("ENDURLS");
|
|
|
var substring = s.Substring(index + 8, s.Length - index - 8);
|
|
|
return new Tuple<string[], string>(substring.Split(","), s);
|
|
@@ -145,12 +143,8 @@ namespace InABox.Mobile
|
|
|
private static void SaveSettings()
|
|
|
{
|
|
|
ClientFactory.InvalidateUser();
|
|
|
- new LocalConfiguration<DatabaseSettings>().Delete();
|
|
|
new LocalConfiguration<DatabaseSettings>().Save(App.DBSettings);
|
|
|
- App.DBSettings = new LocalConfiguration<DatabaseSettings>().Load();
|
|
|
- GlobalVariables.ChangeUser = true;
|
|
|
-
|
|
|
- SaveToSecureStorage();
|
|
|
+ App.Data.ChangeUser = true;
|
|
|
}
|
|
|
|
|
|
private static void RemoveSessionID()
|
|
@@ -302,6 +296,6 @@ namespace InABox.Mobile
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|