示例#1
0
        private int ImportEntityTemplates([NotNull] ThreatModel source, [NotNull] IThreatModel target)
        {
            int result   = 0;
            var elements = source.ElementTypes?
                           .Where(x => !x.IsGeneric)
                           .ToArray();

            if (elements?.Any() ?? false)
            {
                var schemaManager = new ObjectPropertySchemaManager(target);

                IEntityTemplate        entityTemplate;
                ITrustBoundaryTemplate trustBoundaryTemplate;
                Interfaces.Scope       scope;
                IPropertySchema        baseSchema;
                var baseEISchema = new BaseExternalInteractorPropertySchemaManager(target).GetSchema();
                var basePSchema  = new BaseProcessPropertySchemaManager(target).GetSchema();
                var baseDSSchema = new BaseDataStorePropertySchemaManager(target).GetSchema();
                var baseTBSchema = new BaseTrustBoundaryPropertySchemaManager(target).GetSchema();

                foreach (var element in elements)
                {
                    switch (element.ElementType)
                    {
                    case ElementType.StencilRectangle:
                        entityTemplate = target.AddEntityTemplate(element.Name, element.Description,
                                                                  element.Image, element.Image, element.Image,
                                                                  EntityType.ExternalInteractor);
                        trustBoundaryTemplate = null;
                        scope      = Scope.ExternalInteractor;
                        baseSchema = baseEISchema;
                        result++;
                        break;

                    case ElementType.StencilEllipse:
                        entityTemplate = target.AddEntityTemplate(element.Name, element.Description,
                                                                  element.Image, element.Image, element.Image,
                                                                  EntityType.Process);
                        trustBoundaryTemplate = null;
                        scope      = Scope.Process;
                        baseSchema = basePSchema;
                        result++;
                        break;

                    case ElementType.StencilParallelLines:
                        entityTemplate = target.AddEntityTemplate(element.Name, element.Description,
                                                                  element.Image, element.Image, element.Image,
                                                                  EntityType.DataStore);
                        trustBoundaryTemplate = null;
                        scope      = Scope.DataStore;
                        baseSchema = baseDSSchema;
                        result++;
                        break;

                    case ElementType.LineBoundary:
                    case ElementType.BorderBoundary:
                        entityTemplate        = null;
                        trustBoundaryTemplate = target.AddTrustBoundaryTemplate(element.Name, element.Description);
                        scope      = Scope.TrustBoundary;
                        baseSchema = baseTBSchema;
                        result++;
                        break;

                    default:
                        entityTemplate        = null;
                        trustBoundaryTemplate = null;
                        scope      = Scope.Undefined;
                        baseSchema = null;
                        break;
                    }

                    if (entityTemplate != null)
                    {
                        InitializeBaseSchema(entityTemplate, baseSchema);
                        schemaManager.SetObjectId(entityTemplate, element.TypeId);
                        var properties = element.Properties?.ToArray();

                        AddProperties(target, element.Name, scope, baseSchema, entityTemplate, properties);
                    }
                    else if (trustBoundaryTemplate != null)
                    {
                        InitializeBaseSchema(trustBoundaryTemplate, baseSchema);
                        schemaManager.SetObjectId(trustBoundaryTemplate, element.TypeId);
                        var properties = element.Properties?.ToArray();

                        AddProperties(target, element.Name, scope, baseSchema, trustBoundaryTemplate, properties);
                    }
                }
            }

            return(result);
        }