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); }
private int ImportDataFlows([NotNull] ThreatModel source, [NotNull] IThreatModel target) { int result = 0; var flows = source.Flows; if (flows?.Any() ?? false) { var entitiesSchemaManager = new EntitiesPropertySchemaManager(target); var dataFlowsSchemaManager = new DataFlowsPropertySchemaManager(target); var schema = dataFlowsSchemaManager.GetSchema(); foreach (var flow in flows) { var sourceEntity = GetEntity(flow.SourceGuid.ToString(), target, entitiesSchemaManager); var targetEntity = GetEntity(flow.TargetGuid.ToString(), target, entitiesSchemaManager); if (sourceEntity != null && targetEntity != null) { var dataFlow = target.AddDataFlow(flow.Name, sourceEntity.Id, targetEntity.Id); if (dataFlow != null) { dataFlowsSchemaManager.SetMsTmtDataFlowId(dataFlow, flow.FlowId.ToString()); var properties = flow.Properties?.ToArray(); AddProperties(schema, dataFlow, properties); } IDiagram diagram = target.Diagrams?.FirstOrDefault(x => string.CompareOrdinal(x.Name, flow.PageName) == 0); diagram?.AddLink(dataFlow); result++; } } } return(result); }