public void EnsureAuthenticated() { if (_lastLogin.HasValue && _lastLogin.Value > DateTime.Now.AddMinutes(-10)) { return; } lock (_lockObject) { if (_lastLogin.HasValue && _lastLogin.Value > DateTime.Now.AddMinutes(-10)) { return; } var credentials = _bricklinkCredentialProvider.GetCredentials(); var wasLoggedIn = _bricklinkLoginApi.Login(_cookies, credentials.UserName, credentials.Password); if (wasLoggedIn) { _lastLogin = DateTime.Now; return; } throw new Exception("Unable to log in to Bricklink"); } }
public bool ValidateCredential(ExternalSystem system, NetworkCredential credential) { switch (system) { case ExternalSystem.Bricklink: return(_bricklinkLoginApi.Login(new CookieContainer(), credential.UserName, credential.Password)); default: throw new NotSupportedException(string.Format("The system {0} is not supported", system)); } }