//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
using Microsoft.SqlTools.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
{
///
/// Helper class to send events to the client
///
public class DocumentStatusHelper
{
public const string DefinitionRequested = "DefinitionRequested";
public const string DefinitionRequestCompleted = "DefinitionRequestCompleted";
///
/// Sends an event for specific document using the existing request context
///
public static void SendStatusChange(RequestContext requestContext, TextDocumentPosition textDocumentPosition, string status)
{
Task.Factory.StartNew(async () =>
{
if (requestContext != null)
{
string ownerUri = textDocumentPosition != null && textDocumentPosition.TextDocument != null ? textDocumentPosition.TextDocument.Uri : "";
await requestContext.SendEvent(StatusChangedNotification.Type, new StatusChangeParams()
{
OwnerUri = ownerUri,
Status = status
});
}
});
}
///
/// Sends a telemetry event for specific document using the existing request context
///
public static void SendTelemetryEvent(RequestContext requestContext, string telemetryEvent)
{
Validate.IsNotNull(nameof(requestContext), requestContext);
Validate.IsNotNullOrWhitespaceString(nameof(telemetryEvent), telemetryEvent);
Task.Factory.StartNew(async () =>
{
await requestContext.SendEvent(TelemetryNotification.Type, new TelemetryParams()
{
Params = new TelemetryProperties
{
EventName = telemetryEvent
}
});
});
}
///
/// Sends a telemetry event for specific document using the existing request context
///
public static void SendTelemetryEvent(RequestContext requestContext, TelemetryProperties telemetryProps)
{
Validate.IsNotNull(nameof(requestContext), requestContext);
Validate.IsNotNull(nameof(telemetryProps), telemetryProps);
Validate.IsNotNullOrWhitespaceString("telemetryProps.EventName", telemetryProps.EventName);
Task.Factory.StartNew(async () =>
{
await requestContext.SendEvent(TelemetryNotification.Type, new TelemetryParams()
{
Params = telemetryProps
});
});
}
}
}