|
@@ -58,111 +58,14 @@ namespace InABox.Mobile
|
|
|
|
|
|
public static IAppVersion AppVersion { get { return DependencyService.Get<IAppVersion>(); } }
|
|
|
|
|
|
- public static void LoadFromLink()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- var arr = GetArray();
|
|
|
- var array = arr.Item1;
|
|
|
- var s = arr.Item2;
|
|
|
- if (!CheckExpiry(array))
|
|
|
- {
|
|
|
- App.Data.LoadFromLinkString = "Link has expired";
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- SetDBSettings(array, s);
|
|
|
- SaveSettings();
|
|
|
- RemoveSessionID();
|
|
|
-
|
|
|
- SetupClient();
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- if (String.IsNullOrWhiteSpace(App.DBSettings.URLs[0]))
|
|
|
- LoadDemoSettings(App.DBSettings);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static IRpcClientTransport Transport { get; private set; }
|
|
|
|
|
|
- public static bool SetupClient()
|
|
|
- {
|
|
|
- if (!App.DBSettings.URLs.Any())
|
|
|
- return false;
|
|
|
-
|
|
|
- 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(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);
|
|
|
- }
|
|
|
-
|
|
|
- private static bool CheckExpiry(string[] array)
|
|
|
- {
|
|
|
- DateTime expiry = DateTime.Parse(array[2]);
|
|
|
- if (DateTime.Now.Subtract(expiry) < new TimeSpan(0, 5, 0))
|
|
|
- return true;
|
|
|
- else
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- private static void SetDBSettings(string[] array, string s)
|
|
|
- {
|
|
|
- var urls = s.Substring(0, s.IndexOf("ENDURLS") - 1);
|
|
|
- App.DBSettings.URLs = urls.Split(",");
|
|
|
- App.DBSettings.UserID = array[0];
|
|
|
- App.DBSettings.Password = array[1];
|
|
|
- }
|
|
|
-
|
|
|
- private static void SaveSettings()
|
|
|
- {
|
|
|
- ClientFactory.InvalidateUser();
|
|
|
- new LocalConfiguration<DatabaseSettings>().Save(App.DBSettings);
|
|
|
- App.Data.ChangeUser = true;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
private static void RemoveSessionID()
|
|
|
{
|
|
|
if (App.Current.Properties.ContainsKey("SessionID"))
|
|
|
App.Current.Properties.Remove("SessionID");
|
|
|
}
|
|
|
|
|
|
- public static void LoadDemoSettings(DatabaseSettings settings)
|
|
|
- {
|
|
|
- List<string> list = new List<string>();
|
|
|
- list.Add("http://demo.prsdigital.com.au:8003");
|
|
|
- list.Add("http://demo2.prsdigital.com.au:8003");
|
|
|
- list.Add("http://demo3.prsdigital.com.au:8003");
|
|
|
- settings.URLs = list.ToArray();
|
|
|
- settings.UserID = "GUEST";
|
|
|
- settings.Password = "guest";
|
|
|
- }
|
|
|
|
|
|
|
|
|
private static async Task<bool> Retry(Func<Task<bool>> action, int interval, int retryCount = 3)
|