Fix DacFx nullable warnings (#2099)

* cleanup dacfx nullable warnings

* use operation's SqlTask

* remove unneccesary variables
This commit is contained in:
Kim Santiago
2023-06-12 10:50:08 -10:00
committed by GitHub
parent 808172bc20
commit fd0f962056
12 changed files with 23 additions and 45 deletions

View File

@@ -2,6 +2,8 @@
// Copyright (c) Microsoft. All rights reserved. // Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.SqlTools.Hosting.Protocol.Contracts; using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility; using Microsoft.SqlTools.ServiceLayer.Utility;
@@ -21,22 +23,22 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
/// <summary> /// <summary>
/// Gets or sets name for database /// Gets or sets name for database
/// </summary> /// </summary>
public string? DatabaseName { get; set; } public string DatabaseName { get; set; }
/// <summary> /// <summary>
/// Gets or sets target connection string /// Gets or sets target connection string
/// </summary> /// </summary>
public string? ConnectionString { get; set; } public string ConnectionString { get; set; }
/// <summary> /// <summary>
/// Gets or sets SQLCMD variables for deployment /// Gets or sets SQLCMD variables for deployment
/// </summary> /// </summary>
public IDictionary<string, string>? SqlCommandVariableValues { get; set; } public IDictionary<string, string> SqlCommandVariableValues { get; set; }
/// <summary> /// <summary>
/// Gets or sets the options for deployment /// Gets or sets the options for deployment
/// </summary> /// </summary>
public DeploymentOptions? DeploymentOptions { get; set; } public DeploymentOptions DeploymentOptions { get; set; }
} }
/// <summary> /// <summary>

View File

