private void LogInToCompany(CorrigoService service, string companyName, string userName, string password) { var loginStatus = service.LogInStatus() as LoginResponse; var needLogIn = !loginStatus?.Success ?? true; if (needLogIn) { var logIn = service.LogInCompany(userName, password, companyName) as LoginResponse; if (!logIn?.Success ?? true) { throw new Exception($"Cannot log into company {companyName} as {userName} with {password}." + $" Using URL: {service.Url}"); } } }