Example #1
0
        private static void Cleanup(this IThreatModel model)
        {
            model.CleanProperties(model);
            model.CleanThreatEvents(model);

            var dataFlows = model.DataFlows?.ToArray();

            if (dataFlows?.Any() ?? false)
            {
                foreach (var flow in dataFlows)
                {
                    flow.CleanProperties(model);
                    flow.CleanThreatEvents(model);
                }
            }

            var diagrams = model.Diagrams?.ToArray();

            if (diagrams?.Any() ?? false)
            {
                foreach (var diagram in diagrams)
                {
                    diagram.CleanProperties(model);

                    var entityShapes = diagram.Entities?.ToArray();
                    if (entityShapes?.Any() ?? false)
                    {
                        foreach (var entityShape in entityShapes)
                        {
                            entityShape.CleanProperties(model);
                        }
                    }

                    var groupShapes = diagram.Groups?.ToArray();
                    if (groupShapes?.Any() ?? false)
                    {
                        foreach (var groupShape in groupShapes)
                        {
                            groupShape.CleanProperties(model);
                        }
                    }
                }
            }

            var entities = model.Entities?.ToArray();

            if (entities?.Any() ?? false)
            {
                foreach (var entity in entities)
                {
                    entity.CleanProperties(model);
                    entity.CleanThreatEvents(model);
                }
            }

            var entityTemplates = model.EntityTemplates?.ToArray();

            if (entityTemplates?.Any() ?? false)
            {
                foreach (var entityTemplate in entityTemplates)
                {
                    entityTemplate.CleanProperties(model);
                }
            }

            var flowTemplates = model.FlowTemplates?.ToArray();

            if (flowTemplates?.Any() ?? false)
            {
                foreach (var flowTemplate in flowTemplates)
                {
                    flowTemplate.CleanProperties(model);
                }
            }

            var trustBoundaryTemplates = model.TrustBoundaryTemplates?.ToArray();

            if (trustBoundaryTemplates?.Any() ?? false)
            {
                foreach (var trustBoundaryTemplate in trustBoundaryTemplates)
                {
                    trustBoundaryTemplate.CleanProperties(model);
                }
            }

            var groups = model.Groups?.ToArray();

            if (groups?.Any() ?? false)
            {
                foreach (var group in groups)
                {
                    group.CleanProperties(model);
                }
            }

            var mitigations = model.Mitigations?.ToArray();

            if (mitigations?.Any() ?? false)
            {
                foreach (var mitigation in mitigations)
                {
                    mitigation.CleanProperties(model);
                }
            }

            var severities = model.Severities?.ToArray();

            if (severities?.Any() ?? false)
            {
                foreach (var severity in severities)
                {
                    severity.CleanProperties(model);
                }
            }

            var strengths = model.Strengths?.ToArray();

            if (strengths?.Any() ?? false)
            {
                foreach (var strength in strengths)
                {
                    strength.CleanProperties(model);
                }
            }

            var actors = model.ThreatActors?.ToArray();

            if (actors?.Any() ?? false)
            {
                foreach (var actor in actors)
                {
                    actor.CleanProperties(model);
                }
            }

            var threatEvents = model.ThreatEvents?.ToArray();

            if (threatEvents?.Any() ?? false)
            {
                foreach (var threatEvent in threatEvents)
                {
                    threatEvent.CleanProperties(model);

                    var teMitigations = threatEvent.Mitigations?.ToArray();
                    if (teMitigations?.Any() ?? false)
                    {
                        foreach (var teMitigation in teMitigations)
                        {
                            teMitigation.CleanProperties(model);
                        }
                    }

                    var teScenarios = threatEvent.Scenarios?.ToArray();
                    if (teScenarios?.Any() ?? false)
                    {
                        foreach (var teScenario in teScenarios)
                        {
                            teScenario.CleanProperties(model);
                        }
                    }
                }
            }

            var threatTypes = model.ThreatTypes?.ToArray();

            if (threatTypes?.Any() ?? false)
            {
                foreach (var threatType in threatTypes)
                {
                    threatType.CleanProperties(model);
                }
            }
        }