Exemplo n.º 1
0
        public IThreatEvent AddThreatEvent(IThreatType threatType)
        {
            IThreatEvent result = null;

            if (threatType != null && Instance is IIdentity identity)
            {
                IThreatModel model = (Instance as IThreatModel) ?? (Instance as IThreatModelChild)?.Model;

                if (model != null)
                {
                    if (_threatEvents?.All(x => x.ThreatTypeId != threatType.Id) ?? true)
                    {
                        result = new ThreatEvent(model, threatType, identity);
                        if (_threatEvents == null)
                        {
                            _threatEvents = new List <IThreatEvent>();
                        }
                        _threatEvents.Add(result);
                        if (Instance is IDirty dirtyObject)
                        {
                            dirtyObject.SetDirty();
                        }
                        if (Instance is IThreatEventsContainer container)
                        {
                            _threatEventAdded?.Invoke(container, result);
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public IThreatEvent AddThreatEvent(IThreatType threatType)
        {
            if (!(IsInitialized?.Get() ?? false))
            {
                return(null);
            }

            IThreatEvent result = null;

            var threatEventsContainer = ThreatEventsContainer?.Get();

            if ((_threatEvents?.All(x => x.ThreatTypeId != threatType.Id) ?? true) &&
                threatEventsContainer is IIdentity identity)
            {
                result = new ThreatEvent(Model?.Get(), threatType, identity);
                if (_threatEvents == null)
                {
                    _threatEvents = new List <IThreatEvent>();
                }
                _threatEvents.Add(result);
                Dirty.IsDirty = true;
                _threatEventAdded?.Invoke(threatEventsContainer, result);
            }

            return(result);
        }