diff --git a/src/Microsoft.SqlTools.ServiceLayer/HostLoader.cs b/src/Microsoft.SqlTools.ServiceLayer/HostLoader.cs
index 084341dd..e1cb2705 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/HostLoader.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/HostLoader.cs
@@ -166,6 +166,9 @@ namespace Microsoft.SqlTools.ServiceLayer
InitializeHostedServices(serviceProvider, serviceHost);
serviceHost.ServiceProvider = serviceProvider;
+ ShowPlan.ExecutionPlanService.Instance.InitializeService(serviceHost);
+ serviceProvider.RegisterSingleService(ShowPlan.ExecutionPlanService.Instance);
+
serviceHost.InitializeRequestHandlers();
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/Contracts/ExecutionPlanGraph.cs b/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/Contracts/ExecutionPlanGraph.cs
index d5f6702a..0f5adc79 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/Contracts/ExecutionPlanGraph.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/Contracts/ExecutionPlanGraph.cs
@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
///
/// Graph file that used to generate ExecutionPlanGraph
///
- public ExecutionPlanGraphFile GraphFile { get; set; }
+ public ExecutionPlanGraphInfo GraphFile { get; set; }
///
/// Index recommendations given by show plan to improve query performance
///
@@ -146,7 +146,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
public string QueryWithDescription { get; set; }
}
- public class ExecutionPlanGraphFile
+ public class ExecutionPlanGraphInfo
{
///
/// File contents
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/Contracts/GetExecutionPlanRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/Contracts/GetExecutionPlanRequest.cs
new file mode 100644
index 00000000..3d3e5286
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/Contracts/GetExecutionPlanRequest.cs
@@ -0,0 +1,27 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System.Collections.Generic;
+using Microsoft.SqlTools.Hosting.Protocol.Contracts;
+
+namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
+{
+ public class GetExecutionPlanParams
+ {
+ public ExecutionPlanGraphInfo GraphInfo { get; set; }
+ }
+
+ public class GetExecutionPlanResult
+ {
+ public List Graphs { get; set; }
+ }
+
+ public class GetExecutionPlanRequest
+ {
+ public static readonly
+ RequestType Type =
+ RequestType.Create("queryexecutionplan/getexecutionplan");
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ShowPlanService.cs b/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ExecutionPlanService.cs
similarity index 59%
rename from src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ShowPlanService.cs
rename to src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ExecutionPlanService.cs
index 79b30c10..f83ed44c 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ShowPlanService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ExecutionPlanService.cs
@@ -4,6 +4,7 @@
//
using System;
+using System.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Hosting;
@@ -12,23 +13,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
///
/// Main class for Migration Service functionality
///
- public sealed class ShowPlanService : IDisposable
+ public sealed class ExecutionPlanService : IDisposable
{
- private static readonly Lazy instance = new Lazy(() => new ShowPlanService());
+ private static readonly Lazy instance = new Lazy(() => new ExecutionPlanService());
private bool disposed;
///
/// Construct a new MigrationService instance with default parameters
///
- public ShowPlanService()
+ public ExecutionPlanService()
{
}
///
/// Gets the singleton instance object
///
- public static ShowPlanService Instance
+ public static ExecutionPlanService Instance
{
get { return instance.Value; }
}
@@ -49,6 +50,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
public void InitializeService(ServiceHost serviceHost)
{
this.ServiceHost = serviceHost;
+ this.ServiceHost.SetRequestHandler(GetExecutionPlanRequest.Type, HandleGetExecutionPlan);
+ }
+
+ private async Task HandleGetExecutionPlan(GetExecutionPlanParams requestParams, RequestContext requestContext)
+ {
+ try
+ {
+ var plans = ShowPlanGraphUtils.CreateShowPlanGraph(requestParams.GraphInfo.GraphFileContent, "");
+ await requestContext.SendResult(new GetExecutionPlanResult
+ {
+ Graphs = plans
+ });
+ }
+ catch (Exception e)
+ {
+ await requestContext.SendError(e.ToString());
+ }
}
///
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ShowPlanGraphUtils.cs b/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ShowPlanGraphUtils.cs
index 43d59f43..8a8ea687 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ShowPlanGraphUtils.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ShowPlan/ShowPlanGraphUtils.cs
@@ -22,7 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ShowPlan
{
Root = ConvertShowPlanTreeToExecutionPlanTree(g.Root),
Query = g.Statement,
- GraphFile = new ExecutionPlanGraphFile
+ GraphFile = new ExecutionPlanGraphInfo
{
GraphFileContent = xml,
GraphFileType = "xml"