Example #1
0
        private void _objectTypes_SelectedValueChanged(object sender, EventArgs e)
        {
            if (_objectTypes.SelectedItem is string selected)
            {
                _objects.Items.Clear();
                _imageList.Images.Clear();
                _properties.Item = null;

                ChangeCustomActionStatus?.Invoke("AddNotes", false);
                ChangeCustomActionStatus?.Invoke("AddTopic", false);
                ChangeCustomActionStatus?.Invoke("AddHighlight", false);
                ChangeCustomActionStatus?.Invoke("RemoveNotes", false);
                ChangeCustomActionStatus?.Invoke("RemoveTopic", false);
                ChangeCustomActionStatus?.Invoke("RemoveHighlight", false);

                RemoveButtons();
                _annotation.Annotation = null;

                switch (selected)
                {
                case "External Interactors":
                    AddObjects(_model.GetExternalInteractors(_schemaManager, _propertyType, _filter.Text), true);
                    break;

                case "Processes":
                    AddObjects(_model.GetProcesses(_schemaManager, _propertyType, _filter.Text), true);
                    break;

                case "Data Stores":
                    AddObjects(_model.GetDataStores(_schemaManager, _propertyType, _filter.Text), true);
                    break;

                case "Flows":
                    AddObjects(_model.GetFlows(_schemaManager, _propertyType, _filter.Text));
                    break;

                case "Trust Boundaries":
                    AddObjects(_model.GetTrustBoundaries(_schemaManager, _propertyType, _filter.Text));
                    break;

                case "Threat Events":
                    AddObjects(_model.GetThreatEvents(_schemaManager, _propertyType, _filter.Text));
                    break;

                case "Threat Event Mitigations":
                    var tems = _model.GetThreatEventMitigations(_schemaManager, _propertyType, _filter.Text)?
                               .Where(x => x is IPropertiesContainer container &&
                                      ((_show == WhatToShow.All && (_schemaManager.HasNotes(container) || _schemaManager.HasTopics(container) || _schemaManager.HasHighlights(container))) ||
                                       (_show == WhatToShow.OpenTopicsOnly && _schemaManager.HasOpenTopics(container)) ||
                                       (_show == WhatToShow.HighlightsOnly && _schemaManager.HasHighlights(container))))
                               .ToArray();
                    if (tems?.Any() ?? false)
                    {
                        bool first = true;

                        foreach (var tem in tems)
                        {
                            if (first)
                            {
                                _imageList.Images.Add(Icons.Resources.mitigations_small);
                                first = false;
                            }

                            _objects.Items.Add(new ListViewItem(tem.Mitigation.Name, 0)
                            {
                                ToolTipText = $"'{tem.Mitigation.Name}' for '{tem.ThreatEvent.Name}' on '{tem.ThreatEvent.Parent.Name}'",
                                Tag         = tem
                            });
                        }
                    }
                    break;

                case "Threat Types":
                    AddObjects(_model.GetThreatTypes(_schemaManager, _propertyType, _filter.Text));
                    break;

                case "Known Mitigations":
                    AddObjects(_model.GetKnownMitigations(_schemaManager, _propertyType, _filter.Text));
                    break;

                case "Standard Mitigations":
                    var sms = _model.GetStandardMitigations(_schemaManager, _propertyType, _filter.Text)?
                              .Where(x => x is IPropertiesContainer container &&
                                     ((_show == WhatToShow.All && (_schemaManager.HasNotes(container) || _schemaManager.HasTopics(container) || _schemaManager.HasHighlights(container))) ||
                                      (_show == WhatToShow.OpenTopicsOnly && _schemaManager.HasOpenTopics(container)) ||
                                      (_show == WhatToShow.HighlightsOnly && _schemaManager.HasHighlights(container))))
                              .ToArray();
                    if (sms?.Any() ?? false)
                    {
                        bool first = true;

                        foreach (var sm in sms)
                        {
                            if (first)
                            {
                                _imageList.Images.Add(Icons.Resources.standard_mitigations_small);
                                first = false;
                            }

                            _objects.Items.Add(new ListViewItem(sm.Mitigation.Name, 0)
                            {
                                ToolTipText = $"'{sm.Mitigation.Name}' for '{sm.ThreatType.Name}'",
                                Tag         = sm
                            });
                        }
                    }
                    break;

                case "Entity Templates":
                    AddObjects(_model.GetEntityTemplates(_schemaManager, _propertyType, _filter.Text), true);
                    break;

                case "Flow Templates":
                    AddObjects(_model.GetFlowTemplates(_schemaManager, _propertyType, _filter.Text));
                    break;

                case "Trust Boundary Templates":
                    AddObjects(_model.GetTrustBoundaryTemplates(_schemaManager, _propertyType, _filter.Text));
                    break;

                case "Diagrams":
                    AddObjects(_model.GetDiagrams(_schemaManager, _propertyType, _filter.Text));
                    break;

                case "Threat Model":
                    AddObject(_model);
                    break;
                }

                _objects.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
            }
        }