Пример #1
0
        public static IEnumerable <ItemRow> GetItemRows(this IPropertiesContainer container, IPropertyType except = null)
        {
            IEnumerable <ItemRow> result = null;

            if (container is IThreatModelChild child && child.Model != null)
            {
                var model = child.Model;

                var schemas = GetSchemas(model, container.Properties)?.ToArray();

                if (schemas?.Any() ?? false)
                {
                    var list = new List <ItemRow>();

                    foreach (var schema in schemas)
                    {
                        var itemRows = container.Properties?
                                       .Where(x => !(x.PropertyType?.DoNotPrint ?? false) &&
                                              x.PropertyType.SchemaId == schema.Id &&
                                              x.PropertyType != except)
                                       .OrderBy(x => x.PropertyType?.Priority ?? 0)
                                       .Select(x => ItemRow.Create(container, x))
                                       .ToArray();

                        if (itemRows?.Any() ?? false)
                        {
                            list.AddRange(itemRows);
                        }
                    }

                    if (list.Any())
                    {
                        result = list;
                    }
                }
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Creates a new ItemRow for a given Property.
        /// </summary>
        /// <param name="container">Container of the Property.</param>
        /// <param name="property">Property to be analyzed.</param>
        /// <returns>The created ItemRow.</returns>
        public static ItemRow Create([NotNull] IPropertiesContainer container, [NotNull] IProperty property)
        {
            ItemRow result = null;

            var propertyType = property.PropertyType;

            if (property is IPropertyArray propertyArray)
            {
                result = new ListRow(propertyType.Name, propertyArray.Value?.Select(x => new Line(x?.TrimEnd(' ', '\r', '\n'))));
            }
            else if (property is IPropertyIdentityReference propertyIdentityReference)
            {
                if (propertyIdentityReference.Value is IIdentity identity && identity is IThreatModelChild child)
                {
                    result = new TextRow(propertyType.Name,
                                         $"{identity.Name}",
                                         $"[{child.Model.GetIdentityTypeInitial(identity)}] ", null, new[] { identity.Id });
                }
                else
                {
                    result = new EmptyRow(propertyType.Name);
                }
            }