public override SelectionRuleNode CreateNode([NotNull] Node node, params object[] parameters) { SelectionRuleNode result = null; if (parameters != null && parameters.Length >= 4 && parameters[0] is PropertyTypeItemContextType contextType && parameters[1] is string schemaNs && parameters[2] is string schemaName) { switch (contextType) { case PropertyTypeItemContextType.Boolean: if (parameters[3] is bool boolValue) { result = new BooleanRuleNode(node.Text, schemaNs, schemaName, boolValue) { Scope = Scope } } ; break; case PropertyTypeItemContextType.Comparison: if (parameters[3] is ComparisonOperator op && parameters[4] is string textValue) { result = new ComparisonRuleNode(node.Text, schemaNs, schemaName, op, textValue) { Scope = Scope } } ; break; case PropertyTypeItemContextType.EnumValue: if (parameters[3] is IEnumerable <string> values && parameters[4] is string value) { result = new EnumValueRuleNode(node.Text, schemaNs, schemaName, values, value) { Scope = Scope } } ; break; } } return(result); } }
public override SelectionRuleNode CreateNode(Node node, params object[] parameters) { SelectionRuleNode result = null; if (parameters != null && parameters.Length == 2 && parameters[0] is ComparisonOperator op && parameters[1] is string value) { result = new ComparisonRuleNode(node.Text, null, null, op, value) { Scope = Scope }; } return(result); }
private SelectionRuleNode GetComparisonRuleNode([Required] string propertyKey, string value, Scope scope) { SelectionRuleNode result = null; var elementSchemas = _source.GetElementTypesForProperty(propertyKey)?.ToArray(); var flowSchemas = _source.GetFlowTypesForProperty(propertyKey)?.ToArray(); var schema = elementSchemas?.FirstOrDefault(); var property = schema?.Properties?.FirstOrDefault(x => string.CompareOrdinal(x.Key, propertyKey) == 0); string schemaName; if (schema != null && schema.IsGeneric) { switch (schema.ElementType) { case ElementType.StencilRectangle: schemaName = Resources.TmtExternalInteractorPropertySchema; break; case ElementType.StencilEllipse: schemaName = Resources.TmtProcessPropertySchema; break; case ElementType.StencilParallelLines: schemaName = Resources.TmtDataStorePropertySchema; break; case ElementType.BorderBoundary: schemaName = Resources.TmtTrustBoundaryPropertySchema; break; case ElementType.Connector: schemaName = Resources.TmtFlowPropertySchema; break; case ElementType.LineBoundary: schemaName = Resources.TmtTrustBoundaryPropertySchema; break; default: throw new ArgumentOutOfRangeException(); } } else { schemaName = schema?.Name; } if (property == null) { schema = flowSchemas?.FirstOrDefault(); property = schema?.Properties?.FirstOrDefault(x => string.CompareOrdinal(x.Key, propertyKey) == 0); if (schema?.IsGeneric ?? false) { schemaName = Resources.TmtFlowPropertySchema; } else { schemaName = schema?.Name; } } if (schemaName != null && property != null) { switch (property.Type) { case PropertyType.String: result = new ComparisonRuleNode(property.Name, Resources.DefaultNamespace, schemaName, ComparisonOperator.Exact, value) { Scope = scope }; break; case PropertyType.Boolean: if (bool.TryParse(value, out var boolValue)) { result = new BooleanRuleNode(property.Name, Resources.DefaultNamespace, schemaName, boolValue) { Scope = scope } } ; break; case PropertyType.List: result = new EnumValueRuleNode(property.Name, Resources.DefaultNamespace, schemaName, property.Values, value) { Scope = scope }; break; default: throw new ArgumentOutOfRangeException(); } } return(result); }
private static void UpdateNode([NotNull] Node node, [NotNull] ComparisonRuleNode ruleNode) { UpdateNode(node, ruleNode.Name, ruleNode.Namespace, ruleNode.Schema, ruleNode.Operator, ruleNode.Value); }
private SelectionRuleNode GetIdComparisonRuleNode([Required] string id, Scope scope) { SelectionRuleNode result = null; var elementType = _source.ElementTypes?.FirstOrDefault(x => string.CompareOrdinal(x.TypeId, id) == 0); var entityTemplate = GetEntityTemplate(id); if (elementType?.IsGeneric ?? false) { switch (elementType.ElementType) { case ElementType.StencilRectangle: result = new EnumValueRuleNode("Object Type", null, null, new[] { "External Interactor", "Process", "Data Store" }, "External Interactor") { Scope = scope }; break; case ElementType.StencilEllipse: result = new EnumValueRuleNode("Object Type", null, null, new[] { "External Interactor", "Process", "Data Store" }, "Process") { Scope = scope }; break; case ElementType.StencilParallelLines: result = new EnumValueRuleNode("Object Type", null, null, new[] { "External Interactor", "Process", "Data Store" }, "Data Store") { Scope = scope }; break; } } else if (entityTemplate != null) { switch (entityTemplate.EntityType) { case EntityType.ExternalInteractor: result = new ExternalInteractorTemplateRuleNode(entityTemplate) { Scope = scope }; break; case EntityType.Process: result = new ProcessTemplateRuleNode(entityTemplate) { Scope = scope }; break; case EntityType.DataStore: result = new DataStoreTemplateRuleNode(entityTemplate) { Scope = scope }; break; default: throw new ArgumentOutOfRangeException(); } } else { var flowTemplate = GetFlowTemplate(id); if (flowTemplate != null) { result = new FlowTemplateRuleNode(flowTemplate); } else { result = new ComparisonRuleNode(ObjectPropertySchemaManager.ThreatModelObjectId, Resources.DefaultNamespace, Resources.TmtObjectPropertySchema, ComparisonOperator.Exact, id) { Scope = scope }; } } return(result); }