Ejemplo n.º 1
0
        public async Task<bool> Login(string baseUrl, 
                                      string userName, 
                                      string password,
                                      CancellationToken cancelToken)
        {
            Trace_n($"Logging in as “{userName}”...", "server: " + baseUrl);

            _client.BaseUrl = baseUrl;
            if (this.IsLoggedIn) goto FireLoggedIn;


            try {
                await _auth.OpenNewSession(_client, userName, password, cancelToken);
            }
            catch (RestServiceException ex) { OnLogin.Err(this, ex); }
            catch (Exception ex) { OnUnhandled.Err(this, ex); }
            if (!IsLoggedIn) return Error_n("Failed to authenticate!", "");

        FireLoggedIn:
            _loggedIn?.Invoke(this, EventArg.User(userName));
            return true;//Trace_n("Successfully logged in.", "");
        }