public async Task TestActivateDeactivateEndpointAsync() { using (var harness = new TwinModuleFixture()) { await harness.RunTestAsync(async (device, module, services) => { // Setup var supervisorId = SupervisorModelEx.CreateSupervisorId(device, module); var activation = services.Resolve <IEndpointActivation>(); var hub = services.Resolve <IIoTHubTwinServices>(); var twin = new EndpointInfoModel { Registration = new EndpointRegistrationModel { Endpoint = new EndpointModel { Url = "opc.tcp://test" }, SupervisorId = supervisorId }, ApplicationId = "ua326029342304923" }.ToEndpointRegistration(_serializer).ToDeviceTwin(_serializer); await hub.CreateAsync(twin); var registry = services.Resolve <IEndpointRegistry>(); var endpoints = await registry.ListAllEndpointsAsync(); var ep1 = endpoints.FirstOrDefault(); Assert.NotNull(ep1); // Act await activation.ActivateEndpointAsync(ep1.Registration.Id); endpoints = await registry.ListAllEndpointsAsync(); var ep2 = endpoints.FirstOrDefault(); await activation.DeactivateEndpointAsync(ep2.Registration.Id); var diagnostics = services.Resolve <ISupervisorDiagnostics>(); endpoints = await registry.ListAllEndpointsAsync(); var ep3 = endpoints.FirstOrDefault(); var status = await diagnostics.GetSupervisorStatusAsync(supervisorId); // Assert Assert.Equal(device, status.DeviceId); Assert.Equal(module, status.ModuleId); Assert.Null(status.SiteId); Assert.Empty(status.Endpoints); Assert.Equal(EndpointActivationState.Deactivated, ep3.ActivationState); Assert.Equal(EndpointConnectivityState.Disconnected, ep3.EndpointState); }); } }
/// <summary> /// Activate /// </summary> /// <param name="endpoint"></param> /// <returns></returns> public EndpointRegistrationModel RegisterAndActivateTwinId(EndpointRegistrationModel endpoint) { var twin = new EndpointInfoModel { Registration = endpoint, ApplicationId = "uas" + Guid.NewGuid().ToString() }.ToEndpointRegistration().ToDeviceTwin(); var result = _hub.CreateAsync(twin).Result; var registry = HubContainer.Resolve <IEndpointRegistry>(); var endpoints = registry.ListAllEndpointsAsync().Result; var ep1 = endpoints.FirstOrDefault(); if (ep1.ActivationState == EndpointActivationState.Deactivated) { // Activate registry.ActivateEndpointAsync(ep1.Registration.Id).Wait(); } return(ep1.Registration); }
/// <inheritdoc/> public Task OnEndpointUpdatedAsync(RegistryOperationContextModel context, EndpointInfoModel endpoint) { Console.WriteLine($"Updated {endpoint.Registration.Id}"); return(Task.CompletedTask); }
/// <inheritdoc/> public Task OnEndpointDeletedAsync(RegistryOperationContextModel context, EndpointInfoModel endpoint) { return(Task.CompletedTask); }
/// <inheritdoc/> public Task OnEndpointDeletedAsync(RegistryOperationContextModel context, EndpointInfoModel endpoint) { return(RemoveAllRequestsForEntityAsync(endpoint.Registration.Id, context)); }
/// <summary> /// Create endpoint event /// </summary> /// <param name="type"></param> /// <param name="context"></param> /// <param name="endpoint"></param> /// <returns></returns> private static EndpointEventModel Wrap(EndpointEventType type, RegistryOperationContextModel context, EndpointInfoModel endpoint) { return(new EndpointEventModel { EventType = type, Context = context, Endpoint = endpoint }); }
/// <inheritdoc/> public Task OnEndpointUpdatedAsync( RegistryOperationContextModel context, EndpointInfoModel endpoint) { return(_bus.PublishAsync(Wrap(EndpointEventType.Updated, context, endpoint))); }
/// <inheritdoc/> public Task OnEndpointDeletedAsync(RegistryOperationContextModel context, string endpointId, EndpointInfoModel endpoint) { Console.WriteLine($"Deleted {endpointId}"); return(Task.CompletedTask); }
/// <inheritdoc/> public Task OnEndpointNewAsync( RegistryOperationContextModel context, EndpointInfoModel endpoint) { return(_bus.PublishAsync(Wrap(EndpointEventType.New, context, endpoint.Registration.Id, endpoint))); }