private void OnLogin() { Validate(); if (HasErrors) { return; } IsBusy = true; BusyContent = Strings.Common_Loading; var successed = false; string logmsg = ""; Task.Run(() => { bool ok = Enum.TryParse(SelectedApiVersion, true, out ApiVersion apiVersion); if (ok || apiVersion == ApiVersion.AutoDiscovery) { var arys = new ApiVersion[] { ApiVersion.V4_Oauth, ApiVersion.V4, ApiVersion.V3_Oauth, ApiVersion.V3, ApiVersion.V3_1 }; foreach (var apiv in arys) { try { BusyContent = Strings.Trying + apiv.ToString(); var user = _web.LoginAsync(Enable2FA, Host, Email, Password, apiv); if (user != null) { BusyContent = null; successed = true; user.Host = Host; _storage.AddHostVersionInfo(Host, apiv); break; } } catch (Exception ex) { BusyContent = ex.Message; logmsg += apiv.ToString() + ":" + ex.Message + Environment.NewLine; } } } }).ContinueWith(task => { IsBusy = false; BusyContent = null; if (successed) { _dialog.Close(); _messenger.Send("OnLogined"); } else { _dialog.Warning(Strings.Login_FailedToLogin + Environment.NewLine + Strings.PleaseCheckYourUsernameOrPassword + Environment.NewLine + logmsg); } }, TaskScheduler.FromCurrentSynchronizationContext()).Forget(); }