コード例 #1
0
        public async Task <Guid?> Handle(CreateDHCPv6InterfaceListenerCommand request, CancellationToken cancellationToken)
        {
            _logger.LogDebug("Handle started");

            DHCPv6Listener listener = DHCPv6Listener.Create(
                request.NicId,
                DHCPListenerName.FromString(request.Name),
                IPv6Address.FromString(request.IPv6Addres));

            var possibleListeners = _interfaceEngine.GetPossibleListeners();

            if (possibleListeners.Count(x => x.Address == listener.Address && x.PhysicalInterfaceId == listener.PhysicalInterfaceId) == 0)
            {
                return(null);
            }

            var activeListeners = await _interfaceEngine.GetActiveListeners();

            if (activeListeners.Count(x => x.Address == listener.Address && x.PhysicalInterfaceId == listener.PhysicalInterfaceId) > 0)
            {
                return(null);
            }

            if (await _storageEngine.Save(listener) == false)
            {
                return(null);
            }

            _interfaceEngine.OpenListener(listener);

            return(listener.Id);
        }
コード例 #2
0
        public void Create()
        {
            Random      random        = new Random();
            String      interfaceId   = random.NextGuid().ToString();
            IPv6Address address       = random.GetIPv6Address();
            String      interfaceName = random.GetAlphanumericString();

            DHCPv6Listener listener = DHCPv6Listener.Create(interfaceId, DHCPListenerName.FromString(interfaceName), address);

            Assert.NotNull(listener);

            Assert.NotEqual(Guid.Empty, listener.Id);
            Assert.Equal(address, listener.Address);
            Assert.Equal(interfaceName, listener.Name);
            Assert.Equal(interfaceId, listener.PhysicalInterfaceId);

            var @event = GetFirstEvent <DHCPListenerCreatedEvent>(listener);

            Assert.Equal(address.ToString(), @event.Address);
            Assert.Equal(listener.Id, @event.Id);
            Assert.Equal(interfaceId, @event.InterfaceId);
            Assert.Equal(interfaceName, @event.Name);
        }