- 
                Notifications
    You must be signed in to change notification settings 
- Fork 316
Remove Diagnostic Source + Configuration Manager from .NET Standard DLL as it's not supported #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            cheenamalhotra
  merged 11 commits into
  dotnet:master
from
cheenamalhotra:DiagnosticSource
  
      
      
   
  Apr 30, 2020 
      
    
  
     Merged
                    Changes from 5 commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      57e04bb
              
                Remove Diagnostic Source from .NET Standard DLL as it's not supported
              
              
                cheenamalhotra cf12b2f
              
                Merge branch 'master' into DiagnosticSource
              
              
                cheenamalhotra 80249ac
              
                Remove dependency on Configuration Manager for .NET Standard
              
              
                cheenamalhotra fc9d5f7
              
                Rename file
              
              
                cheenamalhotra 5030f43
              
                Add header to file
              
              
                cheenamalhotra 24ce823
              
                Improvements
              
              
                cheenamalhotra 91a1f15
              
                Fix spaces
              
              
                cheenamalhotra c74e16d
              
                Merge branch 'master' into DiagnosticSource
              
              
                cheenamalhotra 8f9d83a
              
                Address review feedback
              
              
                cheenamalhotra f812e34
              
                Address review feedback
              
              
                cheenamalhotra 3ee4e09
              
                Remove unnecessary parameter (NetFx)
              
              
                cheenamalhotra File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            114 changes: 114 additions & 0 deletions
          
          114 
        
  ...lient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.NetCoreApp.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|  | ||
| using System; | ||
| using System.Collections.Concurrent; | ||
| using System.Collections.Generic; | ||
| using System.Configuration; | ||
|  | ||
| namespace Microsoft.Data.SqlClient | ||
| { | ||
| internal partial class SqlAuthenticationProviderManager | ||
| { | ||
| private readonly SqlAuthenticationInitializer _initializer; | ||
|  | ||
| /// <summary> | ||
| /// Constructor. | ||
| /// </summary> | ||
| public SqlAuthenticationProviderManager(SqlAuthenticationProviderConfigurationSection configSection = null) | ||
| { | ||
| var methodName = "Ctor"; | ||
| _typeName = GetType().Name; | ||
| _providers = new ConcurrentDictionary<SqlAuthenticationMethod, SqlAuthenticationProvider>(); | ||
| var authenticationsWithAppSpecifiedProvider = new HashSet<SqlAuthenticationMethod>(); | ||
| _authenticationsWithAppSpecifiedProvider = authenticationsWithAppSpecifiedProvider; | ||
|  | ||
| if (configSection == null) | ||
| { | ||
| _sqlAuthLogger.LogInfo(_typeName, methodName, "No SqlAuthProviders configuration section found."); | ||
| return; | ||
| } | ||
|  | ||
| // Create user-defined auth initializer, if any. | ||
| if (!string.IsNullOrEmpty(configSection.InitializerType)) | ||
| { | ||
| try | ||
| { | ||
| var initializerType = Type.GetType(configSection.InitializerType, true); | ||
| _initializer = (SqlAuthenticationInitializer)Activator.CreateInstance(initializerType); | ||
| _initializer.Initialize(); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| throw SQL.CannotCreateSqlAuthInitializer(configSection.InitializerType, e); | ||
| } | ||
| _sqlAuthLogger.LogInfo(_typeName, methodName, "Created user-defined SqlAuthenticationInitializer."); | ||
| } | ||
| else | ||
| { | ||
| _sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined SqlAuthenticationInitializer found."); | ||
| } | ||
|  | ||
| // add user-defined providers, if any. | ||
| if (configSection.Providers != null && configSection.Providers.Count > 0) | ||
| { | ||
| foreach (ProviderSettings providerSettings in configSection.Providers) | ||
| { | ||
| SqlAuthenticationMethod authentication = AuthenticationEnumFromString(providerSettings.Name); | ||
| SqlAuthenticationProvider provider; | ||
| try | ||
| { | ||
| var providerType = Type.GetType(providerSettings.Type, true); | ||
| provider = (SqlAuthenticationProvider)Activator.CreateInstance(providerType); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| throw SQL.CannotCreateAuthProvider(authentication.ToString(), providerSettings.Type, e); | ||
| } | ||
| if (!provider.IsSupported(authentication)) | ||
| throw SQL.UnsupportedAuthenticationByProvider(authentication.ToString(), providerSettings.Type); | ||
|  | ||
| _providers[authentication] = provider; | ||
| authenticationsWithAppSpecifiedProvider.Add(authentication); | ||
| _sqlAuthLogger.LogInfo(_typeName, methodName, string.Format("Added user-defined auth provider: {0} for authentication {1}.", providerSettings?.Type, authentication)); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| _sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined auth providers."); | ||
| } | ||
| } | ||
|  | ||
| private static SqlAuthenticationMethod AuthenticationEnumFromString(string authentication) | ||
| { | ||
| switch (authentication.ToLowerInvariant()) | ||
| { | ||
| case ActiveDirectoryPassword: | ||
| return SqlAuthenticationMethod.ActiveDirectoryPassword; | ||
| default: | ||
| throw SQL.UnsupportedAuthentication(authentication); | ||
| } | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// The configuration section definition for reading app.config. | ||
| /// </summary> | ||
| internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSection | ||
| { | ||
| public const string Name = "SqlAuthenticationProviders"; | ||
|  | ||
| /// <summary> | ||
| /// User-defined auth providers. | ||
| /// </summary> | ||
| [ConfigurationProperty("providers")] | ||
| public ProviderSettingsCollection Providers => (ProviderSettingsCollection)base["providers"]; | ||
|  | ||
| /// <summary> | ||
| /// User-defined initializer. | ||
| /// </summary> | ||
| [ConfigurationProperty("initializerType")] | ||
| public string InitializerType => base["initializerType"] as string; | ||
| } | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.