Exemplo n.º 1
0
        private int ImportFlowTemplates([NotNull] ThreatModel source, [NotNull] IThreatModel target)
        {
            int result     = 0;
            var connectors = source.FlowTypes?
                             .Where(x => !x.IsGeneric)
                             .ToArray();

            if (connectors?.Any() ?? false)
            {
                var schemaManager = new ObjectPropertySchemaManager(target);
                var baseSchema    = new BaseFlowPropertySchemaManager(target).GetSchema();

                foreach (var connector in connectors)
                {
                    var template = target.AddFlowTemplate(connector.Name, connector.Description);
                    if (template != null)
                    {
                        result++;

                        InitializeBaseSchema(template, baseSchema);
                        schemaManager.SetObjectId(template, connector.TypeId);
                        var properties = connector.Properties?.ToArray();

                        AddProperties(target, connector.Name, Scope.DataFlow, baseSchema, template, properties);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private int ImportDataFlows([NotNull] ThreatModel source, [NotNull] IThreatModel target)
        {
            int result = 0;

            var flows = source.Flows?.ToArray();

            if (flows?.Any() ?? false)
            {
                var schemaManager = new ObjectPropertySchemaManager(target);
                var baseSchema    = new BaseFlowPropertySchemaManager(target).GetSchema();

                foreach (var flow in flows)
                {
                    var sourceEntity = GetEntity(flow.SourceGuid.ToString(), target, schemaManager);
                    var targetEntity = GetEntity(flow.TargetGuid.ToString(), target, schemaManager);
                    if (sourceEntity != null && targetEntity != null)
                    {
                        var flowTemplate = target.FlowTemplates?.FirstOrDefault(x =>
                                                                                string.CompareOrdinal(schemaManager.GetObjectId(x), flow.TypeId) == 0);
                        var secondarySchema = flowTemplate != null?
                                              target.GetSchema(flowTemplate.Name, Resources.DefaultNamespace) : null;

                        var dataFlow = flowTemplate != null?flowTemplate.CreateFlow(flow.Name, sourceEntity.Id, targetEntity.Id) :
                                           target.AddDataFlow(flow.Name, sourceEntity.Id, targetEntity.Id);

                        if (dataFlow != null)
                        {
                            schemaManager.SetObjectId(dataFlow, flow.TypeId);
                            schemaManager.SetInstanceId(dataFlow, flow.FlowId.ToString());

                            var properties = flow.Properties?.ToArray();
                            AddProperties(target, baseSchema, secondarySchema, dataFlow, properties);
                        }

                        IDiagram diagram = target.Diagrams?.FirstOrDefault(x =>
                                                                           string.CompareOrdinal(x.Name, flow.PageName) == 0);
                        diagram?.AddLink(dataFlow);
                        result++;
                    }
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        private void ImportBaseFlowTemplates([NotNull] ThreatModel source, [NotNull] IThreatModel target)
        {
            var connectors = source.FlowTypes?
                             .Where(x => x.IsGeneric)
                             .ToArray();

            if (connectors?.Any() ?? false)
            {
                var schema = new BaseFlowPropertySchemaManager(target).GetSchema();

                if (!(schema.PropertyTypes?.Any(x =>
                                                string.CompareOrdinal("Out of Scope", x.Name) == 0) ?? false))
                {
                    var outOfScope = schema.AddPropertyType("Out of Scope",
                                                            PropertyValueType.Boolean);
                    if (outOfScope != null)
                    {
                        outOfScope.Priority = -2;
                    }
                }

                if (!(schema.PropertyTypes?.Any(x =>
                                                string.CompareOrdinal("Reason For Out Of Scope", x.Name) == 0) ?? false))
                {
                    var reasonOutOfScope =
                        schema.AddPropertyType("Reason For Out Of Scope",
                                               PropertyValueType.String);
                    if (reasonOutOfScope != null)
                    {
                        reasonOutOfScope.Priority = -1;
                    }
                }

                foreach (var connector in connectors)
                {
                    AddProperties(schema, null, connector.Properties?.ToArray());
                }
            }
        }