mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Get Database Info (#370)
* added get database info to admin service * refactored code to be inline with standard * added comments to utils functions * added comments to public classes * removed camelcase from request type * removed the wrapper for the generic dictionary * removed unnecessary imports
This commit is contained in:
@@ -73,6 +73,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
serviceHost.SetRequestHandler(CreateDatabaseRequest.Type, HandleCreateDatabaseRequest);
|
||||
serviceHost.SetRequestHandler(CreateLoginRequest.Type, HandleCreateLoginRequest);
|
||||
serviceHost.SetRequestHandler(DefaultDatabaseInfoRequest.Type, HandleDefaultDatabaseInfoRequest);
|
||||
serviceHost.SetRequestHandler(GetDatabaseInfoRequest.Type, HandleGetDatabaseInfoRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -131,6 +132,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle get database info request
|
||||
/// </summary>
|
||||
internal static async Task HandleGetDatabaseInfoRequest(
|
||||
GetDatabaseInfoParams databaseParams,
|
||||
RequestContext<GetDatabaseInfoResponse> requestContext)
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
AdminService.ConnectionServiceInstance.TryFindConnection(
|
||||
databaseParams.OwnerUri,
|
||||
out connInfo);
|
||||
DatabaseInfo info = null;
|
||||
|
||||
if (connInfo != null)
|
||||
{
|
||||
info = GetDatabaseInfo(connInfo);
|
||||
}
|
||||
|
||||
await requestContext.SendResult(new GetDatabaseInfoResponse(){
|
||||
Result = info
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return database info for a specific database
|
||||
/// </summary>
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
internal const string MaxDop = "maxDop";
|
||||
internal const string DatabaseContainmentType = "databaseContainmentType";
|
||||
internal const string DatabaseState = "databaseState";
|
||||
internal const string RecoveryModel = "recoveryModel";
|
||||
internal const string FileGroupType = "fileGroupType";
|
||||
internal const string IsDefault = "isDefault";
|
||||
internal const string IsFileStream = "isFileStream";
|
||||
@@ -195,6 +196,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
GroupName = "Other"
|
||||
},
|
||||
new ServiceOption
|
||||
{
|
||||
Name = AdminServicesProviderOptionsHelper.RecoveryModel,
|
||||
DisplayName = "RecoveryModel",
|
||||
Description = "Recovery model",
|
||||
ValueType = ServiceOption.ValueTypeString,
|
||||
IsRequired = false,
|
||||
GroupName = "Other"
|
||||
},
|
||||
new ServiceOption
|
||||
{
|
||||
Name = AdminServicesProviderOptionsHelper.FileGroups,
|
||||
DisplayName = "File Groups",
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Admin.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Params for a get database info request
|
||||
/// </summar>
|
||||
public class GetDatabaseInfoParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Uri identifier for the connection to get the database info for
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response object for get database info
|
||||
/// </summary>
|
||||
public class GetDatabaseInfoResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The object containing the database info
|
||||
/// </summary>
|
||||
public DatabaseInfo Result { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get database info request mapping
|
||||
/// </summary>
|
||||
public class GetDatabaseInfoRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<GetDatabaseInfoParams, GetDatabaseInfoResponse> Type =
|
||||
RequestType<GetDatabaseInfoParams, GetDatabaseInfoResponse>.Create("admin/getdatabaseinfo");
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.Owner, prototype.Owner);
|
||||
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.Collation, prototype.Collation);
|
||||
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.DatabaseState, prototype.DatabaseState.ToString());
|
||||
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.RecoveryModel, prototype.RecoveryModel.ToString());
|
||||
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.IsSystemDB, prototype.IsSystemDB.ToString());
|
||||
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.AnsiNulls, prototype.AnsiNulls.ToString());
|
||||
|
||||
|
||||
@@ -85,5 +85,25 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.AdminServices
|
||||
requestContext.VerifyAll();
|
||||
}
|
||||
|
||||
/// <summmary>
|
||||
/// Get database info test
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetDatabaseInfoTest()
|
||||
{
|
||||
var results = GetLiveAutoCompleteTestObjects();
|
||||
var requestContext = new Mock<RequestContext<GetDatabaseInfoResponse>>();
|
||||
requestContext.Setup(x => x.SendResult(It.IsAny<GetDatabaseInfoResponse>())).Returns(Task.FromResult(new object()));
|
||||
|
||||
var dbParams = new GetDatabaseInfoParams
|
||||
{
|
||||
OwnerUri = results.ConnectionInfo.OwnerUri
|
||||
};
|
||||
|
||||
await AdminService.HandleGetDatabaseInfoRequest(dbParams, requestContext.Object);
|
||||
|
||||
requestContext.VerifyAll();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user