public void AddSubscription(string collectionName, string projectId) { //TODO: handle error var subscription = new SubscriptionRequest(projectId, new Uri("http://localhost:4567/build-event")); var uriSuffix = ($"{collectionName}/_apis/hooks/subscriptions/?api-version=1.0"); _tfsConnector.SendPost <Object>(uriSuffix, subscription.ToJson()); }
/// <summary>EdgeOS requires a subscription on its WebSocket for anything to be sent to it, this method will request a subscription to start seeing requested events.</summary> /// <param name="subscriptionRequest">The event types to subscribe/unsubscribe.</param> public async void SubscribeForEvents(SubscriptionRequest subscriptionRequest) { // We need the SubscriptionMessage in JSON format. string subscriptionRequestJson = subscriptionRequest.ToJson(); // The client web socket is expecting bytes and we also need to include the subscription message length. ArraySegment <byte> bytesToSend = new ArraySegment <byte>(Encoding.UTF8.GetBytes(subscriptionRequestJson.Length + "\r\n" + subscriptionRequestJson)); // Send to the EdgeOS device our request. await _clientWebSocket.SendAsync(bytesToSend, WebSocketMessageType.Text, true, _cancellationTokenSource.Token); // Listen for messages being received due to this subscription. BeginReceive(); }