private void InitializeThreatsPropertySchema([NotNull] IPropertySchema schema, [NotNull] IEnumerable <PropertyDefinition> sourceProperties) { if (sourceProperties.Any()) { foreach (var property in sourceProperties) { if (!property.HideFromUi && !IsSpecial(property.Name)) { var propertyType = schema.GetPropertyType(property.Label); if (propertyType == null) { if (property.Values?.Any() ?? false) { propertyType = schema.AddPropertyType(property.Label, PropertyValueType.List); if (propertyType is IListPropertyType listPropertyType) { listPropertyType.SetListProvider(new ListProviderExtension()); listPropertyType.Context = property.Values.TagConcat(); } } else { schema.AddPropertyType(property.Label, PropertyValueType.String); } } } } } }
private static void AddProperties([NotNull] IPropertySchema schema, IPropertiesContainer container, [NotNull] IEnumerable <Property> properties) { foreach (var property in properties) { if (!string.IsNullOrWhiteSpace(property.Name)) { var propertyType = schema.GetPropertyType(property.Name); if (propertyType == null) { switch (property.Type) { case PropertyType.String: propertyType = schema.AddPropertyType(property.Name, PropertyValueType.String); break; case PropertyType.Boolean: propertyType = schema.AddPropertyType(property.Name, PropertyValueType.Boolean); break; case PropertyType.List: propertyType = schema.AddPropertyType(property.Name, PropertyValueType.List); if (propertyType is IListPropertyType listPropertyType) { listPropertyType.Context = property.Values.TagConcat(); listPropertyType.SetListProvider(new ListProviderExtension()); } break; } } if (propertyType != null && container != null) { var value = property.Value; if (string.IsNullOrWhiteSpace(value) && propertyType is IListPropertyType listPropertyType) { value = listPropertyType.Values.FirstOrDefault()?.Id; } var containerProperty = container.GetProperty(propertyType); if (containerProperty == null) { container.AddProperty(propertyType, value); } else { containerProperty.StringValue = value; } } } } }
private void ImportBaseElementTemplates([NotNull] ThreatModel source, [NotNull] IThreatModel target) { var elements = source.ElementTypes? .Where(x => x.IsGeneric) .ToArray(); if (elements?.Any() ?? false) { IPropertySchema schema = null; 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: schema = baseEISchema; break; case ElementType.StencilEllipse: schema = basePSchema; break; case ElementType.StencilParallelLines: schema = baseDSSchema; break; case ElementType.BorderBoundary: case ElementType.LineBoundary: schema = baseTBSchema; break; } if (schema != null) { var properties = element.Properties?.ToArray(); var outOfScope = schema.GetPropertyType("Out of Scope") ?? schema.AddPropertyType("Out of Scope", PropertyValueType.Boolean); var reason = schema.GetPropertyType("Reason For Out Of Scope") ?? schema.AddPropertyType("Reason For Out Of Scope", PropertyValueType.String); AddProperties(schema, null, properties); } } } }
private static void AddProperties([NotNull] IPropertySchema schema, [NotNull] IPropertiesContainer container, [NotNull] IEnumerable <Property> properties) { foreach (var property in properties) { if (!string.IsNullOrWhiteSpace(property.Name)) { var propertyType = schema.GetPropertyType(property.Name); if (propertyType == null) { switch (property.Type) { case PropertyType.String: propertyType = schema.AddPropertyType(property.Name, PropertyValueType.String); break; case PropertyType.Boolean: propertyType = schema.AddPropertyType(property.Name, PropertyValueType.Boolean); break; case PropertyType.List: propertyType = schema.AddPropertyType(property.Name, PropertyValueType.List); if (propertyType is IListPropertyType listPropertyType) { listPropertyType.Context = property.Values.TagConcat(); listPropertyType.SetListProvider(new ListProviderExtension()); } break; default: throw new ArgumentOutOfRangeException(); } } var current = container.GetProperty(propertyType) ?? container.AddProperty(propertyType, property.Value); } } }