public static async Task Execute(IJobContext context) { if (!CliUtils.ParseArgs(Options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (string.IsNullOrEmpty(_version)) { await CliUtils.PrintErrorAsync("未指定需要转换的备份数据版本号: version"); return; } if (string.IsNullOrEmpty(_directory)) { await CliUtils.PrintErrorAsync("未指定需要转换至最新版本的备份数据文件夹:directory"); return; } var oldTreeInfo = new TreeInfo(_directory); var newTreeInfo = new TreeInfo(Folder); if (!DirectoryUtils.IsDirectoryExists(oldTreeInfo.DirectoryPath)) { await CliUtils.PrintErrorAsync($"备份数据的文件夹 {oldTreeInfo.DirectoryPath} 不存在"); return; } DirectoryUtils.CreateDirectoryIfNotExists(newTreeInfo.DirectoryPath); UpdaterBase updater = null; if (_version == Updater36.Version) { updater = new Updater36(oldTreeInfo, newTreeInfo); } else if (_version == Updater40.Version) { updater = new Updater40(oldTreeInfo, newTreeInfo); } else if (_version == Updater41.Version) { updater = new Updater41(oldTreeInfo, newTreeInfo); } else if (_version == Updater50.Version) { updater = new Updater50(oldTreeInfo, newTreeInfo); } if (updater == null) { await Console.Out.WriteLineAsync($"当前支持的升级版本号必须是 {Updater36.Version},{Updater40.Version},{Updater41.Version},{Updater50.Version} 中的一项"); return; } var newVersion = "latest"; await Console.Out.WriteLineAsync($"备份版本: {_version}, 备份数据文件夹: {oldTreeInfo.DirectoryPath}"); await Console.Out.WriteLineAsync($"升级版本: {newVersion}, 升级数据文件夹: {newTreeInfo.DirectoryPath}"); var oldTableNames = TranslateUtils.JsonDeserialize <List <string> >(await FileUtils.ReadTextAsync(oldTreeInfo.TablesFilePath, Encoding.UTF8)); var newTableNames = new List <string>(); await CliUtils.PrintRowLineAsync(); await CliUtils.PrintRowAsync("备份表名称", "升级表名称", "总条数"); await CliUtils.PrintRowLineAsync(); var contentTableNameList = new List <string>(); UpdateUtils.LoadContentTableNameList(oldTreeInfo, "siteserver_PublishmentSystem", contentTableNameList); UpdateUtils.LoadContentTableNameList(oldTreeInfo, "wcm_PublishmentSystem", contentTableNameList); foreach (var oldTableName in oldTableNames) { var oldMetadataFilePath = oldTreeInfo.GetTableMetadataFilePath(oldTableName); if (!FileUtils.IsFileExists(oldMetadataFilePath)) { continue; } var oldTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(await FileUtils.ReadTextAsync(oldMetadataFilePath, Encoding.UTF8)); var tuple = await updater.UpdateTableInfoAsync(oldTableName, oldTableInfo, contentTableNameList); if (tuple != null) { newTableNames.Add(tuple.Item1); await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(tuple.Item1), Encoding.UTF8, TranslateUtils.JsonSerialize(tuple.Item2)); } } await FileUtils.WriteTextAsync(newTreeInfo.TablesFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newTableNames)); await CliUtils.PrintRowLineAsync(); await Console.Out.WriteLineAsync($"恭喜,成功从备份文件夹:{oldTreeInfo.DirectoryPath} 升级至新版本:{newTreeInfo.DirectoryPath} !"); }
public static async Task Execute(IJobContext context) { if (!CliUtils.ParseArgs(Options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (string.IsNullOrEmpty(_version)) { await CliUtils.PrintErrorAsync("Error, the {version} to update is empty"); return; } if (string.IsNullOrEmpty(_directory)) { await CliUtils.PrintErrorAsync("Error, the update {directory} name is empty"); return; } var oldTreeInfo = new TreeInfo(_directory); var newTreeInfo = new TreeInfo(Folder); if (!DirectoryUtils.IsDirectoryExists(oldTreeInfo.DirectoryPath)) { await CliUtils.PrintErrorAsync($"Error, directory {oldTreeInfo.DirectoryPath} not exists"); return; } DirectoryUtils.CreateDirectoryIfNotExists(newTreeInfo.DirectoryPath); UpdaterBase updater = null; if (_version == Updater36.Version) { updater = new Updater36(oldTreeInfo, newTreeInfo); } else if (_version == Updater40.Version) { updater = new Updater40(oldTreeInfo, newTreeInfo); } else if (_version == Updater41.Version) { updater = new Updater41(oldTreeInfo, newTreeInfo); } else if (_version == Updater50.Version) { updater = new Updater50(oldTreeInfo, newTreeInfo); } if (updater == null) { await Console.Out.WriteLineAsync($"Error, the currently supported update versions are {Updater36.Version},{Updater40.Version},{Updater41.Version},{Updater50.Version}"); return; } var newVersion = "latest"; await Console.Out.WriteLineAsync($"Old Version: {_version}, Old Directory: {oldTreeInfo.DirectoryPath}"); await Console.Out.WriteLineAsync($"New Version: {newVersion}, New Directory: {newTreeInfo.DirectoryPath}"); var oldTableNames = TranslateUtils.JsonDeserialize <List <string> >(await FileUtils.ReadTextAsync(oldTreeInfo.TablesFilePath, Encoding.UTF8)); var newTableNames = new List <string>(); await CliUtils.PrintRowLineAsync(); await CliUtils.PrintRowAsync("Old Table Name", "New Table Name", "Total Count"); await CliUtils.PrintRowLineAsync(); var contentTableNameList = new List <string>(); UpdateUtils.LoadContentTableNameList(oldTreeInfo, "siteserver_PublishmentSystem", contentTableNameList); UpdateUtils.LoadContentTableNameList(oldTreeInfo, "wcm_PublishmentSystem", contentTableNameList); foreach (var oldTableName in oldTableNames) { var oldMetadataFilePath = oldTreeInfo.GetTableMetadataFilePath(oldTableName); if (!FileUtils.IsFileExists(oldMetadataFilePath)) { continue; } var oldTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(await FileUtils.ReadTextAsync(oldMetadataFilePath, Encoding.UTF8)); var tuple = await updater.UpdateTableInfoAsync(oldTableName, oldTableInfo, contentTableNameList); if (tuple != null) { newTableNames.Add(tuple.Item1); await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(tuple.Item1), Encoding.UTF8, TranslateUtils.JsonSerialize(tuple.Item2)); } } await FileUtils.WriteTextAsync(newTreeInfo.TablesFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newTableNames)); await CliUtils.PrintRowLineAsync(); await Console.Out.WriteLineAsync("Well done! Thanks for Using SiteServer Cli Tool"); }
public static void Execute(string[] args) { if (!CliUtils.ParseArgs(Options, args)) { return; } if (_isHelp) { PrintUsage(); return; } if (string.IsNullOrEmpty(_version)) { Console.WriteLine("Error, Please input the version to update"); return; } if (string.IsNullOrEmpty(_directory)) { _directory = $"backup/{DateTime.Now:yyyy-MM-dd}"; } var oldTreeInfo = new TreeInfo(_directory); var newTreeInfo = new TreeInfo(Folder); if (!DirectoryUtils.IsDirectoryExists(oldTreeInfo.DirectoryPath)) { CliUtils.PrintError($"Error, Directory {oldTreeInfo.DirectoryPath} Not Exists"); return; } DirectoryUtils.CreateDirectoryIfNotExists(newTreeInfo.DirectoryPath); UpdaterBase updater = null; if (_version == Updater36.Version) { updater = new Updater36(oldTreeInfo, newTreeInfo); } else if (_version == Updater40.Version) { updater = new Updater40(oldTreeInfo, newTreeInfo); } else if (_version == Updater41.Version) { updater = new Updater41(oldTreeInfo, newTreeInfo); } else if (_version == Updater50.Version) { updater = new Updater50(oldTreeInfo, newTreeInfo); } if (updater == null) { Console.WriteLine($"Error, The currently supported update versions are {Updater36.Version}"); return; } var newVersion = "latest"; Console.WriteLine($"Old Version: {_version}, Old Directory: {oldTreeInfo.DirectoryPath}"); Console.WriteLine($"New Version: {newVersion}, New Directory: {newTreeInfo.DirectoryPath}"); var oldTableNames = TranslateUtils.JsonDeserialize <List <string> >(FileUtils.ReadText(oldTreeInfo.TablesFilePath, Encoding.UTF8)); var newTableNames = new List <string>(); CliUtils.PrintLine(); CliUtils.PrintRow("Old Table Name", "New Table Name", "Total Count"); CliUtils.PrintLine(); var contentTableNameList = new List <string>(); UpdateUtils.LoadContentTableNameList(oldTreeInfo, "siteserver_PublishmentSystem", contentTableNameList); UpdateUtils.LoadContentTableNameList(oldTreeInfo, "wcm_PublishmentSystem", contentTableNameList); foreach (var oldTableName in oldTableNames) { var oldMetadataFilePath = oldTreeInfo.GetTableMetadataFilePath(oldTableName); if (!FileUtils.IsFileExists(oldMetadataFilePath)) { continue; } var oldTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(FileUtils.ReadText(oldMetadataFilePath, Encoding.UTF8)); var kvp = updater.UpdateTableInfo(oldTableName, oldTableInfo, contentTableNameList); var newTableName = kvp.Key; var newTableInfo = kvp.Value; newTableNames.Add(newTableName); FileUtils.WriteText(newTreeInfo.GetTableMetadataFilePath(newTableName), Encoding.UTF8, TranslateUtils.JsonSerialize(newTableInfo)); } FileUtils.WriteText(newTreeInfo.TablesFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newTableNames)); CliUtils.PrintLine(); Console.WriteLine("Well done! Thanks for Using SiteServer Cli Tool"); }