diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..1483f4e861 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,158 @@ +# editorconfig.org + +# top-most EditorConfig file +root = true + +# Default settings: +# A newline ending every file +# Use 4 spaces as indentation +[*] +insert_final_newline = true +indent_style = space +indent_size = 4 + +[project.json] +indent_size = 2 + +# C# files +[*.cs] +# New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = one_less_than_current + +# avoid this. unless absolutely necessary +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion + +# only use var when it's obvious what the variable type is +csharp_style_var_for_built_in_types = false:none +csharp_style_var_when_type_is_apparent = false:none +csharp_style_var_elsewhere = false:suggestion + +# use language keywords instead of BCL types +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# name all constant fields using PascalCase +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style + +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const + +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# static fields should have s_ prefix +dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion +dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style + +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static + +dotnet_naming_style.static_prefix_style.required_prefix = s_ +dotnet_naming_style.static_prefix_style.capitalization = camel_case + +# internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style + +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal + +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +# Code style defaults +dotnet_sort_system_directives_first = true +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = false + +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_methods = false:none +csharp_style_expression_bodied_constructors = false:none +csharp_style_expression_bodied_operators = false:none +csharp_style_expression_bodied_properties = true:none +csharp_style_expression_bodied_indexers = true:none +csharp_style_expression_bodied_accessors = true:none + +# Pattern matching +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion + +# Null checking preferences +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = do_not_ignore +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Xml project files +[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] +indent_size = 2 + +# Xml build files +[*.builds] +indent_size = 2 + +# Xml files +[*.{xml,stylecop,resx,ruleset}] +indent_size = 2 + +# Xml config files +[*.{props,targets,config,nuspec}] +indent_size = 2 + +# Shell scripts +[*.sh] +end_of_line = lf +[*.{cmd, bat}] +end_of_line = crlf + +# Analyzers +dotnet_code_quality.ca1802.api_surface = private, internal diff --git a/.gitignore b/.gitignore index 62e4e8f2e1..4794a6e136 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ +.nuget/ # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/src/Directory.Build.props b/src/Directory.Build.props index b8878c0503..da8678358f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -11,7 +11,9 @@ true true - + + $(DefineConstants);DEBUG + $(MSBuildThisFileDirectory) $(ProjectDir)..\ diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.Manual.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.Manual.cs index 79bf00c58a..0519992f61 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.Manual.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.Manual.cs @@ -19,4 +19,4 @@ public sealed partial class SqlParameter { internal class SqlParameterConverter { } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.NetCoreApp.cs index d2329e7e10..eef032209c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.NetCoreApp.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.NetCoreApp.cs @@ -143,4 +143,4 @@ public override void Flush() { } public override void SetLength(long value) { throw null; } public override void Write(byte[] buffer, int offset, int count) { throw null; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index 6c216643a1..dbf0cfe197 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -1081,4 +1081,4 @@ public SensitivityProperty(Microsoft.Data.SqlClient.DataClassification.Label lab public Microsoft.Data.SqlClient.DataClassification.InformationType InformationType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } public Microsoft.Data.SqlClient.DataClassification.Label Label { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/NegotiationInfoClass.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/NegotiationInfoClass.cs index ea6a7d6fb5..f5f7ab1b07 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/NegotiationInfoClass.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/NegotiationInfoClass.cs @@ -16,12 +16,14 @@ internal NegotiationInfoClass(SafeHandle safeHandle, int negotiationState) { if (safeHandle.IsInvalid) { - if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Invalid handle:{safeHandle}"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, $"Invalid handle:{safeHandle}"); return; } IntPtr packageInfo = safeHandle.DangerousGetHandle(); - if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x}"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x}"); if (negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_COMPLETE || negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_OPTIMISTIC) @@ -30,14 +32,15 @@ internal NegotiationInfoClass(SafeHandle safeHandle, int negotiationState) unsafe { - IntPtr unmanagedString = ((SecurityPackageInfo *)packageInfo)->Name; + IntPtr unmanagedString = ((SecurityPackageInfo*)packageInfo)->Name; if (unmanagedString != IntPtr.Zero) { name = Marshal.PtrToStringUni(unmanagedString); } } - if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x} name:{name}"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x} name:{name}"); // An optimization for future string comparisons. if (string.Equals(name, Kerberos, StringComparison.OrdinalIgnoreCase)) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIAuthType.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIAuthType.cs index 20b7f6746a..8855379df7 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIAuthType.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIAuthType.cs @@ -27,7 +27,8 @@ public SecurityPackageInfoClass[] SecurityPackages public int EnumerateSecurityPackages(out int pkgnum, out SafeFreeContextBuffer pkgArray) { - if (NetEventSource.IsEnabled) NetEventSource.Info(this); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this); return SafeFreeContextBuffer.EnumeratePackages(out pkgnum, out pkgArray); } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPISecureChannelType.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPISecureChannelType.cs index dc3cc16b1c..c46f602221 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPISecureChannelType.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPISecureChannelType.cs @@ -26,7 +26,8 @@ public SecurityPackageInfoClass[] SecurityPackages public int EnumerateSecurityPackages(out int pkgnum, out SafeFreeContextBuffer pkgArray) { - if (NetEventSource.IsEnabled) NetEventSource.Info(this); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this); return SafeFreeContextBuffer.EnumeratePackages(out pkgnum, out pkgArray); } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIWrapper.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIWrapper.cs index c841556692..3e31c0c845 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIWrapper.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIWrapper.cs @@ -13,7 +13,8 @@ internal static class SSPIWrapper { internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(SSPIInterface secModule) { - if (NetEventSource.IsEnabled) NetEventSource.Enter(null); + if (NetEventSource.IsEnabled) + NetEventSource.Enter(null); if (secModule.SecurityPackages == null) { @@ -26,7 +27,8 @@ internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(SSPIInterfa try { int errorCode = secModule.EnumerateSecurityPackages(out moduleCount, out arrayBaseHandle); - if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"arrayBase: {arrayBaseHandle}"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(null, $"arrayBase: {arrayBaseHandle}"); if (errorCode != 0) { throw new Win32Exception(errorCode); @@ -38,7 +40,8 @@ internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(SSPIInterfa for (i = 0; i < moduleCount; i++) { securityPackages[i] = new SecurityPackageInfoClass(arrayBaseHandle, i); - if (NetEventSource.IsEnabled) NetEventSource.Log.EnumerateSecurityPackages(securityPackages[i].Name); + if (NetEventSource.IsEnabled) + NetEventSource.Log.EnumerateSecurityPackages(securityPackages[i].Name); } secModule.SecurityPackages = securityPackages; @@ -54,7 +57,8 @@ internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(SSPIInterfa } } - if (NetEventSource.IsEnabled) NetEventSource.Exit(null); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null); return secModule.SecurityPackages; } @@ -72,7 +76,8 @@ internal static SecurityPackageInfoClass GetVerifyPackageInfo(SSPIInterface secM } } - if (NetEventSource.IsEnabled) NetEventSource.Log.SspiPackageNotFound(packageName); + if (NetEventSource.IsEnabled) + NetEventSource.Log.SspiPackageNotFound(packageName); if (throwIfMissing) { @@ -95,7 +100,8 @@ public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface secModu if (errorCode != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, System.SRHelper.Format(SR.net_log_operation_failed_with_error, nameof(AcquireDefaultCredential), $"0x{errorCode:X}")); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, System.SRHelper.Format(SR.net_log_operation_failed_with_error, nameof(AcquireDefaultCredential), $"0x{errorCode:X}")); throw new Win32Exception(errorCode); } return outCredential; @@ -103,14 +109,16 @@ public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface secModu public static SafeFreeCredentials AcquireCredentialsHandle(SSPIInterface secModule, string package, Interop.SspiCli.CredentialUse intent, ref SafeSspiAuthDataHandle authdata) { - if (NetEventSource.IsEnabled) NetEventSource.Log.AcquireCredentialsHandle(package, intent, authdata); + if (NetEventSource.IsEnabled) + NetEventSource.Log.AcquireCredentialsHandle(package, intent, authdata); SafeFreeCredentials credentialsHandle = null; int errorCode = secModule.AcquireCredentialsHandle(package, intent, ref authdata, out credentialsHandle); if (errorCode != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, System.SRHelper.Format(SR.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}")); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, System.SRHelper.Format(SR.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}")); throw new Win32Exception(errorCode); } @@ -134,43 +142,51 @@ public static SafeFreeCredentials AcquireCredentialsHandle(SSPIInterface secModu if (errorCode != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, System.SRHelper.Format(SR.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}")); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, System.SRHelper.Format(SR.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}")); throw new Win32Exception(errorCode); } - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, outCredential); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, outCredential); return outCredential; } internal static int InitializeSecurityContext(SSPIInterface secModule, ref SafeFreeCredentials credential, ref SafeDeleteContext context, string targetName, Interop.SspiCli.ContextFlags inFlags, Interop.SspiCli.Endianness datarep, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, ref Interop.SspiCli.ContextFlags outFlags) { - if (NetEventSource.IsEnabled) NetEventSource.Log.InitializeSecurityContext(credential, context, targetName, inFlags); + if (NetEventSource.IsEnabled) + NetEventSource.Log.InitializeSecurityContext(credential, context, targetName, inFlags); int errorCode = secModule.InitializeSecurityContext(ref credential, ref context, targetName, inFlags, datarep, inputBuffer, outputBuffer, ref outFlags); - if (NetEventSource.IsEnabled) NetEventSource.Log.SecurityContextInputBuffer(nameof(InitializeSecurityContext), inputBuffer?.size ?? 0, outputBuffer.size, (Interop.SECURITY_STATUS)errorCode); + if (NetEventSource.IsEnabled) + NetEventSource.Log.SecurityContextInputBuffer(nameof(InitializeSecurityContext), inputBuffer?.size ?? 0, outputBuffer.size, (Interop.SECURITY_STATUS)errorCode); return errorCode; } internal static int InitializeSecurityContext(SSPIInterface secModule, SafeFreeCredentials credential, ref SafeDeleteContext context, string targetName, Interop.SspiCli.ContextFlags inFlags, Interop.SspiCli.Endianness datarep, SecurityBuffer[] inputBuffers, SecurityBuffer outputBuffer, ref Interop.SspiCli.ContextFlags outFlags) { - if (NetEventSource.IsEnabled) NetEventSource.Log.InitializeSecurityContext(credential, context, targetName, inFlags); + if (NetEventSource.IsEnabled) + NetEventSource.Log.InitializeSecurityContext(credential, context, targetName, inFlags); int errorCode = secModule.InitializeSecurityContext(credential, ref context, targetName, inFlags, datarep, inputBuffers, outputBuffer, ref outFlags); - if (NetEventSource.IsEnabled) NetEventSource.Log.SecurityContextInputBuffers(nameof(InitializeSecurityContext), inputBuffers?.Length ?? 0, outputBuffer.size, (Interop.SECURITY_STATUS)errorCode); + if (NetEventSource.IsEnabled) + NetEventSource.Log.SecurityContextInputBuffers(nameof(InitializeSecurityContext), inputBuffers?.Length ?? 0, outputBuffer.size, (Interop.SECURITY_STATUS)errorCode); return errorCode; } internal static int AcceptSecurityContext(SSPIInterface secModule, SafeFreeCredentials credential, ref SafeDeleteContext context, Interop.SspiCli.ContextFlags inFlags, Interop.SspiCli.Endianness datarep, SecurityBuffer[] inputBuffers, SecurityBuffer outputBuffer, ref Interop.SspiCli.ContextFlags outFlags) { - if (NetEventSource.IsEnabled) NetEventSource.Log.AcceptSecurityContext(credential, context, inFlags); + if (NetEventSource.IsEnabled) + NetEventSource.Log.AcceptSecurityContext(credential, context, inFlags); int errorCode = secModule.AcceptSecurityContext(credential, ref context, inputBuffers, inFlags, datarep, outputBuffer, ref outFlags); - if (NetEventSource.IsEnabled) NetEventSource.Log.SecurityContextInputBuffers(nameof(AcceptSecurityContext), inputBuffers?.Length ?? 0, outputBuffer.size, (Interop.SECURITY_STATUS)errorCode); + if (NetEventSource.IsEnabled) + NetEventSource.Log.SecurityContextInputBuffers(nameof(AcceptSecurityContext), inputBuffers?.Length ?? 0, outputBuffer.size, (Interop.SECURITY_STATUS)errorCode); return errorCode; } @@ -179,7 +195,8 @@ internal static int CompleteAuthToken(SSPIInterface secModule, ref SafeDeleteCon { int errorCode = secModule.CompleteAuthToken(ref context, inputBuffers); - if (NetEventSource.IsEnabled) NetEventSource.Log.OperationReturnedSomething(nameof(CompleteAuthToken), (Interop.SECURITY_STATUS)errorCode); + if (NetEventSource.IsEnabled) + NetEventSource.Log.OperationReturnedSomething(nameof(CompleteAuthToken), (Interop.SECURITY_STATUS)errorCode); return errorCode; } @@ -188,7 +205,8 @@ internal static int ApplyControlToken(SSPIInterface secModule, ref SafeDeleteCon { int errorCode = secModule.ApplyControlToken(ref context, inputBuffers); - if (NetEventSource.IsEnabled) NetEventSource.Log.OperationReturnedSomething(nameof(ApplyControlToken), (Interop.SECURITY_STATUS)errorCode); + if (NetEventSource.IsEnabled) + NetEventSource.Log.OperationReturnedSomething(nameof(ApplyControlToken), (Interop.SECURITY_STATUS)errorCode); return errorCode; } @@ -366,17 +384,20 @@ private static unsafe int EncryptDecryptHelper(OP op, SSPIInterface secModule, S public static SafeFreeContextBufferChannelBinding QueryContextChannelBinding(SSPIInterface secModule, SafeDeleteContext securityContext, Interop.SspiCli.ContextAttribute contextAttribute) { - if (NetEventSource.IsEnabled) NetEventSource.Enter(null, contextAttribute); + if (NetEventSource.IsEnabled) + NetEventSource.Enter(null, contextAttribute); SafeFreeContextBufferChannelBinding result; int errorCode = secModule.QueryContextChannelBinding(securityContext, contextAttribute, out result); if (errorCode != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}"); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}"); return null; } - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, result); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, result); return result; } @@ -388,7 +409,8 @@ public static object QueryContextAttributes(SSPIInterface secModule, SafeDeleteC public static object QueryContextAttributes(SSPIInterface secModule, SafeDeleteContext securityContext, Interop.SspiCli.ContextAttribute contextAttribute, out int errorCode) { - if (NetEventSource.IsEnabled) NetEventSource.Enter(null, contextAttribute); + if (NetEventSource.IsEnabled) + NetEventSource.Enter(null, contextAttribute); int nativeBlockSize = IntPtr.Size; Type handleType = null; @@ -456,7 +478,8 @@ public static object QueryContextAttributes(SSPIInterface secModule, SafeDeleteC errorCode = secModule.QueryContextAttributes(securityContext, contextAttribute, nativeBuffer, handleType, out sspiHandle); if (errorCode != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}"); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}"); return null; } @@ -511,7 +534,7 @@ public static object QueryContextAttributes(SSPIInterface secModule, SafeDeleteC case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_APPLICATION_PROTOCOL: unsafe { - fixed (void *ptr = nativeBuffer) + fixed (void* ptr = nativeBuffer) { attribute = Marshal.PtrToStructure(new IntPtr(ptr)); } @@ -531,7 +554,8 @@ public static object QueryContextAttributes(SSPIInterface secModule, SafeDeleteC } } - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, attribute); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, attribute); return attribute; } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SecurityPackageInfoClass.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SecurityPackageInfoClass.cs index cf10092e68..74fca62e89 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SecurityPackageInfoClass.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SecurityPackageInfoClass.cs @@ -27,12 +27,14 @@ internal unsafe SecurityPackageInfoClass(SafeHandle safeHandle, int index) { if (safeHandle.IsInvalid) { - if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Invalid handle: {safeHandle}"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, $"Invalid handle: {safeHandle}"); return; } IntPtr unmanagedAddress = safeHandle.DangerousGetHandle() + (sizeof(SecurityPackageInfo) * index); - if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"unmanagedAddress: {unmanagedAddress}"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, $"unmanagedAddress: {unmanagedAddress}"); SecurityPackageInfo* pSecurityPackageInfo = (SecurityPackageInfo*)unmanagedAddress; @@ -47,17 +49,20 @@ internal unsafe SecurityPackageInfoClass(SafeHandle safeHandle, int index) if (unmanagedString != IntPtr.Zero) { Name = Marshal.PtrToStringUni(unmanagedString); - if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Name: {Name}"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, $"Name: {Name}"); } unmanagedString = pSecurityPackageInfo->Comment; if (unmanagedString != IntPtr.Zero) { Comment = Marshal.PtrToStringUni(unmanagedString); - if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Comment: {Comment}"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, $"Comment: {Comment}"); } - if (NetEventSource.IsEnabled) NetEventSource.Info(this, this.ToString()); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, this.ToString()); } public override string ToString() diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SecuritySafeHandles.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SecuritySafeHandles.cs index 9c1411434c..eddb15826b 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SecuritySafeHandles.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SecuritySafeHandles.cs @@ -209,7 +209,8 @@ public static unsafe int AcquireDefaultCredential( Interop.SspiCli.CredentialUse intent, out SafeFreeCredentials outCredential) { - if (NetEventSource.IsEnabled) NetEventSource.Enter(null, package, intent); + if (NetEventSource.IsEnabled) + NetEventSource.Enter(null, package, intent); int errorCode = -1; long timeStamp; @@ -274,7 +275,8 @@ public static unsafe int AcquireCredentialsHandle( ref Interop.SspiCli.SCHANNEL_CRED authdata, out SafeFreeCredentials outCredential) { - if (NetEventSource.IsEnabled) NetEventSource.Enter(null, package, intent, authdata); + if (NetEventSource.IsEnabled) + NetEventSource.Enter(null, package, intent, authdata); int errorCode = -1; long timeStamp; @@ -513,7 +515,7 @@ internal static unsafe int InitializeSecurityContext( } Interop.SspiCli.SecBuffer outUnmanagedBuffer = default; - + // Fix Descriptor pointer that points to unmanaged SecurityBuffers. outSecurityBufferDescriptor.pBuffers = &outUnmanagedBuffer; outUnmanagedBuffer.cbBuffer = outSecBuffer.size; @@ -558,7 +560,8 @@ internal static unsafe int InitializeSecurityContext( outFreeContextBuffer); } - if (NetEventSource.IsEnabled) NetEventSource.Info(null, "Marshalling OUT buffer"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(null, "Marshalling OUT buffer"); // Get unmanaged buffer with index 0 as the only one passed into PInvoke. outSecBuffer.size = outUnmanagedBuffer.cbBuffer; @@ -597,7 +600,8 @@ internal static unsafe int InitializeSecurityContext( } } - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, $"errorCode:0x{errorCode:x8}, refContext:{refContext}"); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, $"errorCode:0x{errorCode:x8}, refContext:{refContext}"); return errorCode; } @@ -841,7 +845,8 @@ internal static unsafe int AcceptSecurityContext( ref outFlags, outFreeContextBuffer); - if (NetEventSource.IsEnabled) NetEventSource.Info(null, "Marshaling OUT buffer"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(null, "Marshaling OUT buffer"); // Get unmanaged buffer with index 0 as the only one passed into PInvoke. outSecBuffer.size = outUnmanagedBuffer[0].cbBuffer; @@ -882,7 +887,8 @@ internal static unsafe int AcceptSecurityContext( } } - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, $"errorCode:0x{errorCode:x8}, refContext:{refContext}"); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, $"errorCode:0x{errorCode:x8}, refContext:{refContext}"); return errorCode; } @@ -1065,7 +1071,8 @@ internal static unsafe int CompleteAuthToken( } } - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, $"unmanaged CompleteAuthToken() errorCode:0x{errorCode:x8} refContext:{refContext}"); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, $"unmanaged CompleteAuthToken() errorCode:0x{errorCode:x8} refContext:{refContext}"); return errorCode; } @@ -1168,7 +1175,8 @@ internal static unsafe int ApplyControlToken( } } - if (NetEventSource.IsEnabled) NetEventSource.Exit(null, $"unmanaged ApplyControlToken() errorCode:0x{errorCode:x8} refContext: {refContext}"); + if (NetEventSource.IsEnabled) + NetEventSource.Exit(null, $"unmanaged ApplyControlToken() errorCode:0x{errorCode:x8} refContext: {refContext}"); return errorCode; } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/BasicFieldNameLookup.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/BasicFieldNameLookup.cs index 6e427f771e..6d5b5b8891 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/BasicFieldNameLookup.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/BasicFieldNameLookup.cs @@ -2,11 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - -using Microsoft.Data.Common; using System.Collections.Generic; using System.Data; using System.Globalization; +using Microsoft.Data.Common; namespace Microsoft.Data.ProviderBase { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/DbConnectionOptions.Common.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/DbConnectionOptions.Common.cs index e65b6380e3..2cab0ba6ed 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/DbConnectionOptions.Common.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/DbConnectionOptions.Common.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Data.Common; using System; using System.Collections.Generic; using System.Diagnostics; @@ -58,7 +57,7 @@ partial class DbConnectionOptions + "([^;\\s\\p{Cc}]|\\s+[^;\\s\\p{Cc}])*" // control characters must be quoted + ")" // although the spec does not allow {} - // embedded within a value, the retail code does. + // embedded within a value, the retail code does. + ")(\\s*)(;|[\u0000\\s]*$)" // whitespace after value up to semicolon or end-of-line + ")*" // repeat the key-value pair + "[\\s;]*[\u0000\\s]*" // traling whitespace/semicolons (DataSourceLocator), embedded nulls are allowed only in the end @@ -357,7 +356,7 @@ internal static int GetKeyValuePair(string connectionString, int currentPosition } buffer.Append(currentChar); } - ParserExit: + ParserExit: switch (parserState) { case ParserState.Key: @@ -483,7 +482,7 @@ private static Dictionary SplitConnectionString(string connectio string synonym; string realkeyname = null != synonyms ? (synonyms.TryGetValue(keyname, out synonym) ? synonym : null) : keyname; - + if (!IsKeyNameValid(realkeyname)) { throw ADP.KeywordNotSupported(keyname); @@ -558,47 +557,47 @@ private static NameValuePair ParseInternal(Dictionary parsetable try { #endif - int nextStartPosition = 0; - int endPosition = connectionString.Length; - while (nextStartPosition < endPosition) - { - int startPosition = nextStartPosition; - - string keyname, keyvalue; - nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, firstKey, out keyname, out keyvalue); - if (string.IsNullOrEmpty(keyname)) + int nextStartPosition = 0; + int endPosition = connectionString.Length; + while (nextStartPosition < endPosition) { - // if (nextStartPosition != endPosition) { throw; } - break; - } + int startPosition = nextStartPosition; + + string keyname, keyvalue; + nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, firstKey, out keyname, out keyvalue); + if (string.IsNullOrEmpty(keyname)) + { + // if (nextStartPosition != endPosition) { throw; } + break; + } #if DEBUG DebugTraceKeyValuePair(keyname, keyvalue, synonyms); Debug.Assert(IsKeyNameValid(keyname), "ParseFailure, invalid keyname"); Debug.Assert(IsValueValidInternal(keyvalue), "parse failure, invalid keyvalue"); #endif - string synonym; - string realkeyname = null != synonyms ? - (synonyms.TryGetValue(keyname, out synonym) ? synonym : null) : - keyname; - if (!IsKeyNameValid(realkeyname)) - { - throw ADP.KeywordNotSupported(keyname); - } - if (!firstKey || !parsetable.ContainsKey(realkeyname)) - { - parsetable[realkeyname] = keyvalue; // last key-value pair wins (or first) - } + string synonym; + string realkeyname = null != synonyms ? + (synonyms.TryGetValue(keyname, out synonym) ? synonym : null) : + keyname; + if (!IsKeyNameValid(realkeyname)) + { + throw ADP.KeywordNotSupported(keyname); + } + if (!firstKey || !parsetable.ContainsKey(realkeyname)) + { + parsetable[realkeyname] = keyvalue; // last key-value pair wins (or first) + } - if (null != localKeychain) - { - localKeychain = localKeychain.Next = new NameValuePair(realkeyname, keyvalue, nextStartPosition - startPosition); - } - else if (buildChain) - { // first time only - don't contain modified chain from UDL file - keychain = localKeychain = new NameValuePair(realkeyname, keyvalue, nextStartPosition - startPosition); + if (null != localKeychain) + { + localKeychain = localKeychain.Next = new NameValuePair(realkeyname, keyvalue, nextStartPosition - startPosition); + } + else if (buildChain) + { // first time only - don't contain modified chain from UDL file + keychain = localKeychain = new NameValuePair(realkeyname, keyvalue, nextStartPosition - startPosition); + } } - } #if DEBUG } catch (ArgumentException e) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/NameValuePair.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/NameValuePair.cs index 2cdd8cb6ce..abdbdfd28d 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/NameValuePair.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/NameValuePair.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Data.Common; using System.Diagnostics; namespace Microsoft.Data.Common diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs index e96a6505d8..1ac82b68cc 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs @@ -31,7 +31,7 @@ internal abstract partial class DbConnectionInternal private bool _connectionIsDoomed; // true when the connection should no longer be used. private bool _cannotBePooled; // true when the connection should no longer be pooled. - + private DateTime _createTime; // when the connection was created. #if DEBUG diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugCriticalHandleMinusOneIsInvalid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugCriticalHandleMinusOneIsInvalid.cs index 8ba682fa10..1949341de2 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugCriticalHandleMinusOneIsInvalid.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugCriticalHandleMinusOneIsInvalid.cs @@ -23,7 +23,8 @@ protected DebugCriticalHandleMinusOneIsInvalid() : base() private void Trace() { _trace = "WARNING! GC-ed >>" + this.GetType().FullName + "<< (should be explicitly closed) \r\n"; - if (NetEventSource.IsEnabled) NetEventSource.Info(this, "Creating SafeHandle"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, "Creating SafeHandle"); #if TRACE_VERBOSE string stacktrace = Environment.StackTrace; _trace += stacktrace; @@ -33,7 +34,8 @@ private void Trace() ~DebugCriticalHandleMinusOneIsInvalid() { DebugThreadTracking.SetThreadSource(ThreadKinds.Finalization); - if (NetEventSource.IsEnabled) NetEventSource.Info(this, _trace); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, _trace); } } #endif // DEBUG diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugCriticalHandleZeroOrMinusOneIsInvalid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugCriticalHandleZeroOrMinusOneIsInvalid.cs index ff4ea687d2..c28a7107b1 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugCriticalHandleZeroOrMinusOneIsInvalid.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugCriticalHandleZeroOrMinusOneIsInvalid.cs @@ -23,7 +23,8 @@ protected DebugCriticalHandleZeroOrMinusOneIsInvalid() : base() private void Trace() { _trace = "WARNING! GC-ed >>" + this.GetType().FullName + "<< (should be explicitly closed) \r\n"; - if (NetEventSource.IsEnabled) NetEventSource.Info(this, "Creating SafeHandle"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, "Creating SafeHandle"); #if TRACE_VERBOSE string stacktrace = Environment.StackTrace; _trace += stacktrace; @@ -33,7 +34,8 @@ private void Trace() ~DebugCriticalHandleZeroOrMinusOneIsInvalid() { DebugThreadTracking.SetThreadSource(ThreadKinds.Finalization); - if (NetEventSource.IsEnabled) NetEventSource.Info(this, _trace); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, _trace); } } #endif // DEBUG diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugSafeHandle.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugSafeHandle.cs index e2e7c4629a..b0646f92e9 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugSafeHandle.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/DebugSafeHandle.cs @@ -43,7 +43,8 @@ private void Trace() ~DebugSafeHandle() { - if (NetEventSource.IsEnabled) NetEventSource.Info(this, _trace); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, _trace); } } #endif // DEBUG diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/DebugThreadTracking.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/DebugThreadTracking.cs index d10cf44d08..78d8d48ac6 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/DebugThreadTracking.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/DebugThreadTracking.cs @@ -34,16 +34,19 @@ internal static IDisposable SetThreadKind(ThreadKinds kind) // Special warnings when doing dangerous things on a thread. if ((threadKind & ThreadKinds.User) != 0 && (kind & ThreadKinds.System) != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, "Thread changed from User to System; user's thread shouldn't be hijacked."); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, "Thread changed from User to System; user's thread shouldn't be hijacked."); } if ((threadKind & ThreadKinds.Async) != 0 && (kind & ThreadKinds.Sync) != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, "Thread changed from Async to Sync, may block an Async thread."); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, "Thread changed from Async to Sync, may block an Async thread."); } else if ((threadKind & (ThreadKinds.Other | ThreadKinds.CompletionPort)) == 0 && (kind & ThreadKinds.Sync) != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, "Thread from a limited resource changed to Sync, may deadlock or bottleneck."); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, "Thread from a limited resource changed to Sync, may deadlock or bottleneck."); } ThreadKindStack.Push( @@ -54,7 +57,8 @@ internal static IDisposable SetThreadKind(ThreadKinds kind) if (CurrentThreadKind != threadKind) { - if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"Thread becomes:({CurrentThreadKind})"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(null, $"Thread becomes:({CurrentThreadKind})"); } return new ThreadKindFrame(); @@ -86,7 +90,8 @@ void IDisposable.Dispose() if (CurrentThreadKind != previous && NetEventSource.IsEnabled) { - if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Thread reverts:({CurrentThreadKind})"); + if (NetEventSource.IsEnabled) + NetEventSource.Info(this, $"Thread reverts:({CurrentThreadKind})"); } } } @@ -106,7 +111,8 @@ internal static void SetThreadSource(ThreadKinds source) if (ThreadKindStack.Count > 1) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, "SetThreadSource must be called at the base of the stack, or the stack has been corrupted."); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, "SetThreadSource must be called at the base of the stack, or the stack has been corrupted."); while (ThreadKindStack.Count > 1) { ThreadKindStack.Pop(); @@ -115,7 +121,8 @@ internal static void SetThreadSource(ThreadKinds source) if (ThreadKindStack.Peek() != source) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, "The stack has been corrupted."); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, "The stack has been corrupted."); ThreadKinds last = ThreadKindStack.Pop() & ThreadKinds.SourceMask; if (last != source && last != ThreadKinds.Other && NetEventSource.IsEnabled) { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/NetEventSource.Common.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/NetEventSource.Common.cs index 6d3b94e120..4430445f30 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/NetEventSource.Common.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/NetEventSource.Common.cs @@ -45,7 +45,7 @@ namespace System.Net // method that takes an object and optionally provides a string representation of it, in case a particular library wants to customize further. /// Provides logging facilities for System.Net libraries. -#if NET46 +#if NET46 [SecuritySafeCritical] #endif internal sealed partial class NetEventSource : EventSource @@ -101,7 +101,8 @@ public static void Enter(object thisOrContextObject, FormattableString formattab { DebugValidateArg(thisOrContextObject); DebugValidateArg(formattableString); - if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); + if (IsEnabled) + Log.Enter(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); } /// Logs entrance to a method. @@ -113,7 +114,8 @@ public static void Enter(object thisOrContextObject, object arg0, [CallerMemberN { DebugValidateArg(thisOrContextObject); DebugValidateArg(arg0); - if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)})"); + if (IsEnabled) + Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)})"); } /// Logs entrance to a method. @@ -127,7 +129,8 @@ public static void Enter(object thisOrContextObject, object arg0, object arg1, [ DebugValidateArg(thisOrContextObject); DebugValidateArg(arg0); DebugValidateArg(arg1); - if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)})"); + if (IsEnabled) + Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)})"); } /// Logs entrance to a method. @@ -143,7 +146,8 @@ public static void Enter(object thisOrContextObject, object arg0, object arg1, o DebugValidateArg(arg0); DebugValidateArg(arg1); DebugValidateArg(arg2); - if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)}, {Format(arg2)})"); + if (IsEnabled) + Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)}, {Format(arg2)})"); } [Event(EnterEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)] @@ -161,7 +165,8 @@ public static void Exit(object thisOrContextObject, FormattableString formattabl { DebugValidateArg(thisOrContextObject); DebugValidateArg(formattableString); - if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); + if (IsEnabled) + Log.Exit(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); } /// Logs exit from a method. @@ -173,7 +178,8 @@ public static void Exit(object thisOrContextObject, object arg0, [CallerMemberNa { DebugValidateArg(thisOrContextObject); DebugValidateArg(arg0); - if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, Format(arg0).ToString()); + if (IsEnabled) + Log.Exit(IdOf(thisOrContextObject), memberName, Format(arg0).ToString()); } /// Logs exit from a method. @@ -187,7 +193,8 @@ public static void Exit(object thisOrContextObject, object arg0, object arg1, [C DebugValidateArg(thisOrContextObject); DebugValidateArg(arg0); DebugValidateArg(arg1); - if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, $"{Format(arg0)}, {Format(arg1)}"); + if (IsEnabled) + Log.Exit(IdOf(thisOrContextObject), memberName, $"{Format(arg0)}, {Format(arg1)}"); } [Event(ExitEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)] @@ -205,7 +212,8 @@ public static void Info(object thisOrContextObject, FormattableString formattabl { DebugValidateArg(thisOrContextObject); DebugValidateArg(formattableString); - if (IsEnabled) Log.Info(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); + if (IsEnabled) + Log.Info(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); } /// Logs an information message. @@ -217,7 +225,8 @@ public static void Info(object thisOrContextObject, object message, [CallerMembe { DebugValidateArg(thisOrContextObject); DebugValidateArg(message); - if (IsEnabled) Log.Info(IdOf(thisOrContextObject), memberName, Format(message).ToString()); + if (IsEnabled) + Log.Info(IdOf(thisOrContextObject), memberName, Format(message).ToString()); } [Event(InfoEventId, Level = EventLevel.Informational, Keywords = Keywords.Default)] @@ -235,7 +244,8 @@ public static void Error(object thisOrContextObject, FormattableString formattab { DebugValidateArg(thisOrContextObject); DebugValidateArg(formattableString); - if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString)); + if (IsEnabled) + Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString)); } /// Logs an error message. @@ -247,7 +257,8 @@ public static void Error(object thisOrContextObject, object message, [CallerMemb { DebugValidateArg(thisOrContextObject); DebugValidateArg(message); - if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString()); + if (IsEnabled) + Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString()); } [Event(ErrorEventId, Level = EventLevel.Warning, Keywords = Keywords.Default)] @@ -266,7 +277,8 @@ public static void Fail(object thisOrContextObject, FormattableString formattabl // Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations // that should never happen in production, and thus we don't care about extra costs. - if (IsEnabled) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(formattableString)); + if (IsEnabled) + Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(formattableString)); Debug.Fail(Format(formattableString), $"{IdOf(thisOrContextObject)}.{memberName}"); } @@ -280,7 +292,8 @@ public static void Fail(object thisOrContextObject, object message, [CallerMembe // Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations // that should never happen in production, and thus we don't care about extra costs. - if (IsEnabled) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(message).ToString()); + if (IsEnabled) + Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(message).ToString()); Debug.Fail(Format(message).ToString(), $"{IdOf(thisOrContextObject)}.{memberName}"); } @@ -299,7 +312,7 @@ public static void DumpBuffer(object thisOrContextObject, byte[] buffer, [Caller { DumpBuffer(thisOrContextObject, buffer, 0, buffer.Length, memberName); } - + /// Logs the contents of a buffer. /// `this`, or another object that serves to provide context for the operation. /// The buffer to be logged. @@ -367,7 +380,8 @@ public static void Associate(object first, object second, [CallerMemberName] str { DebugValidateArg(first); DebugValidateArg(second); - if (IsEnabled) Log.Associate(IdOf(first), memberName, IdOf(first), IdOf(second)); + if (IsEnabled) + Log.Associate(IdOf(first), memberName, IdOf(first), IdOf(second)); } /// Logs a relationship between two objects. @@ -381,7 +395,8 @@ public static void Associate(object thisOrContextObject, object first, object se DebugValidateArg(thisOrContextObject); DebugValidateArg(first); DebugValidateArg(second); - if (IsEnabled) Log.Associate(IdOf(thisOrContextObject), memberName, IdOf(first), IdOf(second)); + if (IsEnabled) + Log.Associate(IdOf(thisOrContextObject), memberName, IdOf(first), IdOf(second)); } [Event(AssociateEventId, Level = EventLevel.Informational, Keywords = Keywords.Default, Message = "[{2}]<-->[{3}]")] @@ -409,7 +424,7 @@ private static void DebugValidateArg(FormattableString arg) public static new bool IsEnabled => Log.IsEnabled(); - //true; // uncomment for debugging only + //true; // uncomment for debugging only [NonEvent] public static string IdOf(object value) => value != null ? value.GetType().Name + "#" + GetHashCode(value) : NullInstance; @@ -478,10 +493,14 @@ private static string Format(FormattableString s) { switch (s.ArgumentCount) { - case 0: return s.Format; - case 1: return string.Format(s.Format, Format(s.GetArgument(0))); - case 2: return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1))); - case 3: return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1)), Format(s.GetArgument(2))); + case 0: + return s.Format; + case 1: + return string.Format(s.Format, Format(s.GetArgument(0))); + case 2: + return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1))); + case 3: + return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1)), Format(s.GetArgument(2))); default: object[] args = s.GetArguments(); object[] formattedArgs = new object[args.Length]; @@ -503,10 +522,14 @@ private unsafe void WriteEvent(int eventId, string arg1, string arg2, string arg { if (IsEnabled()) { - if (arg1 == null) arg1 = ""; - if (arg2 == null) arg2 = ""; - if (arg3 == null) arg3 = ""; - if (arg4 == null) arg4 = ""; + if (arg1 == null) + arg1 = ""; + if (arg2 == null) + arg2 = ""; + if (arg3 == null) + arg3 = ""; + if (arg4 == null) + arg4 = ""; fixed (char* string1Bytes = arg1) fixed (char* string2Bytes = arg2) @@ -547,9 +570,12 @@ private unsafe void WriteEvent(int eventId, string arg1, string arg2, byte[] arg { if (IsEnabled()) { - if (arg1 == null) arg1 = ""; - if (arg2 == null) arg2 = ""; - if (arg3 == null) arg3 = Array.Empty(); + if (arg1 == null) + arg1 = ""; + if (arg2 == null) + arg2 = ""; + if (arg3 == null) + arg3 = Array.Empty(); fixed (char* arg1Ptr = arg1) fixed (char* arg2Ptr = arg2) @@ -590,7 +616,8 @@ private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int { if (IsEnabled()) { - if (arg1 == null) arg1 = ""; + if (arg1 == null) + arg1 = ""; fixed (char* arg1Ptr = arg1) { @@ -628,8 +655,10 @@ private unsafe void WriteEvent(int eventId, string arg1, int arg2, string arg3) { if (IsEnabled()) { - if (arg1 == null) arg1 = ""; - if (arg3 == null) arg3 = ""; + if (arg1 == null) + arg1 = ""; + if (arg3 == null) + arg3 = ""; fixed (char* arg1Ptr = arg1) fixed (char* arg3Ptr = arg3) @@ -663,8 +692,10 @@ private unsafe void WriteEvent(int eventId, string arg1, string arg2, int arg3) { if (IsEnabled()) { - if (arg1 == null) arg1 = ""; - if (arg2 == null) arg2 = ""; + if (arg1 == null) + arg1 = ""; + if (arg2 == null) + arg2 = ""; fixed (char* arg1Ptr = arg1) fixed (char* arg2Ptr = arg2) @@ -698,9 +729,12 @@ private unsafe void WriteEvent(int eventId, string arg1, string arg2, string arg { if (IsEnabled()) { - if (arg1 == null) arg1 = ""; - if (arg2 == null) arg2 = ""; - if (arg3 == null) arg3 = ""; + if (arg1 == null) + arg1 = ""; + if (arg2 == null) + arg2 = ""; + if (arg3 == null) + arg3 = ""; fixed (char* arg1Ptr = arg1) fixed (char* arg2Ptr = arg2) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Windows.cs index 36b850af7b..961086a6fe 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Windows.cs @@ -39,7 +39,8 @@ internal static unsafe SafeFreeCredentials AcquireCredentialsHandle(string packa if (result != Interop.SECURITY_STATUS.OK) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, System.SRHelper.Format(SR.net_log_operation_failed_with_error, nameof(Interop.SspiCli.SspiEncodeStringsAsAuthIdentity), $"0x{(int)result:X}")); + if (NetEventSource.IsEnabled) + NetEventSource.Error(null, System.SRHelper.Format(SR.net_log_operation_failed_with_error, nameof(Interop.SspiCli.SspiEncodeStringsAsAuthIdentity), $"0x{(int)result:X}")); throw new Win32Exception((int)result); } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/PasteArguments.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/PasteArguments.Windows.cs index 7cdcbc4533..1e8cfdbaf7 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/PasteArguments.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/PasteArguments.Windows.cs @@ -10,7 +10,7 @@ namespace System { internal static partial class PasteArguments { - /// + /// /// Repastes a set of arguments into a linear string that parses back into the originals under pre- or post-2008 VC parsing rules. /// The rules for parsing the executable name (argv[0]) are special, so you must indicate whether the first argument actually is argv[0]. /// diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Interop/SNINativeMethodWrapper.Common.cs b/src/Microsoft.Data.SqlClient/netcore/src/Interop/SNINativeMethodWrapper.Common.cs index 6d63bc6633..ed33b6897a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Interop/SNINativeMethodWrapper.Common.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Interop/SNINativeMethodWrapper.Common.cs @@ -21,4 +21,4 @@ internal enum SniSpecialErrors : uint MaxErrorValue = SNICommon.MaxErrorValue } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/ActivityCorrelator.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/ActivityCorrelator.cs index 5abd103464..d4f1c1ac6f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/ActivityCorrelator.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/ActivityCorrelator.cs @@ -2,7 +2,6 @@ // 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.Globalization; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/AdapterUtil.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/AdapterUtil.SqlClient.cs index f8ec10f703..27cba16b44 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/AdapterUtil.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/AdapterUtil.SqlClient.cs @@ -324,7 +324,7 @@ internal static Exception InvalidXmlInvalidValue(string collectionName, string c { return Argument(System.SRHelper.GetString(SR.MDF_InvalidXmlInvalidValue, collectionName, columnName)); } - + internal static Exception CollectionNameIsNotUnique(string collectionName) { return Argument(System.SRHelper.GetString(SR.MDF_CollectionNameISNotUnique, collectionName)); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionOptions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionOptions.cs index 02092e5f57..647a5aee94 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionOptions.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionOptions.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Globalization; - namespace Microsoft.Data.Common { internal partial class DbConnectionOptions @@ -21,7 +20,8 @@ public DbConnectionOptions(string connectionString, Dictionary s _usersConnectionString = ((null != connectionString) ? connectionString : ""); // first pass on parsing, initial syntax check - if (0 < _usersConnectionString.Length) { + if (0 < _usersConnectionString.Length) + { _keyChain = ParseInternal(_parsetable, _usersConnectionString, true, synonyms, false); HasPasswordKeyword = (_parsetable.ContainsKey(KEY.Password) || _parsetable.ContainsKey(SYNONYM.Pwd)); HasUserIdKeyword = (_parsetable.ContainsKey(KEY.User_ID) || _parsetable.ContainsKey(SYNONYM.UID)); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.NetCoreApp.cs index bb5c8f07ba..a0ad228a3c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.NetCoreApp.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.NetCoreApp.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Data.SqlClient; using System; using System.Diagnostics; +using Microsoft.Data.SqlClient; namespace Microsoft.Data.Common { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs index a26639bb7a..34ed70bb42 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs @@ -2,12 +2,11 @@ // 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.Diagnostics; +using System.Globalization; using System.Reflection; -using System; using Microsoft.Data.SqlClient; -using System.Globalization; -using Microsoft.Data.Common; namespace Microsoft.Data.Common { @@ -321,7 +320,7 @@ internal static bool IsValidAuthenticationTypeValue(SqlAuthenticationMethod valu return value == SqlAuthenticationMethod.SqlPassword || value == SqlAuthenticationMethod.ActiveDirectoryPassword || value == SqlAuthenticationMethod.ActiveDirectoryIntegrated - || value == SqlAuthenticationMethod.ActiveDirectoryInteractive + || value == SqlAuthenticationMethod.ActiveDirectoryInteractive || value == SqlAuthenticationMethod.NotSpecified; } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/DataException.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/DataException.cs index 32f9b5280b..ad3840237b 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/DataException.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/DataException.cs @@ -2,7 +2,6 @@ // 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; namespace Microsoft.Data @@ -12,8 +11,7 @@ namespace Microsoft.Data // The dangerous point there are the string arguments of the exported (internal) methods. // This string can be argument, table or constraint name but never text of exception itself. // Make an invariant that all texts of exceptions coming from resources only. - - + internal static class ExceptionBuilder { // The class defines the exceptions that are specific to the DataSet. diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/OperationAbortedException.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/OperationAbortedException.cs index a804341524..9dd6cbaa72 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/OperationAbortedException.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/OperationAbortedException.cs @@ -1,6 +1,7 @@ // 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.Runtime.Serialization; @@ -16,7 +17,7 @@ private OperationAbortedException(string message, Exception innerException) : ba } private OperationAbortedException(SerializationInfo info, StreamingContext context) : base(info, context) - { + { } internal static OperationAbortedException Aborted(Exception inner) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs index 01e3c32497..89663d2f90 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs @@ -2,9 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Data.Common; -using System.Data.Common; using System.Transactions; +using Microsoft.Data.Common; namespace Microsoft.Data.ProviderBase { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs index ab5d1de089..65c608d700 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs @@ -2,13 +2,13 @@ // 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.Diagnostics; +using System.Data; using System.Data.Common; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; -using Microsoft.Data.Common; using System.Transactions; -using System.Data; +using Microsoft.Data.Common; namespace Microsoft.Data.ProviderBase { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs index 710503cc4b..39a6f0c3dd 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs @@ -2,14 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - -using Microsoft.Data.Common; using System; using System.Data.Common; using System.Diagnostics; using System.Threading; using System.Transactions; - +using Microsoft.Data.Common; namespace Microsoft.Data.ProviderBase { @@ -374,7 +372,7 @@ public virtual void Dispose() enlistedTransaction.Dispose(); } } - + abstract public void EnlistTransaction(Transaction transaction); // Cleanup connection's transaction-specific structures (currently used by Delegated transaction). diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs index 0406343c93..6a7231d0c8 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs @@ -2,14 +2,14 @@ // 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.Data.Common; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; -using System.Collections.Concurrent; using System.Transactions; -using System; using Microsoft.Data.Common; namespace Microsoft.Data.ProviderBase @@ -128,7 +128,7 @@ internal DbConnectionInternal GetTransactedObject(Transaction transaction) } } } - + return transactedObject; } @@ -622,7 +622,7 @@ private void CleanupCallback(object state) // new stack to old stack. if (_waitHandles.PoolSemaphore.WaitOne(0)) { - for (; ;) + for (; ; ) { DbConnectionInternal obj; @@ -750,7 +750,8 @@ private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectio Timer t = new Timer(new TimerCallback(this.ErrorCallback), null, Timeout.Infinite, Timeout.Infinite); bool timerIsNotDisposed; - try { } + try + { } finally { _waitHandles.ErrorEvent.Set(); @@ -969,7 +970,8 @@ private void WaitForPendingOpen() try { - try { } + try + { } finally { started = Interlocked.CompareExchange(ref _pendingOpensWaiting, 1, 0) == 0; @@ -1383,7 +1385,8 @@ private void PoolCreateRequest(object state) int waitResult = BOGUS_HANDLE; try { - try { } + try + { } finally { waitResult = WaitHandle.WaitAny(_waitHandles.GetHandles(withCreate: true), CreationTimeout); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs index 51946630cd..6fc660b8b1 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs @@ -101,4 +101,4 @@ internal void ReleaseLockToUpdate() { Debug.Assert(oldValue == STATUS_LOCKED); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContextKey.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContextKey.cs index e6499a96bf..0f89649628 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContextKey.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContextKey.cs @@ -99,4 +99,4 @@ private int ComputeHashCode() { return hashCode; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroupProviderInfo.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroupProviderInfo.cs index 1723ea86be..3eceb6d3e3 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroupProviderInfo.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroupProviderInfo.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - namespace Microsoft.Data.ProviderBase { internal class DbConnectionPoolGroupProviderInfo diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Windows.cs index 1b26771e3b..93d2b0f329 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Windows.cs @@ -3,8 +3,8 @@ // See the LICENSE file in the project root for more information. using System; -using Microsoft.Data.SqlClient; using System.Security.Principal; +using Microsoft.Data.SqlClient; namespace Microsoft.Data.ProviderBase { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolProviderInfo.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolProviderInfo.cs index 9eb0379ab0..5392795dff 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolProviderInfo.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPoolProviderInfo.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - namespace Microsoft.Data.ProviderBase { internal class DbConnectionPoolProviderInfo diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Sql/SqlNotificationRequest.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Sql/SqlNotificationRequest.cs index dcbedb6324..3337b576e5 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Sql/SqlNotificationRequest.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Sql/SqlNotificationRequest.cs @@ -71,4 +71,4 @@ public string UserData } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationTimeoutRetryHelper.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationTimeoutRetryHelper.cs index 9679168b92..8e7fca8dcf 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationTimeoutRetryHelper.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationTimeoutRetryHelper.cs @@ -2,18 +2,19 @@ // 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.Security.Cryptography; +using System; using System.ComponentModel; +using System.Security.Cryptography; using System.Text; -using System; - -namespace Microsoft.Data.SqlClient { +namespace Microsoft.Data.SqlClient +{ /// /// AD auth retry states. /// - internal enum ActiveDirectoryAuthenticationTimeoutRetryState { + internal enum ActiveDirectoryAuthenticationTimeoutRetryState + { NotStarted = 0, Retrying, HasLoggedIn, @@ -22,7 +23,8 @@ internal enum ActiveDirectoryAuthenticationTimeoutRetryState { /// /// AD auth retry helper. /// - internal class ActiveDirectoryAuthenticationTimeoutRetryHelper { + internal class ActiveDirectoryAuthenticationTimeoutRetryHelper + { private ActiveDirectoryAuthenticationTimeoutRetryState _state = ActiveDirectoryAuthenticationTimeoutRetryState.NotStarted; private SqlFedAuthToken _token; private readonly string _typeName; @@ -30,25 +32,31 @@ internal class ActiveDirectoryAuthenticationTimeoutRetryHelper { /// /// Constructor. /// - public ActiveDirectoryAuthenticationTimeoutRetryHelper() { + public ActiveDirectoryAuthenticationTimeoutRetryHelper() + { _typeName = GetType().Name; } /// /// Retry state. /// - public ActiveDirectoryAuthenticationTimeoutRetryState State { + public ActiveDirectoryAuthenticationTimeoutRetryState State + { get { return _state; } - set { - switch (_state) { + set + { + switch (_state) + { case ActiveDirectoryAuthenticationTimeoutRetryState.NotStarted: if (value != ActiveDirectoryAuthenticationTimeoutRetryState.Retrying - && value != ActiveDirectoryAuthenticationTimeoutRetryState.HasLoggedIn) { + && value != ActiveDirectoryAuthenticationTimeoutRetryState.HasLoggedIn) + { throw new InvalidOperationException($"Cannot transit from {_state} to {value}."); } break; case ActiveDirectoryAuthenticationTimeoutRetryState.Retrying: - if (value != ActiveDirectoryAuthenticationTimeoutRetryState.HasLoggedIn) { + if (value != ActiveDirectoryAuthenticationTimeoutRetryState.HasLoggedIn) + { throw new InvalidOperationException($"Cannot transit from {_state} to {value}."); } break; @@ -64,11 +72,14 @@ public ActiveDirectoryAuthenticationTimeoutRetryState State { /// /// Cached token. /// - public SqlFedAuthToken CachedToken { - get { + public SqlFedAuthToken CachedToken + { + get + { return _token; } - set { + set + { _token = value; } } @@ -76,29 +87,36 @@ public SqlFedAuthToken CachedToken { /// /// Whether login can be retried after a client/server connection timeout due to a long-time token acquisition. /// - public bool CanRetryWithSqlException(SqlException sqlex) { + public bool CanRetryWithSqlException(SqlException sqlex) + { if (_state == ActiveDirectoryAuthenticationTimeoutRetryState.NotStarted && CachedToken != null - && IsConnectTimeoutError(sqlex)){ + && IsConnectTimeoutError(sqlex)) + { return true; } return false; } - private static bool IsConnectTimeoutError(SqlException sqlex) { + private static bool IsConnectTimeoutError(SqlException sqlex) + { var innerException = sqlex.InnerException as Win32Exception; - if (innerException == null) return false; + if (innerException == null) + return false; return innerException.NativeErrorCode == 10054 // Server timeout || innerException.NativeErrorCode == 258; // Client timeout } - private static string GetTokenHash(SqlFedAuthToken token) { - if (token == null) return "null"; + private static string GetTokenHash(SqlFedAuthToken token) + { + if (token == null) + return "null"; // Here we mimic how ADAL calculates hash for token. They use UTF8 instead of Unicode. var originalTokenString = SqlAuthenticationToken.AccessTokenStringFromBytes(token.accessToken); var bytesInUtf8 = Encoding.UTF8.GetBytes(originalTokenString); - using (var sha256 = SHA256.Create()) { + using (var sha256 = SHA256.Create()) + { var hash = sha256.ComputeHash(bytesInUtf8); return Convert.ToBase64String(hash); } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs index 877c415902..5652d93f04 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Identity.Client; using System.Security; using System.Threading.Tasks; +using Microsoft.Identity.Client; namespace Microsoft.Data.SqlClient { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs index cdeb388481..93eee05b61 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs @@ -2,10 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Data.SqlClient.Server; using System; using System.Collections.Generic; using System.Diagnostics; +using Microsoft.Data.SqlClient.Server; namespace Microsoft.Data.SqlClient { @@ -239,7 +239,7 @@ internal _SqlMetaDataSet(int count, SqlTceCipherInfoTable? cipherTable) _metaDataArray = new _SqlMetaData[count]; for (int i = 0; i < _metaDataArray.Length; ++i) { - _metaDataArray[i] = new _SqlMetaData(i); + _metaDataArray[i] = new _SqlMetaData(i); } } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs index 4a1142bfd9..9e6af8cd0b 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - -//------------------------------------------------------------------------------ - namespace Microsoft.Data.SqlClient { /// diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ColumnEncryptionKeyInfo.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ColumnEncryptionKeyInfo.cs index c7a4394643..eaecec4f9d 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ColumnEncryptionKeyInfo.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ColumnEncryptionKeyInfo.cs @@ -36,10 +36,14 @@ internal class ColumnEncryptionKeyInfo internal ColumnEncryptionKeyInfo(byte[] decryptedKey, int databaseId, byte[] keyMetadataVersion, int keyid) { - if (null == decryptedKey) { throw SQL.NullArgumentInConstructorInternal(_decryptedKeyName, _className); } - if (0 == decryptedKey.Length) { throw SQL.EmptyArgumentInConstructorInternal(_decryptedKeyName, _className); } - if (null == keyMetadataVersion) { throw SQL.NullArgumentInConstructorInternal(_keyMetadataVersionName, _className); } - if (0 == keyMetadataVersion.Length) { throw SQL.EmptyArgumentInConstructorInternal(_keyMetadataVersionName, _className); } + if (null == decryptedKey) + throw SQL.NullArgumentInConstructorInternal(_decryptedKeyName, _className); + if (0 == decryptedKey.Length) + throw SQL.EmptyArgumentInConstructorInternal(_decryptedKeyName, _className); + if (null == keyMetadataVersion) + throw SQL.NullArgumentInConstructorInternal(_keyMetadataVersionName, _className); + if (0 == keyMetadataVersion.Length) + throw SQL.EmptyArgumentInConstructorInternal(_keyMetadataVersionName, _className); KeyId = keyid; DatabaseId = databaseId; @@ -98,10 +102,14 @@ internal int GetLengthForSerialization() internal int SerializeToBuffer(byte[] bytePackage, int startOffset) { - if (null == bytePackage) { throw SQL.NullArgumentInternal(_bytePackageName, _className, _serializeToBufferMethodName); } - if (0 == bytePackage.Length) { throw SQL.EmptyArgumentInternal(_bytePackageName, _className, _serializeToBufferMethodName); } - if (!(startOffset < bytePackage.Length)) { throw SQL.OffsetOutOfBounds(_startOffsetName, _className, _serializeToBufferMethodName); } - if ((bytePackage.Length - startOffset) < GetLengthForSerialization()) { throw SQL.InsufficientBuffer(_bytePackageName, _className, _serializeToBufferMethodName); } + if (null == bytePackage) + throw SQL.NullArgumentInternal(_bytePackageName, _className, _serializeToBufferMethodName); + if (0 == bytePackage.Length) + throw SQL.EmptyArgumentInternal(_bytePackageName, _className, _serializeToBufferMethodName); + if (!(startOffset < bytePackage.Length)) + throw SQL.OffsetOutOfBounds(_startOffsetName, _className, _serializeToBufferMethodName); + if ((bytePackage.Length - startOffset) < GetLengthForSerialization()) + throw SQL.InsufficientBuffer(_bytePackageName, _className, _serializeToBufferMethodName); Buffer.BlockCopy(DatabaseIdBytes, 0, bytePackage, startOffset, DatabaseIdBytes.Length); startOffset += DatabaseIdBytes.Length; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/DataClassification/SensitivityClassification.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/DataClassification/SensitivityClassification.cs index ca1344b559..845d139a77 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/DataClassification/SensitivityClassification.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/DataClassification/SensitivityClassification.cs @@ -4,21 +4,24 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Diagnostics; -namespace Microsoft.Data.SqlClient.DataClassification { +namespace Microsoft.Data.SqlClient.DataClassification +{ - public class Label { + public class Label + { public string Name { get; private set; } public string Id { get; private set; } - public Label(string name, string id) { + public Label(string name, string id) + { Name = name; Id = id; } } - public class InformationType { + public class InformationType + { public string Name { get; private set; } public string Id { get; private set; } @@ -29,30 +32,36 @@ public InformationType(string name, string id) } } - public class SensitivityProperty { + public class SensitivityProperty + { public Label Label { get; private set; } public InformationType InformationType { get; private set; } - public SensitivityProperty(Label label, InformationType informationType) { + public SensitivityProperty(Label label, InformationType informationType) + { Label = label; InformationType = informationType; } } - public class ColumnSensitivity { + public class ColumnSensitivity + { public ReadOnlyCollection SensitivityProperties { get; private set; } - public ColumnSensitivity(IList sensitivityProperties) { + public ColumnSensitivity(IList sensitivityProperties) + { SensitivityProperties = new ReadOnlyCollection(sensitivityProperties); } } - public class SensitivityClassification { + public class SensitivityClassification + { public ReadOnlyCollection