Update to .NET 7 SDK (#1792)

This commit is contained in:
Cheena Malhotra
2023-02-07 17:53:36 -08:00
committed by GitHub
parent 51892519ef
commit 8d119876d9
62 changed files with 169 additions and 147 deletions

4
.vscode/launch.json vendored
View File

@@ -10,7 +10,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Microsoft.SqlTools.ServiceLayer/bin/Debug/net6.0/MicrosoftSqlToolsServiceLayer.dll",
"program": "${workspaceFolder}/src/Microsoft.SqlTools.ServiceLayer/bin/Debug/net7.0/MicrosoftSqlToolsServiceLayer.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Microsoft.SqlTools.ServiceLayer",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
@@ -24,7 +24,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Microsoft.Kusto.ServiceLayer/bin/Debug/net6.0/MicrosoftKustoServiceLayer.dll",
"program": "${workspaceFolder}/src/Microsoft.Kusto.ServiceLayer/bin/Debug/net7.0/MicrosoftKustoServiceLayer.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Microsoft.Kusto.ServiceLayer",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<HighEntropyVA>true</HighEntropyVA>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootDir>$(MSBuildThisFileDirectory)</RootDir>
<!-- Defaults-->

View File

@@ -5,8 +5,8 @@ IF [%_BuildConfiguration%] NEQ [] GOTO Start
SET _BuildConfiguration=Debug
:Start
SET _PerfTestSourceLocation="%WORKINGDIR%\test\Microsoft.SqlTools.ServiceLayer.PerfTests\bin\%_BuildConfiguration%\net6.0\win-x64\publish"
SET _ServiceSourceLocation="%WORKINGDIR%\src\Microsoft.SqlTools.ServiceLayer\bin\%_BuildConfiguration%\net6.0\win-x64\publish"
SET _PerfTestSourceLocation="%WORKINGDIR%\test\Microsoft.SqlTools.ServiceLayer.PerfTests\bin\%_BuildConfiguration%\net7.0\win-x64\publish"
SET _ServiceSourceLocation="%WORKINGDIR%\src\Microsoft.SqlTools.ServiceLayer\bin\%_BuildConfiguration%\net7.0\win-x64\publish"

View File

@@ -40,8 +40,17 @@ parameters:
- 'Microsoft.SqlTools.Migration'
steps:
# .NET Core 2.1 SDK is installed for ESRP Code signing task,
# ESRP currently uses DLL from this path: ~\1.9.111\netcoreapp2.1\esrpcli.dll (found in logs)
# Can be removed once ESRP codesigning task gets an upgrade and a newer SDK DLL is used.
- task: UseDotNet@2
displayName: 'Use defined .NET Core sdk'
displayName: 'Use .NET Core 2 sdk'
inputs:
useGlobalJson: false
version: 2.x
- task: UseDotNet@2
displayName: 'Use defined .NET sdk'
inputs:
useGlobalJson: true
@@ -245,10 +254,10 @@ steps:
- task: ArchiveFiles@1
displayName: 'Archive ${{ platform.displayName }} ${{ project }} build'
inputs:
rootFolder: '$(Build.SourcesDirectory)/artifacts/publish/${{ project }}/${{ platform.name }}/net6.0'
rootFolder: '$(Build.SourcesDirectory)/artifacts/publish/${{ project }}/${{ platform.name }}/net7.0'
includeRootFolder: false
archiveType: ${{ platform.archiveType }}
archiveFile: '$(Build.SourcesDirectory)/artifacts/package/${{ project }}-${{ platform.archiveName }}-net6.0.${{ platform.archiveFileFormat }}'
archiveFile: '$(Build.SourcesDirectory)/artifacts/package/${{ project }}-${{ platform.archiveName }}-net7.0.${{ platform.archiveFileFormat }}'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: build archives'

View File

@@ -13,7 +13,7 @@
# The script need to run from the repo root
net6projectArray=(
dotnetProjectArray=(
"./src/Microsoft.Kusto.ServiceLayer"
"./src/Microsoft.SqlTools.Credentials"
"./src/Microsoft.SqlTools.Hosting"
@@ -34,13 +34,8 @@ net6projectArray=(
"./test/Microsoft.SqlTools.Test.CompletionExtension"
)
netStandard2ProjectArray=(
"./src/Microsoft.SqlTools.ManagedBatchParser"
)
# Please update the framework vars when updating target framework for the projects
framework6="/bin/Debug/net6.0/"
framework2="/bin/Debug/netstandard2.1/"
framework7="/bin/Debug/net7.0/"
requiredLocDirectories=(
"cs"
@@ -74,24 +69,13 @@ requiredLocDirectories=(
"zh-hant"
)
for i in "${net6projectArray[@]}"
for i in "${dotnetProjectArray[@]}"
do
:
for k in "${requiredLocDirectories[@]}"
do
:
output=`mkdir -v -p $i$framework6$k`
output=`mkdir -v -p $i$framework7$k`
echo $output
done
done
for i in "${netStandard2ProjectArray[@]}"
do
:
for k in "${requiredLocDirectories[@]}"
do
:
output=`mkdir -v -p $i$framework2$k`
echo $output
done
done

View File

@@ -470,7 +470,7 @@ void PublishProject(string packageName, string[] projects)
var publishArguments = "publish";
if (!runtime.Equals("default"))
{
publishArguments = $"{publishArguments} --runtime {runtime}";
publishArguments = $"{publishArguments} --runtime {runtime} --self-contained";
}
publishArguments = $"{publishArguments} --framework {framework} --configuration {configuration}";
publishArguments = $"{publishArguments} --output \"{outputFolder}\" \"{projectFolder}\"";

View File

@@ -9,24 +9,24 @@
"PackageName": "Microsoft.SqlTools.ServiceLayer",
"TestProjects": {
"Microsoft.SqlTools.ServiceLayer.UnitTests": [
"net6.0"
"net7.0"
],
"Microsoft.Kusto.ServiceLayer.UnitTests": [
"net6.0"
"net7.0"
],
"Microsoft.SqlTools.ServiceLayer.TestEnvConfig": [
"net6.0"
"net7.0"
],
"Microsoft.SqlTools.ServiceLayer.IntegrationTests": [
"net6.0"
"net7.0"
]
},
"Frameworks": [
"net6.0"
"net7.0"
],
"FxFrameworks":[
"net472",
"net6.0"
"net7.0"
],
"MainProjects": [
"Microsoft.SqlTools.Credentials",

View File

@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.403",
"version": "7.0.101",
"rollForward": "latestFeature"
},
"msbuild-sdks": {

View File

@@ -18,7 +18,7 @@
<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="System.Configuration.ConfigurationManager" version="6.0.0" />
</group>
<group targetFramework="net6.0">
<group targetFramework="net7.0">
<dependency id="Microsoft.Data.SqlClient" version="5.0.1" />
<dependency id="Microsoft.SqlServer.SqlManagementObjects" version="170.12.0" />
<dependency id="Newtonsoft.Json" version="13.0.2" />
@@ -42,19 +42,19 @@
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net472\Microsoft.SqlTools.ManagedBatchParser.pdb" target="lib\net472" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net472\Microsoft.SqlTools.ManagedBatchParser.xml" target="lib\net472" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\de\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\de" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\es\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\es" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\fr\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\fr" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\it\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\it" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\ja\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\ja" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\ko\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\ko" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\pt-br\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\pt-br" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\ru\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\ru" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\zh-hans\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\zh-hans" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\zh-hant\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net6.0\zh-hant" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\de\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\de" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\es\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\es" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\fr\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\fr" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\it\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\it" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\ja\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\ja" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\ko\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\ko" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\pt-br\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\pt-br" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\ru\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\ru" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\zh-hans\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\zh-hans" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\zh-hant\Microsoft.SqlTools.ManagedBatchParser.resources.dll" target="lib\net7.0\zh-hant" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\Microsoft.SqlTools.ManagedBatchParser.dll" target="lib\net6.0" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\Microsoft.SqlTools.ManagedBatchParser.pdb" target="lib\net6.0" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net6.0\Microsoft.SqlTools.ManagedBatchParser.xml" target="lib\net6.0" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\Microsoft.SqlTools.ManagedBatchParser.dll" target="lib\net7.0" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\Microsoft.SqlTools.ManagedBatchParser.pdb" target="lib\net7.0" />
<file src="..\..\artifacts\publish\Microsoft.SqlTools.ServiceLayer\default\net7.0\Microsoft.SqlTools.ManagedBatchParser.xml" target="lib\net7.0" />
</files>
</package>

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -14,6 +14,8 @@
<PreserveCompilationContext>true</PreserveCompilationContext>
<DebugType>portable</DebugType>
<RuntimeIdentifiers>$(ToolsServiceTargetRuntimes)</RuntimeIdentifiers>
<!-- TODO FIX THESE WARNINGS ASAP -->
<NoWarn>$(NoWarn);SYSLIB1045;CA1311;CA1854</NoWarn>
</PropertyGroup>
<PropertyGroup>

View File

@@ -8,6 +8,7 @@ using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.Kusto.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;
using System.Diagnostics;
using System.Threading.Tasks;
namespace Microsoft.Kusto.ServiceLayer
{
@@ -21,7 +22,7 @@ namespace Microsoft.Kusto.ServiceLayer
/// <summary>
/// Main entry point into the SQL Tools API Service Layer
/// </summary>
internal static void Main(string[] args)
internal static async Task Main(string[] args)
{
try
{
@@ -54,7 +55,7 @@ namespace Microsoft.Kusto.ServiceLayer
ProcessExitTimer.Start(commandOptions.ParentProcessId.Value);
}
serviceHost.WaitForExit();
await serviceHost.WaitForExitAsync();
}
catch (Exception e)
{

View File

@@ -73,7 +73,7 @@ namespace Microsoft.Kusto.ServiceLayer.QueryExecution.DataStorage
/// <returns></returns>
public Task<bool> ReadAsync(CancellationToken cancellationToken)
{
return Task.Run(() => DataReader.Read());
return Task.Run(DataReader.Read);
}
/// <summary>

View File

@@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.Credentials
// which obtains the raw errno that varies between unixes. The strong typing as an enum is meant to
// prevent confusing the two. Casting to or from int is suspect. Use GetLastErrorInfo() if you need to
// correlate these to the underlying platform values or obtain the corresponding error message.
//
//
SUCCESS = 0,
@@ -185,7 +185,7 @@ namespace Microsoft.SqlTools.Credentials
// so here in the future if necessary.
message = buffer;
}
string returnMsg = Marshal.PtrToStringAnsi(message);
return returnMsg;
}

View File

@@ -19,7 +19,7 @@ namespace Microsoft.SqlTools.Credentials
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ChMod", SetLastError = true)]
internal static extern int ChMod(string path, int mode);
internal struct Passwd
{
internal IntPtr Name; // char*

View File

@@ -43,10 +43,10 @@ namespace Microsoft.SqlTools.Credentials
/// <remarks>For *nix systems, the CLR maps ANSI to UTF-8, so be explicit about that</remarks>
[DllImport(Interop.Libraries.CoreFoundationLibrary, CharSet = CharSet.Ansi)]
private static extern SafeCreateHandle CFStringCreateWithCString(
IntPtr allocator,
string str,
IntPtr allocator,
string str,
CFStringBuiltInEncodings encoding);
/// <summary>
/// Creates a CFStringRef from a 8-bit String object. Follows the "Create Rule" where if you create it, you delete it.
/// </summary>
@@ -86,7 +86,7 @@ namespace Microsoft.SqlTools.Credentials
/// <summary>
/// You should retain a Core Foundation object when you receive it from elsewhere
/// (that is, you did not create or copy it) and you want it to persist. If you
/// (that is, you did not create or copy it) and you want it to persist. If you
/// retain a Core Foundation object you are responsible for releasing it
/// </summary>
/// <param name="ptr">The CFType object to retain. This value must not be NULL</param>

View File

@@ -16,11 +16,11 @@ namespace Microsoft.SqlTools.Credentials
{
[DllImport(Libraries.SecurityLibrary, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern OSStatus SecKeychainAddGenericPassword(IntPtr keyChainRef, UInt32 serviceNameLength, string serviceName,
internal static extern OSStatus SecKeychainAddGenericPassword(IntPtr keyChainRef, UInt32 serviceNameLength, string serviceName,
UInt32 accountNameLength, string accountName, UInt32 passwordLength, IntPtr password, [Out] IntPtr itemRef);
/// <summary>
/// Find a generic password based on the attributes passed
/// Find a generic password based on the attributes passed
/// </summary>
/// <param name="keyChainRef">
/// A reference to an array of keychains to search, a single keychain, or NULL to search the user's default keychain search list.
@@ -31,22 +31,22 @@ namespace Microsoft.SqlTools.Credentials
/// <param name="accountName">A pointer to a string containing the account name.</param>
/// <param name="passwordLength">On return, the length of the buffer pointed to by passwordData.</param>
/// <param name="password">
/// On return, a pointer to a data buffer containing the password.
/// Your application must call SecKeychainItemFreeContent(NULL, passwordData)
/// On return, a pointer to a data buffer containing the password.
/// Your application must call SecKeychainItemFreeContent(NULL, passwordData)
/// to release this data buffer when it is no longer needed.Pass NULL if you are not interested in retrieving the password data at
/// this time, but simply want to find the item reference.
/// </param>
/// <param name="itemRef">On return, a reference to the keychain item which was found.</param>
/// <returns>A result code that should be in <see cref="OSStatus"/></returns>
/// <remarks>
/// The SecKeychainFindGenericPassword function finds the first generic password item which matches the attributes you provide.
/// Most attributes are optional; you should pass only as many as you need to narrow the search sufficiently for your application's intended use.
/// The SecKeychainFindGenericPassword function finds the first generic password item which matches the attributes you provide.
/// Most attributes are optional; you should pass only as many as you need to narrow the search sufficiently for your application's intended use.
/// SecKeychainFindGenericPassword optionally returns a reference to the found item.
/// </remarks>
[DllImport(Libraries.SecurityLibrary, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern OSStatus SecKeychainFindGenericPassword(IntPtr keyChainRef, UInt32 serviceNameLength, string serviceName,
internal static extern OSStatus SecKeychainFindGenericPassword(IntPtr keyChainRef, UInt32 serviceNameLength, string serviceName,
UInt32 accountNameLength, string accountName, out UInt32 passwordLength, out IntPtr password, out IntPtr itemRef);
/// <summary>
/// Releases the memory used by the keychain attribute list and the keychain data retrieved in a previous call to SecKeychainItemCopyContent.
/// </summary>
@@ -55,15 +55,15 @@ namespace Microsoft.SqlTools.Credentials
/// <returns>A result code that should be in <see cref="OSStatus"/></returns>
[DllImport(Libraries.SecurityLibrary, SetLastError = true)]
internal static extern OSStatus SecKeychainItemFreeContent([In] IntPtr attrList, [In] IntPtr data);
/// <summary>
/// Deletes a keychain item from the default keychain's permanent data store.
/// </summary>
/// <param name="itemRef">A keychain item reference of the item to delete.</param>
/// <returns>A result code that should be in <see cref="OSStatus"/></returns>
/// <remarks>
/// If itemRef has not previously been added to the keychain, SecKeychainItemDelete does nothing and returns ErrSecSuccess.
/// IMPORTANT: SecKeychainItemDelete does not dispose the memory occupied by the item reference itself;
/// If itemRef has not previously been added to the keychain, SecKeychainItemDelete does nothing and returns ErrSecSuccess.
/// IMPORTANT: SecKeychainItemDelete does not dispose the memory occupied by the item reference itself;
/// use the CFRelease function when you are completely * * finished with an item.
/// </remarks>
[DllImport(Libraries.SecurityLibrary, SetLastError = true)]

View File

@@ -1,6 +1,6 @@
//
// Code originally from http://credentialmanagement.codeplex.com/,
// Licensed under the Apache License 2.0
// Code originally from http://credentialmanagement.codeplex.com/,
// Licensed under the Apache License 2.0
//
using System;
@@ -11,7 +11,7 @@ namespace Microsoft.SqlTools.Credentials.Win32
{
internal class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
internal struct CREDENTIAL
{
@@ -32,7 +32,7 @@ namespace Microsoft.SqlTools.Credentials.Win32
[MarshalAs(UnmanagedType.LPWStr)]
public string UserName;
}
[DllImport("Advapi32.dll", EntryPoint = "CredReadW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool CredRead(string target, CredentialType type, int reservedFlag, out IntPtr CredentialPtr);
@@ -47,7 +47,7 @@ namespace Microsoft.SqlTools.Credentials.Win32
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool CredEnumerateW(string filter, int flag, out uint count, out IntPtr pCredentials);
[DllImport("ole32.dll")]
internal static extern void CoTaskMemFree(IntPtr ptr);
@@ -86,7 +86,7 @@ namespace Microsoft.SqlTools.Credentials.Win32
}
// Perform any specific actions to release the handle in the ReleaseHandle method.
// Often, you need to use Pinvoke to make a call into the Win32 API to release the
// Often, you need to use Pinvoke to make a call into the Win32 API to release the
// handle. In this case, however, we can use the Marshal class to release the unmanaged memory.
protected override bool ReleaseHandle()
@@ -101,7 +101,7 @@ namespace Microsoft.SqlTools.Credentials.Win32
SetHandleAsInvalid();
return true;
}
// Return false.
// Return false.
return false;
}
}

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -13,6 +13,8 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PreserveCompilationContext>true</PreserveCompilationContext>
<RuntimeIdentifiers>$(ToolsServiceTargetRuntimes)</RuntimeIdentifiers>
<!-- TODO FIX THESE WARNINGS ASAP -->
<NoWarn>$(NoWarn);SYSLIB1054</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" Exclude="**/obj/**/*.cs" />

View File

@@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.SqlTools.Credentials.Utility;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.Utility;
@@ -20,7 +21,7 @@ namespace Microsoft.SqlTools.Credentials
/// <summary>
/// Main entry point into the Credentials Service Host
/// </summary>
internal static void Main(string[] args)
internal static async Task Main(string[] args)
{
try
{
@@ -48,7 +49,7 @@ namespace Microsoft.SqlTools.Credentials
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
UtilityServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
serviceHost.WaitForExit();
await serviceHost.WaitForExitAsync();
}
catch (Exception e)
{

View File

@@ -112,7 +112,7 @@ namespace Microsoft.SqlTools.Extensibility
if (!services.ContainsKey(typeof(T)))
{
ExtensionStore store = new ExtensionStore(typeof(T), config);
base.Register<T>(() => store.GetExports<T>());
base.Register<T>(store.GetExports<T>);
}
}
@@ -136,11 +136,11 @@ namespace Microsoft.SqlTools.Extensibility
// If the service type is already registered, replace the existing registration with the new one
if (this.services.ContainsKey(typeof(T)))
{
this.services[typeof(T)] = () => store.GetExports<T>();
this.services[typeof(T)] = store.GetExports<T>;
}
else
{
base.Register<T>(() => store.GetExports<T>());
base.Register<T>(store.GetExports<T>);
}
}

View File

@@ -119,10 +119,10 @@ namespace Microsoft.SqlTools.Hosting.Protocol
}
}
public void WaitForExit()
public async Task WaitForExitAsync()
{
this.endpointExitedTask = new TaskCompletionSource<bool>();
this.endpointExitedTask.Task.Wait();
await this.endpointExitedTask.Task.WaitAsync(CancellationToken.None);
}
public async Task Stop()

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -23,10 +23,7 @@ namespace Microsoft.SqlTools.Utility
{
foreach (var key in keys)
{
if (_cache.ContainsKey(key))
{
_cache.Remove(key);
}
_cache.Remove(key);
}
}
}, out exception);

View File

@@ -19,6 +19,7 @@ namespace Microsoft.SqlTools.Utility
public T GetOptionValue<T>(string name, T defaultValue = default(T))
{
#pragma warning disable CA1854
T result = defaultValue;
if (Options != null && Options.ContainsKey(name))
{
@@ -34,6 +35,7 @@ namespace Microsoft.SqlTools.Utility
"Cannot convert option value {0}:{1} to {2}", name, value ?? "", typeof(T)));
}
}
#pragma warning restore CA1854
return result;
}

View File

@@ -89,10 +89,7 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
if (value == null)
{
if (internalVariables.ContainsKey(name))
{
internalVariables.Remove(name);
}
internalVariables.Remove(name);
}
else
{

View File

@@ -8,7 +8,7 @@ using System;
namespace Microsoft.SqlTools.ServiceLayer.BatchParser
{
[Serializable]
public struct PositionStruct
public readonly struct PositionStruct
{
private readonly int line;
private readonly int column;

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Targeting both net6.0 and net472 so that other things such as PS cmdlets can use this which need to support a wider range of machines -->
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<!-- Targeting both net7.0 and net472 so that other things such as PS cmdlets can use this which need to support a wider range of machines -->
<TargetFrameworks>net7.0;net472</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<Nullable>disable</Nullable>
<AssemblyName>Microsoft.SqlTools.ManagedBatchParser</AssemblyName>
@@ -13,6 +13,8 @@
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
<EmbeddedResourceUseDependentUponConvention>false</EmbeddedResourceUseDependentUponConvention>
<Product>Microsoft SqlTools Managed batch parser</Product>
<!-- TODO FIX THESE WARNINGS ASAP -->
<NoWarn>$(NoWarn);CA1852</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" />
@@ -25,7 +27,7 @@
<EmbeddedResource Include="Localization\*.resx" />
<None Include="Localization\sr.strings" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'net6.0'">
<ItemGroup Condition="$(TargetFramework) == 'net7.0'">
<InternalsVisibleTo Include="Microsoft.SqlTools.ServiceLayer.UnitTests" />
<InternalsVisibleTo Include="Microsoft.SqlTools.ServiceLayer.IntegrationTests" />
<InternalsVisibleTo Include="Microsoft.SqlTools.ServiceLayer.Test.Common" />

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -10,6 +10,7 @@ using System.IO;
using System.Diagnostics;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.Utility;
using System.Threading.Tasks;
namespace Microsoft.SqlTools.Migration
{
@@ -17,7 +18,7 @@ namespace Microsoft.SqlTools.Migration
{
private const string ServiceName = "MicrosoftSqlToolsMigration.exe";
internal static void Main(string[] args)
internal static async Task Main(string[] args)
{
try
{
@@ -51,7 +52,7 @@ namespace Microsoft.SqlTools.Migration
});
serviceHost.RegisterAndInitializeService(new MigrationService());
serviceHost.WaitForExit();
await serviceHost.WaitForExitAsync();
Logger.Verbose("SqlTools Migration Server exiting....");
}
catch (Exception ex)

View File

@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.Migration.Utils
foreach (var keyValuePair2 in exceptionMap2)
{
// If the dictionary already contains the key then merge them
if (exceptionMap1.ContainsKey(keyValuePair2.Key))
if (exceptionMap1.TryGetValue(keyValuePair2.Key, out _))
{
foreach (var value in keyValuePair2.Value)
{

View File

@@ -69,10 +69,12 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
clientIp = null;
try
{
#pragma warning disable SYSLIB1045
Regex regex =
new Regex(
@"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b",
RegexOptions.IgnoreCase);
#pragma warning restore SYSLIB1045
Match match = regex.Match(message);
if (match.Success)

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -10,6 +10,8 @@
<StartupObject />
<Description>Provides the default for SqlTools applications.</Description>
<Copyright><EFBFBD> Microsoft Corporation. All rights reserved.</Copyright>
<!-- TODO FIX THESE WARNINGS ASAP -->
<NoWarn>$(NoWarn);CA1852</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" />

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -12,6 +12,8 @@
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
<EmbeddedResourceUseDependentUponConvention>false</EmbeddedResourceUseDependentUponConvention>
<RuntimeIdentifiers>$(ToolsServiceTargetRuntimes)</RuntimeIdentifiers>
<!-- TODO FIX THESE WARNINGS ASAP -->
<NoWarn>$(NoWarn);CA1852</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_0;NETCOREAPP2_0</DefineConstants>

View File

@@ -7,6 +7,7 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.Utility;
@@ -22,7 +23,7 @@ namespace Microsoft.SqlTools.ResourceProvider
/// <summary>
/// Main entry point into the Credentials Service Host
/// </summary>
internal static void Main(string[] args)
internal static async Task Main(string[] args)
{
try
{
@@ -52,7 +53,7 @@ namespace Microsoft.SqlTools.ResourceProvider
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
UtilityServiceHost serviceHost = ResourceProviderHostLoader.CreateAndStartServiceHost(sqlToolsContext);
serviceHost.WaitForExit();
await serviceHost.WaitForExitAsync();
}
catch (Exception e)
{

View File

@@ -36,7 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
{
try
{
var filters = Parameters.ObjectTypes.Select(t => MapType(t)).ToArray();
var filters = Parameters.ObjectTypes.Select(MapType).ToArray();
var objects = Model.GetObjects(DacQueryScopes.UserDefined, filters).ToList();
return objects.Select(o => new TSqlObjectInfo

View File

@@ -81,8 +81,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
Subtext = currentNode.GetDisplayLinesOfText(true),
RelativeCost = currentNode.RelativeCost,
Properties = GetProperties(currentNode.Properties),
Children = currentNode.Children.Select(x => ConvertShowPlanTreeToExecutionPlanTree(x)).ToList(),
Edges = currentNode.Edges.Select(x => ConvertShowPlanEdgeToExecutionPlanEdge(x)).ToList(),
Children = currentNode.Children.Select(ConvertShowPlanTreeToExecutionPlanTree).ToList(),
Edges = currentNode.Edges.Select(ConvertShowPlanEdgeToExecutionPlanEdge).ToList(),
Badges = GenerateNodeOverlay(currentNode),
Name = currentNode.DisplayName,
ElapsedTimeInMs = currentNode.ElapsedTimeInMs,

View File

@@ -599,7 +599,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
{
if (currentList != null &&
token != null && !string.IsNullOrWhiteSpace(token.Text) &&
token.Text.All(ch => char.IsLetter(ch)) &&
token.Text.All(char.IsLetter) &&
currentList.All(x => string.Compare(x.Label, token.Text, true) != 0
))
{

View File

@@ -1,5 +1,5 @@
// WARNING:
// This file was generated by the Microsoft DataWarehouse String Resource Tool 6.0.0.0
// This file was generated by the Microsoft DataWarehouse String Resource Tool 7.0.0.0
// from information in sr.strings
// DO NOT MODIFY THIS FILE'S CONTENTS, THEY WILL BE OVERWRITTEN
//

View File

@@ -13,6 +13,8 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PreserveCompilationContext>true</PreserveCompilationContext>
<RuntimeIdentifiers>$(ToolsServiceTargetRuntimes)</RuntimeIdentifiers>
<!-- TODO FIX THESE WARNINGS ASAP -->
<NoWarn>$(NoWarn);SYSLIB1045;CA1311;CA1854;CS8600;CS8603;CS8625</NoWarn>
</PropertyGroup>
<PropertyGroup>

View File

@@ -63,7 +63,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
public ObjectExplorerService()
{
sessionMap = new ConcurrentDictionary<string, ObjectExplorerSession>();
applicableNodeChildFactories = new Lazy<Dictionary<string, HashSet<ChildFactory>>>(() => PopulateFactories());
applicableNodeChildFactories = new Lazy<Dictionary<string, HashSet<ChildFactory>>>(PopulateFactories);
NodePathGenerator.Initialize();
}

View File

@@ -118,7 +118,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return;
}
IEnumerable<SmoQuerier> queriers = context.ServiceProvider.GetServices<SmoQuerier>(q => IsCompatibleQuerier(q));
IEnumerable<SmoQuerier> queriers = context.ServiceProvider.GetServices<SmoQuerier>(IsCompatibleQuerier);
var filters = this.Filters.ToList();
var smoProperties = this.SmoProperties.Where(p => ServerVersionHelper.IsValidFor(serverValidFor, p.ValidFor)).Select(x => x.Name);
if (!string.IsNullOrEmpty(name))

View File

@@ -11,6 +11,7 @@ using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;
using System.Diagnostics;
using System.Threading.Tasks;
namespace Microsoft.SqlTools.ServiceLayer
{
@@ -22,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer
/// <summary>
/// Main entry point into the SQL Tools API Service Layer
/// </summary>
internal static void Main(string[] args)
internal static async Task Main(string[] args)
{
SqlClientListener? sqlClientListener = null;
try
@@ -61,7 +62,7 @@ namespace Microsoft.SqlTools.ServiceLayer
ProcessExitTimer.Start(commandOptions.ParentProcessId.Value);
}
serviceHost.WaitForExit();
await serviceHost.WaitForExitAsync();
}
catch (Exception ex)
{

View File

@@ -231,7 +231,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
//Run Task synchronously
public void Run()
{
Task.Run(() => RunAsync());
Task.Run(RunAsync);
}
/// <summary>

View File

@@ -12,7 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode;
namespace Microsoft.SqlTools.ManagedBatchParser.UnitTests.BatchParser
{
internal class BatchParserMockEventHandler : IBatchEventsHandler
public class BatchParserMockEventHandler : IBatchEventsHandler
{
public SqlError Error { get; private set; }

View File

@@ -54,7 +54,7 @@ namespace Microsoft.SqlTools.ManagedBatchParser.UnitTests.BatchParser
p.ThrowOnUnresolvedVariable = true;
handler.SetParser(p);
Assert.Throws<BatchParserException>(() => p.Parse());
Assert.Throws<BatchParserException>(p.Parse);
}
}
@@ -77,7 +77,7 @@ namespace Microsoft.SqlTools.ManagedBatchParser.UnitTests.BatchParser
{
p.ThrowOnUnresolvedVariable = true;
handler.SetParser(p);
Assert.Throws<BatchParserException>(() => p.Parse());
Assert.Throws<BatchParserException>(p.Parse);
}
}
@@ -98,7 +98,7 @@ namespace Microsoft.SqlTools.ManagedBatchParser.UnitTests.BatchParser
{
p.ThrowOnUnresolvedVariable = true;
handler.SetParser(p);
Assert.Throws<BatchParserException>(() => p.Parse());
Assert.Throws<BatchParserException>(p.Parse);
}
}
@@ -119,7 +119,7 @@ namespace Microsoft.SqlTools.ManagedBatchParser.UnitTests.BatchParser
{
p.ThrowOnUnresolvedVariable = true;
handler.SetParser(p);
Assert.Throws<BatchParserException>(() => p.Parse());
Assert.Throws<BatchParserException>(p.Parse);
}
}
@@ -142,7 +142,7 @@ namespace Microsoft.SqlTools.ManagedBatchParser.UnitTests.BatchParser
handler.SetParser(p);
// This test will fail because we are passing invalid number.
// Exception will be raised from ParseGo()
Assert.Throws<BatchParserException>(() => p.Parse());
Assert.Throws<BatchParserException>(p.Parse);
}
}
@@ -248,7 +248,7 @@ namespace Microsoft.SqlTools.ManagedBatchParser.UnitTests.BatchParser
p.ThrowOnUnresolvedVariable = true;
handler.SetParser(p);
var exception = Assert.Throws<BatchParserException>(() => p.Parse());
var exception = Assert.Throws<BatchParserException>(p.Parse);
// Verify the message should be "Command Execute is not supported."
Assert.AreEqual("Command Execute is not supported.", exception.Message);
}

View File

@@ -13,7 +13,7 @@ using Microsoft.SqlTools.ServiceLayer.BatchParser;
namespace Microsoft.SqlTools.ManagedBatchParser.UnitTests.BatchParser
{
internal class TestCommandHandler : ICommandHandler
public class TestCommandHandler : ICommandHandler
{
private Parser parser;
private StringBuilder outputString;

View File

@@ -12,7 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode;
namespace Microsoft.SqlTools.ManagedBatchParser.IntegrationTests.TSQLExecutionEngine
{
internal class BatchEventHandler : IBatchEventsHandler
public class BatchEventHandler : IBatchEventsHandler
{
private List<int> resultCounts = new List<int>();
private List<string> sqlMessages = new List<string>();

View File

@@ -14,7 +14,7 @@ using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ManagedBatchParser.IntegrationTests.TSQLExecutionEngine
{
internal class TestExecutor : IDisposable
public class TestExecutor : IDisposable
{
#region Private variables

View File

@@ -9,7 +9,7 @@ using System.IO;
namespace Microsoft.SqlTools.ManagedBatchParser.IntegrationTests.Utility
{
internal class FileUtilities
public class FileUtilities
{
/// <summary>
/// Turns off the read-only attribute for this file

View File

@@ -6,6 +6,8 @@
<PackageId>Microsoft.SqlTools.ServiceLayer.IntegrationTests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
<!-- TODO FIX THESE WARNINGS ASAP -->
<NoWarn>$(NoWarn);SYSLIB1045;IDE0200;IDE0230;CA1311;CA1852;CA1854</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Microsoft.SqlTools.Hosting/Microsoft.SqlTools.Hosting.csproj" />

View File

@@ -9,7 +9,7 @@ using System;
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
{
internal class ComparisonFailureException : InvalidOperationException
internal sealed class ComparisonFailureException : InvalidOperationException
{
internal string FullMessageWithDiff { get; private set; }
internal string EditAndCopyMessage { get; private set; }

View File

@@ -180,14 +180,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking
Event
}
private class ExpectedEvent
private sealed class ExpectedEvent
{
public EventTypes EventType { get; set; }
public Type ParamType { get; set; }
public Delegate Validator { get; set; }
}
private class ReceivedEvent
private sealed class ReceivedEvent
{
public object EventObject { get; set; }
public EventTypes EventType { get; set; }

View File

@@ -45,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Driver
// Include a fallback value to for running tests within visual studio
serviceHostExecutable =
@"..\..\..\..\..\src\Microsoft.SqlTools.ServiceLayer\bin\Debug\net6.0\win-x64\MicrosoftSqlToolsServiceLayer.exe";
@"..\..\..\..\..\src\Microsoft.SqlTools.ServiceLayer\bin\Debug\net7.0\win-x64\MicrosoftSqlToolsServiceLayer.exe";
if (!File.Exists(serviceHostExecutable))
{
serviceHostExecutable = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "MicrosoftSqlToolsServiceLayer.exe");

View File

@@ -13,7 +13,7 @@ using System.Collections.Generic;
namespace Microsoft.SqlTools.ServiceLayer.TestEnvConfig
{
class Program
sealed class Program
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0210:Convert to top-level statements", Justification = "Structure retained for readability.")]
static void Main(string[] args)

View File

@@ -5,7 +5,9 @@
<DefineConstants>$(DefineConstants);NETCOREAPP1_0;TRACE</DefineConstants>
<IsPackable>false</IsPackable>
<ApplicationIcon />
<StartupObject />
<StartupObject />
<!-- TODO FIX THESE WARNINGS ASAP -->
<NoWarn>$(NoWarn);SYSLIB1045;IDE0200;IDE0230;CA1311;CA1852;CA1854</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" />

View File

@@ -11,21 +11,20 @@ using System.Text.RegularExpressions;
namespace ScriptGenerator
{
class Program
public partial class Program
{
internal const string DefaultFileExtension = "Sql";
static readonly Regex ExtractDbName = new Regex(@"CREATE\s+DATABASE\s+\[(?<dbName>\w+)\]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
static readonly Regex CreateTableRegex = new Regex(@"(?<begin>CREATE\s+TABLE\s+.*)(?<middle>\](?![\.])[\s\S]*?CONSTRAINT\s+\[\w+?)(?<end>\](?![\.]))", RegexOptions.Compiled | RegexOptions.IgnoreCase);
static readonly Regex AlterTableConstraintRegex = new Regex(@"(?<begin>ALTER\s+TABLE\s+.*?)(?<middle>\](?![\.])\s*\b(?:ADD|WITH|CHECK)\b[\s\S]*?CONSTRAINT\s+\[\w+?)(?<end>\](?![\.]))", RegexOptions.Compiled | RegexOptions.IgnoreCase);
static readonly Regex CreateViewRegex = new Regex(@"(?<begin>CREATE\s+VIEW\s+.*?)(?<end>\](?![\.])[\s\S]*?\bAS\b)", RegexOptions.Compiled | RegexOptions.IgnoreCase );
static readonly Regex CreateProcedureRegex = new Regex(@"(?<begin>CREATE\s+PROCEDURE\s+.*?)(?<end>\](?![\.])[\s\S]*?(?:@|WITH|AS))", RegexOptions.Compiled | RegexOptions.IgnoreCase);
static readonly Regex ExtractDbName = CreateDbRegex();
static readonly Regex CreateTableRegex = CreateTableSyntaxRegex();
static readonly Regex AlterTableConstraintRegex = AlterTableSyntaxRegex();
static readonly Regex CreateViewRegex = CreateViewSyntaxRegex();
static readonly Regex CreateProcedureRegex = CreateProcedureSyntaxRegex();
static void Main(string[] args)
{
CommandOptions options = new CommandOptions(args);
var options = new CommandOptions(args);
for (int d = 1; d <= options.Databases; d++)
{
using (StreamWriter writer = new StreamWriter(Path.ChangeExtension($@"{options.FilePathPrefix}{d}", DefaultFileExtension)))
using (var writer = new StreamWriter(Path.ChangeExtension($@"{options.FilePathPrefix}{d}", DefaultFileExtension)))
{
string oldDbName = ExtractDbName.Match(Resources.AdventureWorks).Groups["dbName"].Value;
string newDbName = $@"{oldDbName}{d}";
@@ -59,5 +58,16 @@ namespace ScriptGenerator
}
}
}
[GeneratedRegex("CREATE\\s+DATABASE\\s+\\[(?<dbName>\\w+)\\]", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-CA")]
private static partial Regex CreateDbRegex();
[GeneratedRegex("(?<begin>CREATE\\s+TABLE\\s+.*)(?<middle>\\](?![\\.])[\\s\\S]*?CONSTRAINT\\s+\\[\\w+?)(?<end>\\](?![\\.]))", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-CA")]
private static partial Regex CreateTableSyntaxRegex();
[GeneratedRegex("(?<begin>ALTER\\s+TABLE\\s+.*?)(?<middle>\\](?![\\.])\\s*\\b(?:ADD|WITH|CHECK)\\b[\\s\\S]*?CONSTRAINT\\s+\\[\\w+?)(?<end>\\](?![\\.]))", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-CA")]
private static partial Regex AlterTableSyntaxRegex();
[GeneratedRegex("(?<begin>CREATE\\s+VIEW\\s+.*?)(?<end>\\](?![\\.])[\\s\\S]*?\\bAS\\b)", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-CA")]
private static partial Regex CreateViewSyntaxRegex();
[GeneratedRegex("(?<begin>CREATE\\s+PROCEDURE\\s+.*?)(?<end>\\](?![\\.])[\\s\\S]*?(?:@|WITH|AS))", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-CA")]
private static partial Regex CreateProcedureSyntaxRegex();
}
}