private AuthenticationContext GetContext(IKeyValueSettings settings, out string serviceId, out string clientId, out string authority) { // Valdate arguments. if (!settings.Values.ContainsKey(TokenKeys.AuthorityKey)) { throw new ArgumentException("Authority is missing. Cannot process the request."); } if (!settings.Values.ContainsKey(TokenKeys.ClientIdKey)) { throw new ArgumentException("ClientId is missing. Cannot process the request."); } if (!settings.Values.ContainsKey(TokenKeys.ServiceApplicationIdKey)) { throw new ArgumentException("ApplicationId is missing. Cannot process the request."); } Logger.Technical().From <AdalTokenProvider>().System($"Creating an authentication context for the request.").Log(); clientId = settings.Values[TokenKeys.ClientIdKey]; serviceId = settings.Values[TokenKeys.ServiceApplicationIdKey]; authority = settings.Values[TokenKeys.AuthorityKey]; // Check the information. var messages = new ServiceModel.Messages(); if (String.IsNullOrWhiteSpace(clientId)) { messages.Add(new Message(ServiceModel.MessageCategory.Technical, ServiceModel.MessageType.Warning, $"{TokenKeys.ClientIdKey} is not defined in the configuration file.")); } else { Logger.Technical().From <AdalTokenProvider>().System($"{TokenKeys.ClientIdKey} = {clientId}.").Log(); } if (String.IsNullOrWhiteSpace(serviceId)) { messages.Add(new Message(ServiceModel.MessageCategory.Technical, ServiceModel.MessageType.Warning, $"No information from the application settings section about an entry: {TokenKeys.ServiceApplicationIdKey}.")); } if (String.IsNullOrWhiteSpace(authority)) { messages.Add(new Message(ServiceModel.MessageCategory.Technical, ServiceModel.MessageType.Warning, $"{TokenKeys.AuthorityKey} is not defined in the configuration file.")); } else { Logger.Technical().From <AdalTokenProvider>().System($"{TokenKeys.AuthorityKey} = {authority}.").Log(); } messages.LogAndThrowIfNecessary(typeof(AdalTokenProvider)); messages.Clear(); // The cache is per user on the device and Application. var authContext = CreateAuthenticationContext(authority, serviceId); Logger.Technical().From <AdalTokenProvider>().System("Authentication context is created.").Log(); return(authContext); }
public static void ValidateAll <T>(this IEnumerable <T> entities) where T : PersistEntity { var messages = new ServiceModel.Messages(); foreach (var entity in entities) { messages.AddRange(entity.TryValidate()); } messages.LogAndThrowIfNecessary(typeof(ValidationExtention)); }