-
Notifications
You must be signed in to change notification settings - Fork 317
Refactor and update sample project build. #3816
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| using System; | ||
| /* | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could not make this build, so commented out |
||
| #if NETFRAMEWORK | ||
| namespace ConnectionStringsWeb_Encrypt; | ||
|
|
||
| using System; | ||
| using System.Configuration; | ||
| using System.Web.Configuration; | ||
|
|
||
|
|
@@ -35,3 +39,5 @@ static void ToggleWebEncrypt() | |
| } | ||
| // </Snippet1> | ||
| } | ||
| #endif | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| using System; | ||
| namespace ConnectionStrings_Encrypt; | ||
|
|
||
| using System; | ||
| using System.Configuration; | ||
|
|
||
| class Program | ||
|
|
@@ -7,7 +9,7 @@ static void Main() | |
| { | ||
| } | ||
| // <Snippet1> | ||
| static void ToggleConfigEncryption(string exeFile) | ||
| static void ToggleConfigEncryption(string exeConfigName) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected parameter name to make build pass |
||
| { | ||
| // Takes the executable file name without the | ||
| // .config extension. | ||
ErikEJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| namespace DataColumn_DataType; | ||
|
|
||
| using System; | ||
| using System.Data; | ||
| // <Snippet1> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| namespace DataTableReader_GetValues; | ||
|
|
||
| // <Snippet1> | ||
| using System; | ||
| using System.Data; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| namespace Isolation_Snapshot; | ||
|
|
||
| using System; | ||
| using System.Data; | ||
| // <Snippet1> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| namespace Isolation_Snapshot1; | ||
|
|
||
| using System; | ||
| using System.Data; | ||
| // <Snippet1> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net8.0;net462</TargetFrameworks> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to make "dotnet build" work
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we target .NET 10 here instead of 8? |
||
| <OutputType>Library</OutputType> | ||
| <ImplicitUsings>disable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
|
|
@@ -16,10 +17,11 @@ | |
| <PackageReference Include="Microsoft.Data.SqlClient" /> | ||
| <PackageReference Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" /> | ||
| <PackageReference Include="Newtonsoft.Json" /> | ||
| <PackageReference Include="System.Configuration.ConfigurationManager" /> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to make build pass |
||
| </ItemGroup> | ||
|
|
||
| <!-- .NET Framework references --> | ||
| <ItemGroup Condition="$(TargetGroup) == 'netfx'"> | ||
| <ItemGroup Condition="'$(TargetFramework)' == 'net462'"> | ||
ErikEJ marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to make local "dotnet build" work |
||
| <PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" /> | ||
| <Reference Include="System.Transactions" /> | ||
| <Reference Include="System.Windows.Forms" /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| using System.IO; | ||
| using Microsoft.SqlServer.Server; | ||
|
|
||
| namespace test | ||
| namespace DataWorks_IBinarySerialize_Sample | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we come up with a namespace convention for samples? For example, base namespace names of:
And then append something unique to make the complete namespace:
@benrr101 and others - should we discuss before Erik makes any changes here? |
||
| { | ||
| public class Class1 : IBinarySerialize | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| using System.IO; | ||
| namespace DataWorks_SqlFunctionAttribute_Sample; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we prefer to put usings outside of any namespace declaration.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to deliberate minimize impact on sample code - I think mentally this code base is quite different from production code
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to deliberate minimize impact on sample code - I think mentally this code base is quite different from production code |
||
|
|
||
| using System.IO; | ||
| using System.Collections; | ||
| using Microsoft.SqlServer.Server; | ||
|
|
||
|
|
@@ -20,4 +22,4 @@ public static IEnumerable GetFileDetails(string directoryPath) | |
| } | ||
| } | ||
| //</Snippet1> | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| namespace SqlMethodCSExample; | ||
|
|
||
| using System; | ||
| // <Snippet1> | ||
| using Microsoft.SqlServer.Server; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| //----------------------------------------------------------------------------- | ||
| namespace SqlUserDefinedTypeAttribute_Type1; | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| //<Snippet5> | ||
| using System; | ||
| using System.Data.SqlTypes; | ||
|
|
@@ -78,8 +80,8 @@ public static Point Parse(SqlString s) | |
| string[] xy = str.Split(':'); | ||
|
|
||
| Point pt = new Point(); | ||
| pt.X = Convert.Toint(xy[0]); | ||
| pt.Y = Convert.Toint(xy[1]); | ||
| pt.X = Convert.ToInt32(xy[0]); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix of incorrect sample code |
||
| pt.Y = Convert.ToInt32(xy[1]); | ||
| return (pt); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| // <Snippet1> | ||
| namespace RegisterCustomKeyStoreProvider_CommandPrecedence; | ||
|
|
||
| using System.Collections.Generic; | ||
| using Azure.Identity; | ||
| using Microsoft.Data.SqlClient; | ||
| using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider; | ||
|
|
||
| // <Snippet1> | ||
| class Program | ||
| { | ||
| static void Main() | ||
| static void Main(string connectionString) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added missing parameter to make build pass |
||
| { | ||
| Dictionary<string, SqlColumnEncryptionKeyStoreProvider> customKeyStoreProviders = new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>(); | ||
| MyCustomKeyStoreProvider firstProvider = new MyCustomKeyStoreProvider(); | ||
|
|
@@ -20,7 +27,7 @@ static void Main() | |
| using (SqlCommand command = connection.CreateCommand()) | ||
| { | ||
| customKeyStoreProviders.Clear(); | ||
| SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(); | ||
| SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uses the updated API to make build pass |
||
| customKeyStoreProviders.Add(SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, azureKeyVaultProvider); | ||
| // Registers the provider on the command | ||
| // These providers will take precedence over connection-level providers and globally registered providers | ||
|
|
@@ -30,3 +37,17 @@ static void Main() | |
| } | ||
| } | ||
| // </Snippet1> | ||
|
|
||
| class MyCustomKeyStoreProvider : SqlColumnEncryptionKeyStoreProvider | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added dummy class to make build pass (not part of snippet) |
||
| { | ||
| public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey) | ||
| { | ||
| // Custom decryption logic here | ||
| return new byte[0]; | ||
| } | ||
| public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey) | ||
| { | ||
| // Custom encryption logic here | ||
| return new byte[0]; | ||
ErikEJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| // <Snippet1> | ||
| namespace RegisterCustomKeyStoreProvider_ConnectionPrecedence; | ||
|
|
||
| using System.Collections.Generic; | ||
| using Azure.Core; | ||
| using Azure.Identity; | ||
| using Microsoft.Data.SqlClient; | ||
| using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider; | ||
|
|
||
| // <Snippet1> | ||
| class Program | ||
| { | ||
| static void Main() | ||
| static void Main(string connectionString) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added missing parameter to make build pass |
||
| { | ||
| Dictionary<string, SqlColumnEncryptionKeyStoreProvider> customKeyStoreProviders = new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>(); | ||
| MyCustomKeyStoreProvider myProvider = new MyCustomKeyStoreProvider(); | ||
|
|
@@ -12,7 +20,7 @@ static void Main() | |
| using (SqlConnection connection = new SqlConnection(connectionString)) | ||
| { | ||
| customKeyStoreProviders.Clear(); | ||
| SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(); | ||
| SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the updated API to make build pass |
||
| customKeyStoreProviders.Add(SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, azureKeyVaultProvider); | ||
| // Registers the provider on the connection | ||
| // These providers will take precedence over globally registered providers | ||
|
|
@@ -21,3 +29,17 @@ static void Main() | |
| } | ||
| } | ||
| // </Snippet1> | ||
|
|
||
| class MyCustomKeyStoreProvider : SqlColumnEncryptionKeyStoreProvider | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added dummy class to make build pass (not part of snippet) |
||
| { | ||
| public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey) | ||
| { | ||
| // Custom decryption logic here | ||
| return new byte[0]; | ||
| } | ||
| public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey) | ||
| { | ||
| // Custom encryption logic here | ||
| return new byte[0]; | ||
| } | ||
| } | ||
ErikEJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| // <Snippet1> | ||
| namespace RegisterCustomKeyStoreProvider_Example; | ||
|
|
||
| // <Snippet1> | ||
| using Azure.Identity; | ||
| using Microsoft.Data.SqlClient; | ||
| using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider; | ||
| using System.Collections.Generic; | ||
|
|
@@ -15,7 +18,7 @@ void ExecuteSelectQuery(object user, SqlConnection connection) | |
| if (azureKeyVaultProvider is null) | ||
| { | ||
| // Create a new SqlColumnEncryptionAzureKeyVaultProvider with the user's credentials and save it for future use | ||
| azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(); | ||
| azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the updated API to make build pass |
||
| providerByUser[user] = azureKeyVaultProvider; | ||
| } | ||
|
|
||
|
|
@@ -35,7 +38,7 @@ void ExecuteUpdateQuery(object user, SqlConnection connection) | |
| if (azureKeyVaultProvider is null) | ||
| { | ||
| // Create a new SqlColumnEncryptionAzureKeyVaultProvider with the user's credentials and save it for future use | ||
| azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(); | ||
| azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the updated API to make build pass |
||
| providerByUser[user] = azureKeyVaultProvider; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excluded this from build, as it contains obsolete APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment to this effect?
Also, if you use
#if falseinstead of the block comment/* */then we still get nice IDE presentation and you can put comments about what isn't compiling adjacent to the offending lines.