// ------------------ CREATE, LIST, AND DELETE EVENT ROUTE (Full sample) --------------------- // <FullEventRouteSample> public static async Task CreateEventRouteAsync(DigitalTwinsClient client, string routeId, DigitalTwinsEventRoute er) { try { Console.WriteLine("Create a route: testRoute1"); // Make a filter that passes everything er.Filter = "true"; await client.CreateOrReplaceEventRouteAsync(routeId, er); Console.WriteLine("Create route succeeded."); // List routes AsyncPageable <DigitalTwinsEventRoute> results = client.GetEventRoutesAsync(); await foreach (DigitalTwinsEventRoute route in results) { Console.WriteLine($"Route {route.Id} to endpoint {route.EndpointName} with filter {route.Filter} "); } // Delete route created earlier Console.WriteLine($"Deleting route {routeId}:"); await client.DeleteEventRouteAsync(routeId); } catch (RequestFailedException e) { Console.WriteLine($"*** Error in event route processing ({e.ErrorCode}):\n${e.Message}"); } }
public async Task EventRoutes_Lifecycle() { // arrange DigitalTwinsClient client = GetClient(); // Ensure unique eventRouteId and endpointName string eventRouteId = $"someEventRouteId-{GetRandom()}"; string filter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'"; var eventRoute = new EventRoute(EndpointName) { Filter = filter }; // Test CreateEventRoute Response createEventRouteResponse = await client.CreateEventRouteAsync(eventRouteId, eventRoute).ConfigureAwait(false); createEventRouteResponse.Status.Should().Be((int)HttpStatusCode.NoContent); // Test GetEventRoute EventRoute getEventRouteResult = await client.GetEventRouteAsync(eventRouteId); eventRoute.EndpointName.Should().Be(getEventRouteResult.EndpointName); eventRoute.Filter.Should().Be(getEventRouteResult.Filter); eventRouteId.Should().Be(getEventRouteResult.Id); // Test GetEventRoutes var eventRoutesListOptions = new EventRoutesListOptions(); AsyncPageable <EventRoute> eventRouteList = client.GetEventRoutesAsync(eventRoutesListOptions); bool eventRouteFoundInList = false; await foreach (EventRoute eventRouteListEntry in eventRouteList) { if (StringComparer.Ordinal.Equals(eventRouteListEntry.Id, eventRouteId)) { eventRouteFoundInList = true; eventRoute.EndpointName.Should().Be(getEventRouteResult.EndpointName); eventRoute.Filter.Should().Be(getEventRouteResult.Filter); break; } } eventRouteFoundInList.Should().BeTrue("Newly created event route should have been present when listing all event routes"); // Test DeleteEventRoute Response deleteEventRouteResponse = await client.DeleteEventRouteAsync(eventRouteId).ConfigureAwait(false); deleteEventRouteResponse.Status.Should().Be((int)HttpStatusCode.NoContent); // Verify event route was deleted by trying to get it again // act Func <Task> act = async() => await client.GetEventRouteAsync(eventRouteId).ConfigureAwait(false); // assert act.Should().Throw <RequestFailedException>() .And.Status.Should().Be((int)HttpStatusCode.NotFound); }
public async Task EventRoutes_Lifecycle() { // arrange DigitalTwinsClient client = GetClient(); // Ensure unique eventRouteId string eventRouteId = $"someEventRouteId-{GetRandom()}"; string filter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'"; var eventRoute = new DigitalTwinsEventRoute(EndpointName, filter); // Test CreateEventRoute Response createEventRouteResponse = await client.CreateOrReplaceEventRouteAsync(eventRouteId, eventRoute).ConfigureAwait(false); createEventRouteResponse.Status.Should().Be((int)HttpStatusCode.NoContent); // Wait certain amount of time to test if the issue is with propagation. // TODO: azabbasi: remove this logic once experiment is over. await WaitIfLiveAsync(_creationDelay); // Test GetEventRoute DigitalTwinsEventRoute getEventRouteResult = await client.GetEventRouteAsync(eventRouteId); eventRoute.EndpointName.Should().Be(getEventRouteResult.EndpointName); eventRoute.Filter.Should().Be(getEventRouteResult.Filter); eventRouteId.Should().Be(getEventRouteResult.Id); // Test GetEventRoutes AsyncPageable <DigitalTwinsEventRoute> eventRouteList = client.GetEventRoutesAsync(); bool eventRouteFoundInList = false; await foreach (DigitalTwinsEventRoute eventRouteListEntry in eventRouteList) { if (StringComparer.Ordinal.Equals(eventRouteListEntry.Id, eventRouteId)) { eventRouteFoundInList = true; eventRoute.EndpointName.Should().Be(getEventRouteResult.EndpointName); eventRoute.Filter.Should().Be(getEventRouteResult.Filter); break; } } eventRouteFoundInList.Should().BeTrue("Newly created event route should have been present when listing all event routes"); // Test DeleteEventRoute Response deleteEventRouteResponse = await client.DeleteEventRouteAsync(eventRouteId).ConfigureAwait(false); deleteEventRouteResponse.Status.Should().Be((int)HttpStatusCode.NoContent); // Verify event route was deleted by trying to get it again // act Func <Task> act = async() => await client.GetEventRouteAsync(eventRouteId).ConfigureAwait(false); // assert act.Should().Throw <RequestFailedException>() .And.Status.Should().Be((int)HttpStatusCode.NotFound); }
/// <summary> /// Gets all event routes for digital Twin /// </summary> public async Task GetEventRoutes() { PrintHeader("LISTING EVENT ROUTES"); try { #region Snippet:DigitalTwinsSampleGetEventRoutes AsyncPageable <EventRoute> response = client.GetEventRoutesAsync(); await foreach (EventRoute er in response) { Console.WriteLine($"Event route: {er.Id}, endpoint name: {er.EndpointName}"); } #endregion Snippet:DigitalTwinsSampleGetEventRoutes } catch (Exception ex) { FatalError($"Could not get event routes due to {ex.Message}"); } }