void SetExecuted(UpgradeContext uctx, string upgradeFile) { Console.WriteLine(); if (!File.Exists(upgradeFile)) { SafeConsole.WriteLineColor(ConsoleColor.Yellow, $"File {upgradeFile} not found... let's create one!"); Console.WriteLine(); var result = Upgrades.Select(a => a.Key).And("<< Mark ALL upgrades as executed >>").ChooseConsole(a => a.ToString(), "What do you think is the next upgrade that you should run? (the previous ones will be marked as executed)"); File.WriteAllLines(upgradeFile, result == null ? new string[0] : Upgrades.TakeWhile(a => a.Key != result).Select(a => a.Key).ToArray()); Console.WriteLine(); SafeConsole.WriteLineColor(ConsoleColor.Green, $"File {upgradeFile} created!"); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, $"(this file contains the Upgrades that have been run, and should be commited to git)"); } else { SafeConsole.WriteLineColor(ConsoleColor.DarkGray, $"Reading {upgradeFile}..."); } var list = File.ReadAllLines(upgradeFile); foreach (var v in this.Upgrades) { v.IsExecuted = list.Contains(v.GetType().Name); } }
static void Main(string[] args) { Console.WriteLine(); Console.WriteLine(" ..:: Welcome to Signum Upgrade ::.."); Console.WriteLine(); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, " This application helps you upgrade a Signum Framework application by modifying your source code."); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, " The closer your application resembles Southwind, the better it works."); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, " Review all the changes carefully"); Console.WriteLine(); var uctx = UpgradeContext.CreateFromCurrentDirectory(); Console.Write(" RootFolder = "); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, uctx.RootFolder); Console.Write(" ApplicationName = "); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, uctx.ApplicationName); new CodeUpgradeRunner { new Upgrade_20200920_moment_to_luxon(), new Upgrade_20200920_remove_numbro(), new Upgrade_20200921_corejs(), new Upgrade_20200929_WebAuthn(), new Upgrade_20201110_DotNet5(), new Upgrade_20201118_FixSwagger(), new Upgrade_20201119_SplitPolyfills(), new Upgrade_20201123_Typescript41(), new Upgrade_20201124_CombinedUserChartPart(), new Upgrade_20201124_FixImportUserAssets(), new Upgrade_20201125_ReactBootstrap14(), new Upgrade_20201126_AddWebAppRestart(), new Upgrade_20201210_NavigatorView(), new Upgrade_20201220_React17(), new Upgrade_20201223_IndexErrorHandling(), new Upgrade_20201230_TensorFlow(), new Upgrade_20201231_AnyCPU(), new Upgrade_20210108_RemoveLangVersion(), new Upgrade_20210113_TimezoneInDockerfile(), new Upgrade_20210119_DeepL(), new Upgrade_20210205_ErrorHandling(), new Upgrade_20210210_UpgradeNugets(), new Upgrade_20210216_RegisterTranslatableRoutes(), new Upgrade_20210302_TypeScript42(), new Upgrade_20210325_FixDllPlugin(), new Upgrade_20210331_ReactWidgets5(), new Upgrade_20210414_SimplifyQueryTokenString(), new Upgrade_20210415_ReactWidgets503(), new Upgrade_20210511_MSAL2(), new Upgrade_20210513_UpdateNugets(), }.Run(uctx); }
public void Run(UpgradeContext uctx) { var upgradeFile = Path.Combine(uctx.RootFolder, "SignumUpgrade.txt"); while (true) { SetExecuted(uctx, upgradeFile); if (!Prompt(uctx, upgradeFile)) { return; } } }
bool Prompt(UpgradeContext uctx, string signumUpgradeFile) { Draw(); if (Upgrades.All(a => a.IsExecuted)) { SafeConsole.WriteLineColor(ConsoleColor.Green, "All Upgrades are executed!"); return(false); } else { var first = Upgrades.FirstEx(a => !a.IsExecuted); if (!SafeConsole.Ask("Run next Upgrade ({0})?".FormatWith(first.Key))) { return(false); } return(ExecuteUpgrade(first, uctx, signumUpgradeFile)); } }
static void Main(string[] args) { Console.WriteLine(); Console.WriteLine(" ..:: Welcome to Signum Upgrade ::.."); Console.WriteLine(); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, " This application helps you upgrade a Signum Framework application by modifying your source code."); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, " The closer your application resembles Southwind, the better it works."); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, " Review all the changes carefully"); Console.WriteLine(); var uctx = UpgradeContext.CreateFromCurrentDirectory(); Console.Write(" RootFolder = "); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, uctx.RootFolder); Console.Write(" ApplicationName = "); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, uctx.ApplicationName); new CodeUpgradeRunner { new Upgrade_20200920_moment_to_luxon(), new Upgrade_20200920_remove_numbro(), new Upgrade_20200921_corejs(), new Upgrade_20200929_WebAuthn(), new Upgrade_20201110_DotNet5(), new Upgrade_20201118_FixSwagger(), new Upgrade_20201119_SplitPolyfills(), new Upgrade_20201123_Typescript41(), new Upgrade_20201124_CombinedUserChartPart(), new Upgrade_20201124_FixImportUserAssets(), new Upgrade_20201125_ReactBootstrap14(), new Upgrade_20201126_AddWebAppRestart(), new Upgrade_20201210_NavigatorView(), new Upgrade_20201220_React17(), new Upgrade_20201223_IndexErrorHandling(), }.Run(uctx); }
private bool ExecuteUpgrade(CodeUpgradeBase upgrade, UpgradeContext uctx, string signumUpgradeFile) { while (IsDirtyExceptSubmodules(uctx.RootFolder)) { Console.WriteLine(); Console.WriteLine("There are changes in the git repo. Commit or reset the changes and press [Enter]"); Console.ReadLine(); } Console.WriteLine(); try { uctx.HasWarnings = WarningLevel.None; upgrade.Execute(uctx); } catch (Exception ex) { SafeConsole.WriteLineColor(ConsoleColor.Red, ex.Message); SafeConsole.WriteLineColor(ConsoleColor.DarkGray, ex.Message); if (!SafeConsole.Ask("Do you want to skip {0} and mark it as executed?".FormatWith(upgrade.Key))) { return(false); } } File.AppendAllLines(signumUpgradeFile, new[] { upgrade.Key }); Console.WriteLine(); switch (uctx.HasWarnings) { case WarningLevel.None: SafeConsole.WriteColor(ConsoleColor.Green, "Upgrade finished sucessfully!"); break; case WarningLevel.Warning: SafeConsole.WriteColor(ConsoleColor.Yellow, "Upgrade finished with Warnings..."); break; case WarningLevel.Error: SafeConsole.WriteColor(ConsoleColor.Red, "Upgrade finished with Errors..."); break; default: throw new UnexpectedValueException(uctx.HasWarnings); } Console.WriteLine(" Please review the changes..."); Console.WriteLine(); switch (SafeConsole.Ask("What should we do next?", "commit", "retry", "exit")) { case "commit": using (Repository rep = new Repository(uctx.RootFolder)) { if (rep.RetrieveStatus().IsDirty) { Commands.Stage(rep, "*"); var sign = rep.Config.BuildSignature(DateTimeOffset.Now); rep.Commit(upgrade.Key, sign, sign); SafeConsole.WriteLineColor(ConsoleColor.White, "A commit with text message '{0}' has been created".FormatWith(upgrade.Key)); } else { Console.WriteLine("Nothing to commit"); } } return(true); case "retry": while (IsDirtyExceptSubmodules(uctx.RootFolder)) { Console.WriteLine("Revert all the changes in git and press [Enter]"); Console.ReadLine(); } return(true); case "exit": case null: return(false); } Console.ReadLine(); return(true); }
public abstract void Execute(UpgradeContext uctx);
public CodeFile(string filePath, UpgradeContext uctx) { this.FilePath = filePath; this.Uctx = uctx; }