Skip to content

Commit

Permalink
Disconnect session (microsoft#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrenmsft authored Jan 17, 2019
1 parent 5f6d500 commit 7cc2636
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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");
}
}
22 changes: 21 additions & 1 deletion src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void InitializeService(ServiceHost serviceHost)
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);
}
Expand Down Expand Up @@ -147,7 +148,7 @@ await Task.Run(async () =>
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.
Expand Down Expand Up @@ -314,6 +315,25 @@ await Task.Run(async () =>
});
}

/// <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>
Expand Down

0 comments on commit 7cc2636

Please # to comment.