Пример #1
0
        public async void Process(IThreatModel model)
        {
            Connect.ChangeDisconnectButtonStatus(null, false);

            var schemaManager = new DevOpsConfigPropertySchemaManager(model);
            var connector     = schemaManager.GetDevOpsConnector(out var url, out var project);

            if (connector != null && !string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(project))
            {
                try
                {
                    var tokenManager = new SecretsManager();
                    var token        = tokenManager.GetSecret(url);
                    if (!string.IsNullOrWhiteSpace(token))
                    {
                        connector.Connect(url, token);
                        var projects = (await connector.GetProjectsAsync())?.ToArray();
                        if (projects?.Contains(project) ?? false)
                        {
                            if (connector.OpenProject(project))
                            {
                                DevOpsManager.Register(connector, model);
                                Connect.ChangeDisconnectButtonStatus(connector, true);

                                var configManager = new ExtensionConfigurationManager(model, this.GetExtensionId());
                                configManager.Apply();

                                await DevOpsManager.UpdateAsync(model);
                            }
                        }
                        else
                        {
                            connector.Disconnect();
                            ShowWarning?.Invoke(
                                "DevOps system cannot be automatically connected due to an internal error.");
                        }
                    }
                    else
                    {
                        ShowWarning?.Invoke(
                            "DevOps system cannot be automatically connected because no Personal Access Token has been found.");
                    }
                }
                catch (Exception exc)
                {
                    ShowWarning?.Invoke($@"DevOps system cannot be automatically connected due to the following error: {exc.Message}. Everything else should be unaffected.");
                }
            }
        }
Пример #2
0
        public async void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            string text    = null;
            bool   warning = false;

            try
            {
                switch (action.Name)
                {
                case "Sync":
                    if ((await DevOpsManager.UpdateAsync(_model)) > 0)
                    {
                        LoadModel();
                    }
                    break;

                case "Auto":
                    var summaries     = DevOpsManager.GetMitigationsSummary(_model);
                    var schemaManager = new RoadmapPropertySchemaManager(_model);
                    var mitigations   = _model?.GetUniqueMitigations()?
                                        .Where(x => (schemaManager.GetStatus(x) != RoadmapStatus.NoActionRequired) &&
                                               !(summaries?.ContainsKey(x) ?? false))
                                        .OrderBy(x => x.Name).ToArray();
                    if (mitigations?.Any() ?? false)
                    {
                        var connector           = DevOpsManager.GetConnector(_model);
                        var devOpsSchemaManager = new DevOpsPropertySchemaManager(_model);
                        _countdown = new CountdownEvent(mitigations.Length);
                        foreach (var mitigation in mitigations)
                        {
                            AutoLoad(mitigation, connector, devOpsSchemaManager);
                        }

                        ShowMessage?.Invoke("Automatic Load in progress...");
                        AutomaticLoadCompletion();
                    }
                    else
                    {
                        ShowWarning?.Invoke("Automatic Load has not identified any action to do.");
                    }
                    break;

                case "ShortTerm":
                    _filter = RoadmapStatus.ShortTerm;
                    LoadModel();
                    break;

                case "MidTerm":
                    _filter = RoadmapStatus.MidTerm;
                    LoadModel();
                    break;

                case "LongTerm":
                    _filter = RoadmapStatus.LongTerm;
                    LoadModel();
                    break;

                case "All":
                    _filter = RoadmapStatus.NoActionRequired;
                    LoadModel();
                    break;

                case "Refresh":
                    LoadModel();
                    break;
                }

                //if (warning)
                //    ShowWarning?.Invoke(text);
                //else if (text != null)
                //    ShowMessage?.Invoke($"{text} has been executed successfully.");
            }
            catch
            {
                //ShowWarning?.Invoke($"An error occurred during the execution of the action.");
                throw;
            }
        }