示例#1
0
            public override Task <bool> IsValid(NotifcationTrigger trigger)
            {
                if (IsValidShouldThrowError == true)
                {
                    throw new NotImplementedException();
                }

                return(Task.FromResult(IsValidResult));
            }
示例#2
0
            protected override Task <bool> Handle(NotifcationTrigger trigger)
            {
                if (HandleModelShouldThrowError == true)
                {
                    throw new NotImplementedException();
                }

                return(Task.FromResult(HandleResult));
            }
示例#3
0
        protected internal override async Task <Boolean> Handle(NotifcationTrigger trigger)
        {
            if (trigger is PrefixEdgeRouterBindingUpdatedTrigger == false)
            {
                _logger.LogError("notification actor {name} has an invalid trigger. expected trigger type is {expectedType} actual is {type}",
                                 nameof(NxOsStaticRouteUpdaterNotificationActor), typeof(PrefixEdgeRouterBindingUpdatedTrigger), trigger.GetType());

                return(false);
            }

            _logger.LogDebug("connection to nx os device {address}", Url);

            Boolean isReachabled = await _nxosDeviceSerive.Connect(Url, Username, Password);

            if (isReachabled == false)
            {
                _logger.LogDebug("unable to connect to device {address}", Url);
                return(false);
            }

            var castedTrigger = (PrefixEdgeRouterBindingUpdatedTrigger)trigger;

            _logger.LogDebug("connection to device {address} established", Url);
            if (castedTrigger.OldBinding != null)
            {
                Boolean removeResult = await _nxosDeviceSerive.RemoveIPv6StaticRoute(
                    castedTrigger.OldBinding.Prefix, castedTrigger.OldBinding.Mask.Identifier, castedTrigger.OldBinding.Host);

                if (removeResult == false)
                {
                    _logger.LogError("unable to remve old route form device {address}. Cancel actor", Url);
                    return(false);
                }

                _logger.LogDebug("static route {prefix}/{mask} via {host} has been removed from {device}",
                                 castedTrigger.OldBinding.Prefix, castedTrigger.OldBinding.Mask.Identifier, castedTrigger.OldBinding.Host, Url);
            }

            if (castedTrigger.NewBinding != null)
            {
                Boolean addResult = await _nxosDeviceSerive.AddIPv6StaticRoute(
                    castedTrigger.NewBinding.Prefix, castedTrigger.NewBinding.Mask.Identifier, castedTrigger.NewBinding.Host);

                if (addResult == false)
                {
                    _logger.LogError("unable to add a static route to device {address}. Cancel actor", Url);
                    return(false);
                }

                _logger.LogDebug("static route {prefix}/{mask} via {host} has been added from {device}",
                                 castedTrigger.NewBinding.Prefix, castedTrigger.NewBinding.Mask.Identifier, castedTrigger.NewBinding.Host, Url);
            }

            _logger.LogDebug("actor {name} successfully finished", nameof(NxOsStaticRouteUpdaterNotificationActor));
            return(true);
        }
示例#4
0
 public async Task HandleTrigger(NotifcationTrigger trigger)
 {
     foreach (var item in _pipelines)
     {
         if (item.CanExecute(trigger) == true)
         {
             await item.Execute(trigger);
         }
     }
 }
示例#5
0
        public override Task <Boolean> IsValid(NotifcationTrigger trigger)
        {
            if (trigger is PrefixEdgeRouterBindingUpdatedTrigger == false)
            {
                _logger.LogError("condition {name} has invalid trigger. expected trigger type is {expectedType} actual is {type}",
                                 nameof(DHCPv6ScopeIdNotificationCondition), typeof(PrefixEdgeRouterBindingUpdatedTrigger), trigger.GetType());

                return(Task.FromResult(false));
            }

            var castedTrigger = (PrefixEdgeRouterBindingUpdatedTrigger)trigger;

            if (ScopeIds.Contains(castedTrigger.ScopeId) == true)
            {
                _logger.LogDebug("triggers scope id {scopeId} found in condtition. Condition is true", castedTrigger.ScopeId);
                return(Task.FromResult(true));
            }
            else
            {
                _logger.LogDebug("triggers scope id {scopeId} not found scope list. Checking if children are included", castedTrigger.ScopeId);
                if (IncludesChildren == false)
                {
                    _logger.LogDebug("children shouldn't be included. Conditition evalutated to false");
                    return(Task.FromResult(false));
                }
                else
                {
                    foreach (var scopeId in ScopeIds)
                    {
                        _logger.LogDebug("checking scopes recursivly for machting id");
                        _logger.LogDebug("check if {triggerId} is a child of {scopeId}", castedTrigger.ScopeId, castedTrigger.ScopeId);

                        var scope = _rootScope.GetScopeById(scopeId);
                        if (scope == null)
                        {
                            _logger.LogError("scope with id {scopeId} not found", scopeId);
                            continue;
                        }

                        foreach (var item in scope.GetChildScopes())
                        {
                            Boolean found = SearchChildScope(item, castedTrigger.ScopeId);
                            if (found == true)
                            {
                                _logger.LogDebug("a machting child scope found. Condition evaluted to true");
                                return(Task.FromResult(true));
                            }
                        }
                    }

                    _logger.LogDebug("no child found. Condition evaluted to false");
                    return(Task.FromResult(false));
                }
            }
        }
示例#6
0
 protected void AddNotificationTrigger(NotifcationTrigger trigger) => _addtionalNotifier?.Invoke(trigger);
示例#7
0
 protected void AddTrigger(NotifcationTrigger trigger) => _triggers.Add(trigger);