Exemplo n.º 1
0
        public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
        {
            try
            {
                var connector = DevOpsManager.GetConnector(threatModel);

                switch (action.Name)
                {
                case "Connect":
                    var dialog = new DevOpsConnectionDialog();
                    if (connector == null)
                    {
                        var schemaManager = new DevOpsConfigPropertySchemaManager(threatModel);
                        dialog.Connection = schemaManager.ConnectionInfo;
                    }
                    else
                    {
                        dialog.Connector = connector;
                    }
                    if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        connector = dialog.Connector;
                        var project = dialog.ProjectName;
                        if (connector != null && !string.IsNullOrWhiteSpace(project))
                        {
                            connector.OpenProject(project);
                            DevOpsManager.Register(connector, threatModel);
                            ChangeDisconnectButtonStatus(connector, true);
                        }
                    }

                    break;

                case "Disconnect":
                    if (connector != null && MessageBox.Show(Form.ActiveForm,
                                                             "You are about to disconnect the current DevOps Connector.\nIf you proceed, all the links between the Threat Model and the DevOps system may be lost.\nAre you sure?",
                                                             "DevOps Disconnect", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                        DialogResult.Yes)
                    {
                        DevOpsManager.Unregister(threatModel);
                        ChangeDisconnectButtonStatus(null, false);
                    }
                    break;
                }
            }
            catch
            {
                ShowWarning?.Invoke("Connection failed.");
                throw;
            }
        }