} // proc ClearCredentials public async Task <PpsLoginResult> LoginAsync(IWin32Window parent) { var newRequest = DEHttpClient.Create(info.Uri, null, Encoding); try { // get app-info var xInfo = await newRequest.GetXmlAsync("info.xml?app=" + formsApplication.ApplicationId); // check version var clientVersion = GetExcelAddinVersion(); var assemblyVesion = GetExcelAssemblyVersion(); var serverVersion = new Version(xInfo.GetAttribute("version", "1.0.0.0")); #if DEBUG assemblyVesion = serverVersion = clientVersion; #endif if (clientVersion < serverVersion) // new version is provided { return(await UpdateApplicationAsync(newRequest, xInfo.GetAttribute("src", null)) ? PpsLoginResult.Restart : PpsLoginResult.Canceled); } else if (assemblyVesion < clientVersion) // new version is installed, but not active { return(AskForRestart() ? PpsLoginResult.Restart : PpsLoginResult.Canceled); } // update mime type mappings PpsShellExtensions.UpdateMimeTypesFromInfo(xInfo); // open trust stroe using (var login = new PpsClientLogin("ppsn_env:" + info.Uri.ToString(), info.Name, false)) { var loginCounter = 0; // first time, do not show login dialog while (true) { // show login dialog if (loginCounter > 0) { if (!await InvokeAsync(() => login.ShowWindowsLogin(parent.Handle))) { return(PpsLoginResult.Canceled); } } // create new client request loginCounter++; newRequest?.Dispose(); newRequest = DEHttpClient.Create(info.Uri, login.GetCredentials(true), Encoding); // try login with user try { // execute login var xLogin = await newRequest.GetXmlAsync("login.xml"); request = newRequest; IsAuthentificatedChanged?.Invoke(this, EventArgs.Empty); fullName = xLogin.GetAttribute("FullName", (string)null); login.Commit(); return(PpsLoginResult.Sucess); } catch (HttpResponseException e) { switch (e.StatusCode) { case HttpStatusCode.Unauthorized: if (loginCounter > 1) { ShowMessage("Passwort oder Nutzername falsch."); } break; default: formsApplication.ShowMessage(String.Format("Verbindung mit fehlgeschlagen.\n{0} ({2} {1})", e.Message, e.StatusCode, (int)e.StatusCode), MessageBoxIcon.Error); return(PpsLoginResult.Canceled); } } } } } catch (HttpRequestException e) { newRequest?.Dispose(); if (e.InnerException is WebException we) { switch (we.Status) { case WebExceptionStatus.Timeout: case WebExceptionStatus.ConnectFailure: ShowMessage("Server nicht erreichbar."); return(PpsLoginResult.Canceled); } } else { ShowException(ExceptionShowFlags.None, e, "Verbindung fehlgeschlagen."); } return(PpsLoginResult.Canceled); } catch { newRequest?.Dispose(); throw; } } // func LoginAsync