@@ -26,8 +26,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
/// </summary> /// </summary>
class DacFxService class DacFxService
{ {
private static ConnectionService connectionService = null;
private SqlTaskManager sqlTaskManagerInstance = null;
private static readonly Lazy<DacFxService> instance = new Lazy<DacFxService>(() => new DacFxService()); private static readonly Lazy<DacFxService> instance = new Lazy<DacFxService>(() => new DacFxService());
private static Version? serviceVersion = LoadServiceVersion(); private static Version? serviceVersion = LoadServiceVersion();
private const string TelemetryDefaultApplicationName = "sqltoolsservice"; private const string TelemetryDefaultApplicationName = "sqltoolsservice";
@@ -105,7 +103,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
/// Handles request to import a bacpac /// Handles request to import a bacpac
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task HandleImportRequest(ImportParams parameters, RequestContext<DacFxResult> requestContext) public Task HandleImportRequest(ImportParams parameters, RequestContext<DacFxResult> requestContext)
{ {
ConnectionInfo connInfo; ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection( ConnectionServiceInstance.TryFindConnection(
@@ -116,6 +114,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
ImportOperation operation = new ImportOperation(parameters, connInfo); ImportOperation operation = new ImportOperation(parameters, connInfo);
ExecuteOperation(operation, parameters, SR.ImportBacpacTaskName, requestContext); ExecuteOperation(operation, parameters, SR.ImportBacpacTaskName, requestContext);
} }
return Task.CompletedTask;
} }
/// <summary> /// <summary>
@@ -170,7 +169,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
if (connInfo != null) if (connInfo != null)
{ {
GenerateDeployScriptOperation operation = new GenerateDeployScriptOperation(parameters, connInfo); GenerateDeployScriptOperation operation = new GenerateDeployScriptOperation(parameters, connInfo);
SqlTask sqlTask = null;
TaskMetadata metadata = new TaskMetadata(); TaskMetadata metadata = new TaskMetadata();
metadata.TaskOperation = operation; metadata.TaskOperation = operation;
metadata.TaskExecutionMode = parameters.TaskExecutionMode; metadata.TaskExecutionMode = parameters.TaskExecutionMode;
@@ -178,7 +176,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
metadata.DatabaseName = parameters.DatabaseName; metadata.DatabaseName = parameters.DatabaseName;
metadata.Name = SR.GenerateScriptTaskName; metadata.Name = SR.GenerateScriptTaskName;
sqlTask = SqlTaskManagerInstance.CreateAndRun<SqlTask>(metadata); operation.SqlTask = SqlTaskManagerInstance.CreateAndRun<SqlTask>(metadata);
await requestContext.SendResult(new DacFxResult() await requestContext.SendResult(new DacFxResult()
{ {
@@ -201,7 +199,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
out connInfo); out connInfo);
if (connInfo != null) if (connInfo != null)
{ {
await BaseService.RunWithErrorHandling(async () => await BaseService.RunWithErrorHandling(() =>
{ {
GenerateDeployPlanOperation operation = new GenerateDeployPlanOperation(parameters, connInfo); GenerateDeployPlanOperation operation = new GenerateDeployPlanOperation(parameters, connInfo);
operation.Execute(parameters.TaskExecutionMode); operation.Execute(parameters.TaskExecutionMode);
@@ -223,7 +221,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
/// <returns></returns> /// <returns></returns>
public async Task HandleGetOptionsFromProfileRequest(GetOptionsFromProfileParams parameters, RequestContext<DacFxOptionsResult> requestContext) public async Task HandleGetOptionsFromProfileRequest(GetOptionsFromProfileParams parameters, RequestContext<DacFxOptionsResult> requestContext)
{ {
DeploymentOptions options = null; DeploymentOptions? options = null;
if (parameters.ProfilePath != null) if (parameters.ProfilePath != null)
{ {
DacProfile profile = DacProfile.Load(parameters.ProfilePath); DacProfile profile = DacProfile.Load(parameters.ProfilePath);
@@ -366,18 +364,18 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
try try
{ {
// show file location for export and extract operations // show file location for export and extract operations
string targetLocation = (operation is ExportOperation || operation is ExtractOperation) ? parameters.PackageFilePath : null; string? targetLocation = (operation is ExportOperation || operation is ExtractOperation) ? parameters.PackageFilePath : null;
TaskMetadata metadata = TaskMetadata.Create(parameters, taskName, operation, ConnectionServiceInstance, targetLocation); TaskMetadata metadata = TaskMetadata.Create(parameters, taskName, operation, ConnectionServiceInstance, targetLocation);
// put appropriate database name since connection passed was to master // put appropriate database name since connection passed was to master
metadata.DatabaseName = parameters.DatabaseName; metadata.DatabaseName = parameters.DatabaseName;
SqlTask sqlTask = SqlTaskManagerInstance.CreateTask<SqlTask>(metadata); operation.SqlTask = SqlTaskManagerInstance.CreateTask<SqlTask>(metadata);
await sqlTask.RunAsync(); await operation.SqlTask.RunAsync();
await requestContext.SendResult(new DacFxResult() await requestContext.SendResult(new DacFxResult()
{ {
OperationId = operation.OperationId, OperationId = operation.OperationId,
Success = sqlTask.TaskStatus == SqlTaskStatus.Succeeded, Success = operation.SqlTask.TaskStatus == SqlTaskStatus.Succeeded,
ErrorMessage = string.Empty ErrorMessage = string.Empty
}); });
} }
@@ -397,12 +395,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
{ {
get get
{ {
sqlTaskManagerInstance ??= SqlTaskManager.Instance; return SqlTaskManager.Instance;
return sqlTaskManagerInstance;
}
set
{
sqlTaskManagerInstance = value;
} }
} }
@@ -413,12 +406,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
{ {
get get
{ {
connectionService ??= ConnectionService.Instance; return ConnectionService.Instance;
return connectionService;
}
set
{
connectionService = value;
} }
} }
@@ -458,8 +446,8 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
{ {
try try
{ {
string fileVersion = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion; string? fileVersion = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion;
if (Version.TryParse(fileVersion, out Version version)) if (Version.TryParse(fileVersion, out Version? version))
{ {
return version; return version;
} }

View File

@@ -39,7 +39,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
{ {
List<ObjectType> finalExcludeObjects = new List<ObjectType> { }; List<ObjectType> finalExcludeObjects = new List<ObjectType> { };
var val = deployOptionsProp.GetValue(deploymentOptions); var val = deployOptionsProp.GetValue(deploymentOptions);
string[] excludeObjectTypeOptionsArray = (string[])val?.GetType()?.GetProperty("Value")?.GetValue(val); string[]? excludeObjectTypeOptionsArray = (string[]?)val?.GetType()?.GetProperty("Value")?.GetValue(val);
if (excludeObjectTypeOptionsArray != null) if (excludeObjectTypeOptionsArray != null)
{ {

View File

@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using Microsoft.SqlServer.Dac; using Microsoft.SqlServer.Dac;
using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;

View File

@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.Utility; using Microsoft.SqlTools.Utility;

View File

@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using Microsoft.SqlServer.Dac; using Microsoft.SqlServer.Dac;
using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
@@ -34,7 +33,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
public static Version ParseVersion(string incomingVersion) public static Version ParseVersion(string incomingVersion)
{ {
Version parsedVersion; Version? parsedVersion;
if (!Version.TryParse(incomingVersion, out parsedVersion)) if (!Version.TryParse(incomingVersion, out parsedVersion))
{ {
throw new ArgumentException(string.Format(SR.ExtractInvalidVersion, incomingVersion)); throw new ArgumentException(string.Format(SR.ExtractInvalidVersion, incomingVersion));

View File

@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using Microsoft.SqlServer.Dac; using Microsoft.SqlServer.Dac;
using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
@@ -18,7 +17,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
{ {
public GenerateDeployPlanParams Parameters { get; } public GenerateDeployPlanParams Parameters { get; }
public string DeployReport { get; set; } public string? DeployReport { get; set; }
public GenerateDeployPlanOperation(GenerateDeployPlanParams parameters, ConnectionInfo connInfo): base(connInfo) public GenerateDeployPlanOperation(GenerateDeployPlanParams parameters, ConnectionInfo connInfo): base(connInfo)
{ {

View File

@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using Microsoft.SqlServer.Dac; using Microsoft.SqlServer.Dac;
@@ -21,7 +20,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
{ {
public GenerateDeployScriptParams Parameters { get; } public GenerateDeployScriptParams Parameters { get; }
public PublishResult Result { get; set; } public PublishResult? Result { get; set; }
public GenerateDeployScriptOperation(GenerateDeployScriptParams parameters, ConnectionInfo connInfo) : base(connInfo) public GenerateDeployScriptOperation(GenerateDeployScriptParams parameters, ConnectionInfo connInfo) : base(connInfo)
{ {

View File

@@ -3,8 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;

View File

@@ -3,8 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using System; using System;
using System.Linq; using System.Linq;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;

View File

@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
using Microsoft.SqlServer.Dac; using Microsoft.SqlServer.Dac;
using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;

View File

@@ -3,8 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
#nullable disable
extern alias ASAScriptDom; extern alias ASAScriptDom;
using System; using System;