diff --git a/src/Microsoft.SqlTools.ServiceLayer/Profiler/Contracts/DisconnectSessionRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/Profiler/Contracts/DisconnectSessionRequest.cs
new file mode 100644
index 00000000..8721fcfb
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/Profiler/Contracts/DisconnectSessionRequest.cs
@@ -0,0 +1,35 @@
+//
+// 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;
+using Microsoft.SqlTools.ServiceLayer.Utility;
+using Microsoft.SqlTools.Utility;
+using System;
+
+namespace Microsoft.SqlTools.ServiceLayer.Profiler.Contracts
+{
+ ///
+ /// Disconnect Session request parameters
+ ///
+ public class DisconnectSessionParams : GeneralRequestDetails
+ {
+ public string OwnerUri { get; set; }
+ }
+
+ public class DisconnectSessionResult { }
+
+ ///
+ /// Disconnect session request type
+ ///
+ public class DisconnectSessionRequest
+ {
+ ///
+ /// Request definition
+ ///
+ public static readonly
+ RequestType Type =
+ RequestType.Create("profiler/disconnect");
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs b/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs
index 516de2de..9bb36ec9 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs
@@ -115,6 +115,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
this.ServiceHost.SetRequestHandler(StopProfilingRequest.Type, HandleStopProfilingRequest);
this.ServiceHost.SetRequestHandler(PauseProfilingRequest.Type, HandlePauseProfilingRequest);
this.ServiceHost.SetRequestHandler(GetXEventSessionsRequest.Type, HandleGetXEventSessionsRequest);
+ this.ServiceHost.SetRequestHandler(DisconnectSessionRequest.Type, HandleDisconnectSessionRequest);
this.SessionMonitor.AddSessionListener(this);
}
@@ -147,7 +148,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
else
{
IXEventSession xeSession = null;
-
+
// first check whether the session with the given name already exists.
// if so skip the creation part. An exception will be thrown if no session with given name can be found,
// and it can be ignored.
@@ -314,6 +315,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
});
}
+ ///
+ /// Handle request to disconnect a session
+ ///
+ internal async Task HandleDisconnectSessionRequest(DisconnectSessionParams parameters, RequestContext requestContext)
+ {
+ await Task.Run(async () =>
+ {
+ try
+ {
+ ProfilerSession session;
+ monitor.StopMonitoringSession(parameters.OwnerUri, out session);
+ }
+ catch (Exception e)
+ {
+ await requestContext.SendError(e);
+ }
+ });
+ }
+
///
/// Gets a list of all running XEvent Sessions
///