public InvocationResponse ExecuteSetup(string targetModel, ExecuteSetupRequest request)
        {
            var contextType        = DbContextManager.Contexts.First(c => TargetModelName(c) == targetModel);
            var targetConfigurator = DbContextManager.GetConfigurator(contextType);

            if (targetConfigurator == null)
            {
                return(new InvocationResponse("No configurator found"));
            }

            // Update config copy from model
            var config = UpdateConfigFromModel(targetConfigurator.Config, request.Config);

            var setupExecutor = DbContextManager.GetSetupExecutor(contextType);

            var targetSetup = setupExecutor.GetAllSetups().FirstOrDefault(s => s.GetType().FullName == request.Setup.Fullname);

            if (targetSetup == null)
            {
                return(new InvocationResponse("No matching setup found"));
            }

            // Provide logger for model
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (targetSetup is ILoggingComponent loggingComponent)
            {
                loggingComponent.Logger = Logger.GetChild("Setup", loggingComponent.GetType());
            }

            try
            {
                setupExecutor.Execute(config, targetSetup, request.Setup.SetupData);
                return(new InvocationResponse());
            }
            catch (Exception ex)
            {
                Logger.LogException(LogLevel.Warning, ex, "Database setup execution failed!");
                return(new InvocationResponse(ex));
            }
        }
        private SetupModel[] GetAllSetups(Type contextType)
        {
            var setupExecutor = DbContextManager.GetSetupExecutor(contextType);
            var allSetups     = setupExecutor.GetAllSetups();
            var setups        = allSetups.Where(setup => string.IsNullOrEmpty(setup.SupportedFileRegex))
                                .Select(ConvertSetup).OrderBy(setup => setup.SortOrder).ToList();

            string[] files;
            if (!Directory.Exists(Config.SetupDataDir) || !(files = Directory.GetFiles(Config.SetupDataDir)).Any())
            {
                return(setups.ToArray());
            }

            var fileSetups = allSetups.Where(setup => !string.IsNullOrEmpty(setup.SupportedFileRegex))
                             .Select(ConvertSetup).ToList();

            foreach (var setup in fileSetups)
            {
                var regex         = new Regex(setup.SupportedFileRegex);
                var matchingFiles = files.Where(file => regex.IsMatch(Path.GetFileName(file)));
                setups.AddRange(matchingFiles.Select(setup.CopyWithFile));
            }
            return(setups.OrderBy(setup => setup.SortOrder).ToArray());
        }