Disconnect session (#764)

This commit is contained in:
Alan Ren
2019-01-16 22:03:18 -08:00
committed by GitHub
parent 5f6d500977
commit 7cc2636e6a
2 changed files with 56 additions and 1 deletions

View File

@@ -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
{
/// <summary>
/// Disconnect Session request parameters
/// </summary>
public class DisconnectSessionParams : GeneralRequestDetails
{
public string OwnerUri { get; set; }
}
public class DisconnectSessionResult { }
/// <summary>
/// Disconnect session request type
/// </summary>
public class DisconnectSessionRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly
RequestType<DisconnectSessionParams, DisconnectSessionResult> Type =
RequestType<DisconnectSessionParams, DisconnectSessionResult>.Create("profiler/disconnect");
}
}

View File

@@ -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
});
}
/// <summary>
/// Handle request to disconnect a session
/// </summary>
internal async Task HandleDisconnectSessionRequest(DisconnectSessionParams parameters, RequestContext<DisconnectSessionResult> requestContext)
{
await Task.Run(async () =>
{
try
{
ProfilerSession session;
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
}
catch (Exception e)
{
await requestContext.SendError(e);
}
});
}
/// <summary>
/// Gets a list of all running XEvent Sessions
/// </summary>