public void Execute(ICommandContext context) { ILogger logger = context.Container.Resolve <ILogger>(); IRuntime runtime = context.Container.Resolve <IRuntime>(); IEnumerable <Type> migrationSteps = GetType().Assembly.FindTypes <IMigrationStep>(); string parentPath = Directory.GetParent(runtime.WorkingDirectory).FullName; string basePath = Path.Combine(parentPath, "Rocket.old"); basePath = Path.GetFullPath(basePath); if (!Directory.Exists(basePath)) { context.User.SendMessage($"Migration failed: Path \"{basePath}\" does not exist.", Color.Red); return; } string targetStep = context.Parameters.Get <string>(0, null); foreach (Type migrationStep in migrationSteps) { IMigrationStep step = (IMigrationStep)Activator.CreateInstance(migrationStep); if (targetStep != null && !step.Name.Equals(targetStep, StringComparison.OrdinalIgnoreCase)) { continue; } logger.LogInformation($"Executing migration step \"{step.Name}\"."); if (Debugger.IsAttached) { step.Migrate(context.Container, basePath); } else { try { step.Migrate(context.Container, basePath); } catch (Exception e) { logger.LogError($"Failed at migration step \"{step.Name}\": ", e); logger.LogWarning($"Use \"{context.CommandPrefix}{Name} {step.Name}\" to retry."); } } } logger.LogInformation("Legacy migration done.", Color.DarkGreen); }