Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public class NancyContextAccountAccessor : IAccountAccessor {
  2. static readonly ILog _log = LogProvider.For<NancyContextAccountAccessor>();
  3.  
  4. readonly IAccountRepository _accountRepository;
  5. readonly NancyContext _nancyContext;
  6.  
  7. public NancyContextAccountAccessor(IAccountRepository accountRepository, NancyContext nancyContext) {
  8. _accountRepository = accountRepository;
  9. _nancyContext = nancyContext;
  10. }
  11.  
  12. public Account GetCurrentAccount() {
  13. var hostName = _nancyContext.Request.Url.HostName;
  14. _log.DebugFormat("Hostname resolved from nancy context `{hostName}`", hostName);
  15. var account = _accountRepository.GetFirst(x => x.Hostname.ToLower() == hostName);
  16. if (account == null) {
  17. _log.WarnFormat("Account was not found in the system for `{hostName}`", hostName);
  18. throw new UnknownAccountException(3, string.Format("Hostname: {0} has not been registered.", hostName));
  19. }
  20. return account;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement