Example #1
0
        public void ExecuteRibbonAction([NotNull] IThreatModel threatModel, [NotNull] IActionDefinition action)
        {
            try
            {
                switch (action.Name)
                {
                case "ImportDocument":
                    var dialog = new OpenFileDialog()
                    {
                        AddExtension     = true,
                        CheckFileExists  = true,
                        CheckPathExists  = true,
                        DefaultExt       = "tm7",
                        Filter           = "TMT documents (*.tm7)|*.tm7|TMT templates (*.tb7)|*.tb7",
                        FilterIndex      = 1,
                        Multiselect      = false,
                        RestoreDirectory = true
                    };
                    if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        var importer = new Importer();
                        importer.Import(threatModel, dialog.FileName, Dpi.Factor.Height, HandleUnassignedThreat,
                                        out var diagrams, out var externalInteractors, out var processes, out var dataStores,
                                        out var flows, out var trustBoundaries, out var entityTypes, out var threatTypes, out var customThreatTypes,
                                        out var threats, out var missingThreats);
                        RefreshPanels?.Invoke(this);
                        ShowMessage?.Invoke("TMT7 file imported successfully.");

                        using (var resultDialog = new ImportResultDialog()
                        {
                            Properties = new ImportStatus()
                            {
                                Diagrams = diagrams,
                                ExternalInteractors = externalInteractors,
                                Processes = processes,
                                DataStores = dataStores,
                                DataFlows = flows,
                                TrustBoundaries = trustBoundaries,
                                EntityTypes = entityTypes,
                                ThreatTypes = threatTypes,
                                CustomThreatTypes = customThreatTypes,
                                Threats = threats,
                                MissingThreats = missingThreats
                            }
                        })
                        {
                            resultDialog.ShowDialog(Form.ActiveForm);
                        }
                    }
                    break;
                }
            }
            catch
            {
                ShowWarning?.Invoke("TMT file import failed.\nPlease close the document without saving it.");
                throw;
            }
        }
Example #2
0
        public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
        {
            try
            {
                switch (action.Name)
                {
                case "Merge":
                    var dialog = new OpenFileDialog()
                    {
                        AddExtension       = true,
                        AutoUpgradeEnabled = true,
                        CheckFileExists    = true,
                        CheckPathExists    = true,
                        DefaultExt         = "tm",
                        DereferenceLinks   = true,
                        Filter             = "Threat Model (*.tm)|*.tm|Threat Model Template (*.tmt)|*.tmt|Threat Model Json Template (*.tmk)|*.tmk",
                        FilterIndex        = 0,
                        Title            = "Select file to be merged",
                        RestoreDirectory = true
                    };
                    if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        using (var merge = new MergeDialog())
                        {
                            merge.SetExecutionMode(_executionMode);
                            if (merge.Initialize(threatModel, dialog.FileName))
                            {
                                if (merge.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                                {
                                    RefreshPanels?.Invoke(this);
                                    var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");
                                    if (factory != null)
                                    {
                                        ClosePanels?.Invoke(factory);
                                        UpdateStatusInfoProviders?.Invoke();
                                    }

                                    ShowMessage?.Invoke("Merge succeeded.");
                                }
                            }
                        }
                    }

                    break;
                }
            }
            catch
            {
                ShowWarning?.Invoke("Merge failed.\nPlease close the document without saving it.");
                throw;
            }
        }