コード例 #1
0
        public async Task TestPublishEndpointEventAndReceiveMultipleAsync(int total)
        {
            var bus    = _factory.Resolve <IEventBus>();
            var client = _factory.Resolve <IRegistryServiceEvents>();

            var expected = new EndpointEventModel {
                Endpoint = new EndpointInfoModel {
                    ApplicationId   = "TestSigfsdfg  ff",
                    ActivationState = IIoT.OpcUa.Registry.Models.EndpointActivationState.ActivatedAndConnected,
                    NotSeenSince    = DateTime.UtcNow
                }
            };
            var result  = new TaskCompletionSource <bool>();
            var counter = 0;

            await using (await client.SubscribeEndpointEventsAsync(ev => {
                counter++;
                if (counter == total)
                {
                    result.SetResult(true);
                }
                return(Task.CompletedTask);
            })) {
                for (var i = 0; i < total; i++)
                {
                    await bus.PublishAsync(expected);
                }

                await Task.WhenAny(result.Task, Task.Delay(1000));

                Assert.True(result.Task.IsCompleted);
            }
        }
コード例 #2
0
        public async Task TestPublishEndpointEventAndReceiveAsync()
        {
            var bus    = _factory.Resolve <IEventBus>();
            var client = _factory.Resolve <IRegistryServiceEvents>();

            var expected = new EndpointEventModel {
                Endpoint = new EndpointInfoModel {
                    ApplicationId   = "TestSigfsdfg  ff",
                    ActivationState = IIoT.OpcUa.Registry.Models.EndpointActivationState.ActivatedAndConnected,
                    NotSeenSince    = DateTime.UtcNow
                }
            };
            var result = new TaskCompletionSource <EndpointEventApiModel>();

            await using (await client.SubscribeEndpointEventsAsync(ev => {
                result.SetResult(ev);
                return(Task.CompletedTask);
            })) {
                await bus.PublishAsync(expected);

                await Task.WhenAny(result.Task, Task.Delay(1000));

                Assert.True(result.Task.IsCompleted);
                var received = result.Task.Result;
                Assert.NotNull(received?.Endpoint);
                Assert.Equal(expected.Endpoint.NotSeenSince, received.Endpoint.NotSeenSince);
                Assert.Equal(expected.Endpoint.ApplicationId, received.Endpoint.ApplicationId);
                Assert.Equal(expected.Endpoint.ActivationState,
                             (IIoT.OpcUa.Registry.Models.EndpointActivationState)received.Endpoint.ActivationState);
            }
        }
コード例 #3
0
        /// <inheritdoc/>
        public Task HandleAsync(EndpointEventModel eventData)
        {
            var arguments = new object[] { eventData.ToApiModel() };

            return(_callback.BroadcastAsync(
                       EventTargets.EndpointEventTarget, arguments));
        }
コード例 #4
0
 /// <summary>
 /// Convert to api model
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static EndpointEventApiModel ToApiModel(
     this EndpointEventModel model)
 {
     return(new EndpointEventApiModel {
         EventType = (EndpointEventType)model.EventType,
         Endpoint = model.Endpoint.Map <EndpointInfoApiModel>()
     });
 }
コード例 #5
0
        /// <inheritdoc/>
        public Task HandleAsync(EndpointEventModel eventData)
        {
            // Send to supervisor listeners
            var arguments = new object[] { eventData.ToApiModel() };

            return(_callback.MulticastAsync(EventTargets.Endpoints,
                                            EventTargets.EndpointEventTarget, arguments));
        }
コード例 #6
0
 /// <summary>
 /// Convert to api model
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static EndpointEventApiModel ToApiModel(
     this EndpointEventModel model)
 {
     return(new EndpointEventApiModel {
         EventType = (EndpointEventType)model.EventType,
         Id = model.Id,
         Endpoint = model.Endpoint.ToApiModel()
     });
 }