mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
handling database info and metadata request async (#541)
This commit is contained in:
@@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||||
{
|
{
|
||||||
@@ -143,21 +144,31 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
RequestContext<GetDatabaseInfoResponse> requestContext)
|
RequestContext<GetDatabaseInfoResponse> requestContext)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo;
|
Func<Task> requestHandler = async () =>
|
||||||
AdminService.ConnectionServiceInstance.TryFindConnection(
|
|
||||||
databaseParams.OwnerUri,
|
|
||||||
out connInfo);
|
|
||||||
DatabaseInfo info = null;
|
|
||||||
|
|
||||||
if (connInfo != null)
|
|
||||||
{
|
{
|
||||||
info = GetDatabaseInfo(connInfo);
|
ConnectionInfo connInfo;
|
||||||
}
|
AdminService.ConnectionServiceInstance.TryFindConnection(
|
||||||
|
databaseParams.OwnerUri,
|
||||||
|
out connInfo);
|
||||||
|
DatabaseInfo info = null;
|
||||||
|
|
||||||
await requestContext.SendResult(new GetDatabaseInfoResponse(){
|
if (connInfo != null)
|
||||||
DatabaseInfo = info
|
{
|
||||||
|
info = GetDatabaseInfo(connInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
await requestContext.SendResult(new GetDatabaseInfoResponse()
|
||||||
|
{
|
||||||
|
DatabaseInfo = info
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Task task = Task.Run(async () => await requestHandler()).ContinueWithOnFaulted(async t =>
|
||||||
|
{
|
||||||
|
await requestContext.SendError(t.Exception.ToString());
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using Microsoft.SqlTools.Hosting.Protocol;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Metadata.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Metadata.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Metadata
|
namespace Microsoft.SqlTools.ServiceLayer.Metadata
|
||||||
{
|
{
|
||||||
@@ -66,23 +67,31 @@ namespace Microsoft.SqlTools.ServiceLayer.Metadata
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo;
|
Func<Task> requestHandler = async () =>
|
||||||
MetadataService.ConnectionServiceInstance.TryFindConnection(
|
|
||||||
metadataParams.OwnerUri,
|
|
||||||
out connInfo);
|
|
||||||
|
|
||||||
var metadata = new List<ObjectMetadata>();
|
|
||||||
if (connInfo != null)
|
|
||||||
{
|
|
||||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connInfo, "Metadata"))
|
|
||||||
{
|
|
||||||
ReadMetadata(sqlConn, metadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await requestContext.SendResult(new MetadataQueryResult
|
|
||||||
{
|
{
|
||||||
Metadata = metadata.ToArray()
|
ConnectionInfo connInfo;
|
||||||
|
MetadataService.ConnectionServiceInstance.TryFindConnection(
|
||||||
|
metadataParams.OwnerUri,
|
||||||
|
out connInfo);
|
||||||
|
|
||||||
|
var metadata = new List<ObjectMetadata>();
|
||||||
|
if (connInfo != null)
|
||||||
|
{
|
||||||
|
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connInfo, "Metadata"))
|
||||||
|
{
|
||||||
|
ReadMetadata(sqlConn, metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await requestContext.SendResult(new MetadataQueryResult
|
||||||
|
{
|
||||||
|
Metadata = metadata.ToArray()
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Task task = Task.Run(async () => await requestHandler()).ContinueWithOnFaulted(async t =>
|
||||||
|
{
|
||||||
|
await requestContext.SendError(t.Exception.ToString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user