private string BulkOperation(Action <IModelConfigurator> operation, string operationName) { var result = string.Empty; foreach (var contextType in DbContextManager.Contexts) { var configurator = DbContextManager.GetConfigurator(contextType); try { operation(configurator); } catch (Exception ex) { Logger.LogException(LogLevel.Warning, ex, "{0} of {1} failed!", operationName, TargetModelName(contextType)); result += $"{operationName} of {TargetModelName(contextType)} failed!\n"; } } return(result); }
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 IModelConfigurator GetTargetConfigurator(string model) { var context = DbContextManager.Contexts.First(c => TargetModelName(c) == model); return(DbContextManager.GetConfigurator(context)); }