|
@@ -89,41 +89,76 @@ namespace InABox.Mobile
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var s = Encryption.Decrypt(GlobalVariables.LoadFromLinkString, "logindetailslink");
|
|
|
- var index = s.IndexOf("ENDURLS");
|
|
|
- var substring = s.Substring(index + 8, s.Length - index - 8);
|
|
|
- var array = substring.Split(",");
|
|
|
- DateTime expiry = DateTime.Parse(array[2]);
|
|
|
- if (DateTime.Now.Subtract(expiry) < new TimeSpan(0, 5, 0))
|
|
|
+ var arr = GetArray();
|
|
|
+ var array = arr.Item1;
|
|
|
+ var s = arr.Item2;
|
|
|
+ if (!CheckExpiry(array))
|
|
|
{
|
|
|
- var urls = s.Substring(0, s.IndexOf("ENDURLS") - 1);
|
|
|
- App.DBSettings.URLs = urls.Split(",");
|
|
|
- App.DBSettings.UserID = array[0];
|
|
|
- App.DBSettings.Password = array[1];
|
|
|
-
|
|
|
- ClientFactory.InvalidateUser();
|
|
|
- new LocalConfiguration<DatabaseSettings>().Delete();
|
|
|
- new LocalConfiguration<DatabaseSettings>().Save(App.DBSettings);
|
|
|
- App.DBSettings = new LocalConfiguration<DatabaseSettings>().Load();
|
|
|
- GlobalVariables.ChangeUser = true;
|
|
|
- if (App.Current.Properties.ContainsKey("SessionID"))
|
|
|
- App.Current.Properties.Remove("SessionID");
|
|
|
- MobileUtils.SaveToSecureStorage();
|
|
|
-
|
|
|
- var result = JsonClient<User>.Ping(App.DBSettings.URLs, out DatabaseInfo info);
|
|
|
-
|
|
|
- ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + App.DeviceString, result, true);
|
|
|
- }
|
|
|
- else
|
|
|
GlobalVariables.LoadFromLinkString = "Link has expired";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ SetDBSettings(array, s);
|
|
|
+ SaveSettings();
|
|
|
+ RemoveSessionID();
|
|
|
+ PingAndSetClient();
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- if (String.IsNullOrWhiteSpace(App.Settings.URL))
|
|
|
+ if (String.IsNullOrWhiteSpace(App.DBSettings.URLs[0]))
|
|
|
LoadDemoSettings(App.DBSettings);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static void PingAndSetClient()
|
|
|
+ {
|
|
|
+ var result = JsonClient<User>.Ping(App.DBSettings.URLs, out DatabaseInfo info);
|
|
|
+
|
|
|
+ ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + App.DeviceString, result, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Tuple<string[], string> GetArray()
|
|
|
+ {
|
|
|
+ var s = Encryption.Decrypt(GlobalVariables.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>().Delete();
|
|
|
+ new LocalConfiguration<DatabaseSettings>().Save(App.DBSettings);
|
|
|
+ App.DBSettings = new LocalConfiguration<DatabaseSettings>().Load();
|
|
|
+ GlobalVariables.ChangeUser = true;
|
|
|
+
|
|
|
+ SaveToSecureStorage();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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>();
|