Пример #1
0
        public async Task <Boolean> Handle(UpdateDHCPv6ScopeParentCommand request, CancellationToken cancellationToken)
        {
            _logger.LogDebug("Handle started");

            var scope = _rootScope.GetScopeById(request.ScopeId);

            if (scope == DHCPv6Scope.NotFound)
            {
                return(false);
            }

            if (request.ParentScopeId.HasValue == true)
            {
                if (_rootScope.GetScopeById(request.ParentScopeId.Value) == DHCPv6Scope.NotFound)
                {
                    return(false);
                }
            }

            Boolean moveResult = _rootScope.UpdateParent(request.ScopeId, request.ParentScopeId);

            if (moveResult == true)
            {
                Boolean result = await _store.Save(_rootScope);

                return(result);
            }

            return(false);
        }
Пример #2
0
        public async Task <Boolean> Handle(UpdateDHCPv6ScopeCommand request, CancellationToken cancellationToken)
        {
            _logger.LogDebug("Handle started");

            var scope = _rootScope.GetScopeById(request.ScopeId);

            if (scope == DHCPv6Scope.NotFound)
            {
                return(false);
            }

            Guid?parentId          = scope.HasParentScope() == false ? new Guid?() : scope.ParentScope.Id;
            var  properties        = GetScopeProperties(request);
            var  addressProperties = GetScopeAddressProperties(request);

            if (request.Name != scope.Name)
            {
                _rootScope.UpdateScopeName(request.ScopeId, ScopeName.FromString(request.Name));
            }
            if (request.Description != scope.Description)
            {
                _rootScope.UpdateScopeDescription(request.ScopeId, ScopeDescription.FromString(request.Description));
            }
            if (request.ParentId != parentId)
            {
                _rootScope.UpdateParent(request.ScopeId, request.ParentId);
            }

            _rootScope.UpdateScopeResolver(request.ScopeId, GetResolverInformation(request));

            if (addressProperties != scope.AddressRelatedProperties)
            {
                _rootScope.UpdateAddressProperties(request.ScopeId, addressProperties);
            }

            if (properties != scope.Properties)
            {
                _rootScope.UpdateScopeProperties(request.ScopeId, properties);
            }

            Boolean result = await _store.Save(_rootScope);

            if (result == true)
            {
                var triggers = _rootScope.GetTriggers();

                if (triggers.Any() == true)
                {
                    await _serviceBus.Publish(new NewTriggerHappendMessage(triggers));

                    _rootScope.ClearTriggers();
                }
            }

            return(result);
        }
Пример #3
0
        public async Task SaveAndHydrateRootScope_AddAndChangeScopes()
        {
            Random random = new Random();

            await ExecuteWithStreamErase(random, async (eventStore) =>
            {
                Mock <IDHCPv6ServerPropertiesResolver> propertyResolverMock;
                DHCPv6StorageEngine engine;
                PrepareEngine(random, eventStore, out propertyResolverMock, out engine);

                DHCPv6RootScope initialRootScope = await engine.GetRootScope();

                Guid rootScopeId        = random.NextGuid();
                Guid firstChildScopeId  = random.NextGuid();
                Guid secondChildScopeId = random.NextGuid();

                initialRootScope.AddScope(new DHCPv6ScopeCreateInstruction
                {
                    AddressProperties = new DHCPv6ScopeAddressProperties(
                        IPv6Address.FromString("fe80::0"),
                        IPv6Address.FromString("fe80::ff"),
                        new List <IPv6Address> {
                        IPv6Address.FromString("fe80::1")
                    },
                        preferredLifeTime: TimeSpan.FromDays(0.5),
                        validLifeTime: TimeSpan.FromDays(1),
                        rapitCommitEnabled: true,
                        informsAreAllowd: true,
                        supportDirectUnicast: true,
                        reuseAddressIfPossible: false,
                        acceptDecline: true,
                        t1: DHCPv6TimeScale.FromDouble(0.6),
                        t2: DHCPv6TimeScale.FromDouble(0.8),
                        addressAllocationStrategy: DHCPv6ScopeAddressProperties.AddressAllocationStrategies.Next),
                    ScopeProperties     = DHCPv6ScopeProperties.Empty,
                    ResolverInformation = new CreateScopeResolverInformation
                    {
                        Typename            = nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver),
                        PropertiesAndValues = new Dictionary <String, String>
                        {
                            { nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver.EnterpriseNumber), random.NextUInt16().ToString() },
                            { nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver.RelayAgentIndex), 0.ToString() },
                        }
                    },
                    Name = "Testscope",
                    Id   = rootScopeId,
                });
                initialRootScope.AddScope(new DHCPv6ScopeCreateInstruction
                {
                    AddressProperties = new DHCPv6ScopeAddressProperties(
                        IPv6Address.FromString("fe80::0"),
                        IPv6Address.FromString("fe80::ff"),
                        new List <IPv6Address> {
                        IPv6Address.FromString("fe80::1")
                    }),
                    ScopeProperties     = DHCPv6ScopeProperties.Empty,
                    ResolverInformation = new CreateScopeResolverInformation
                    {
                        Typename            = nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver),
                        PropertiesAndValues = new Dictionary <String, String>
                        {
                            { nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver.EnterpriseNumber), random.NextUInt16().ToString() },
                            { nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver.RelayAgentIndex), 0.ToString() },
                        }
                    },
                    Name     = "First Child Testscope",
                    Id       = firstChildScopeId,
                    ParentId = rootScopeId,
                });
                initialRootScope.AddScope(new DHCPv6ScopeCreateInstruction
                {
                    AddressProperties = new DHCPv6ScopeAddressProperties(
                        IPv6Address.FromString("fe80::0"),
                        IPv6Address.FromString("fe80::ff"),
                        new List <IPv6Address> {
                        IPv6Address.FromString("fe80::1")
                    }),
                    ScopeProperties     = DHCPv6ScopeProperties.Empty,
                    ResolverInformation = new CreateScopeResolverInformation
                    {
                        Typename            = nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver),
                        PropertiesAndValues = new Dictionary <String, String>
                        {
                            { nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver.EnterpriseNumber), random.NextUInt16().ToString() },
                            { nameof(DHCPv6RemoteIdentifierEnterpriseNumberResolver.RelayAgentIndex), 0.ToString() },
                        }
                    },
                    Name     = "Second child Testscope",
                    Id       = secondChildScopeId,
                    ParentId = firstChildScopeId,
                });

                initialRootScope.UpdateParent(firstChildScopeId, null);

                await engine.Save(initialRootScope);

                var rehydratedRoot = await engine.GetRootScope();

                Assert.Equal(2, rehydratedRoot.GetRootScopes().Count());
                var rehydratedRootScope       = rehydratedRoot.GetRootScopes().First();
                var rehydratedFirstLevelScope = rehydratedRoot.GetRootScopes().ElementAt(1);

                Assert.Equal(rootScopeId, rehydratedRootScope.Id);
                Assert.Equal(firstChildScopeId, rehydratedFirstLevelScope.Id);

                Assert.Empty(rehydratedRootScope.GetChildScopes());
                Assert.Single(rehydratedFirstLevelScope.GetChildScopes());

                var rehydratedSecondLevelChild = rehydratedFirstLevelScope.GetChildScopes().First();
                Assert.Equal(secondChildScopeId, rehydratedSecondLevelChild.Id);
            });
        }