public static void LoadSites(TreeInfo oldTreeInfo, List <int> siteIdList, List <string> tableNameListForContent, List <string> tableNameListForGovPublic, List <string> tableNameListForGovInteract, List <string> tableNameListForJob) { foreach (string oldSiteTableName in TableSite.OldTableNames) { var siteMetadataFilePath = oldTreeInfo.GetTableMetadataFilePath(oldSiteTableName); if (FileUtils.IsFileExists(siteMetadataFilePath)) { var siteTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(FileUtils.ReadText(siteMetadataFilePath, Encoding.UTF8)); foreach (var fileName in siteTableInfo.RowFiles) { var filePath = oldTreeInfo.GetTableContentFilePath(oldSiteTableName, fileName); var rows = TranslateUtils.JsonDeserialize <List <JObject> >(FileUtils.ReadText(filePath, Encoding.UTF8)); foreach (var row in rows) { var dict = TranslateUtils.JsonGetDictionaryIgnorecase(row); if (dict.ContainsKey(nameof(TableSite.PublishmentSystemId))) { var value = Convert.ToInt32(dict[nameof(TableSite.PublishmentSystemId)]); if (value > 0 && !siteIdList.Contains(value)) { siteIdList.Add(value); } } if (dict.ContainsKey(nameof(TableSite.AuxiliaryTableForContent))) { var value = Convert.ToString(dict[nameof(TableSite.AuxiliaryTableForContent)]); if (!string.IsNullOrEmpty(value) && !tableNameListForContent.Contains(value)) { tableNameListForContent.Add(value); } } if (dict.ContainsKey(nameof(TableSite.AuxiliaryTableForGovInteract))) { var value = Convert.ToString(dict[nameof(TableSite.AuxiliaryTableForGovInteract)]); if (!string.IsNullOrEmpty(value) && !tableNameListForGovInteract.Contains(value)) { tableNameListForGovInteract.Add(value); } } if (dict.ContainsKey(nameof(TableSite.AuxiliaryTableForGovPublic))) { var value = Convert.ToString(dict[nameof(TableSite.AuxiliaryTableForGovPublic)]); if (!string.IsNullOrEmpty(value) && !tableNameListForGovPublic.Contains(value)) { tableNameListForGovPublic.Add(value); } } if (dict.ContainsKey(nameof(TableSite.AuxiliaryTableForJob))) { var value = Convert.ToString(dict[nameof(TableSite.AuxiliaryTableForJob)]); if (!string.IsNullOrEmpty(value) && !tableNameListForJob.Contains(value)) { tableNameListForJob.Add(value); } } } } } } }
public static List <Dictionary <string, object> > UpdateRows(List <JObject> oldRows, Dictionary <string, string> convertKeyDict, Dictionary <string, string> convertValueDict) { var newRows = new List <Dictionary <string, object> >(); foreach (var oldRow in oldRows) { var newRow = TranslateUtils.JsonGetDictionaryIgnorecase(oldRow); foreach (var key in convertKeyDict.Keys) { var value = newRow[convertKeyDict[key]]; var valueDictKey = GetConvertValueDictKey(key, value); if (convertValueDict != null && convertValueDict.ContainsKey(valueDictKey)) { value = convertValueDict[valueDictKey]; } newRow[key] = value; } newRows.Add(newRow); } return(newRows); }
public static void LoadContentTableNameList(TreeInfo oldTreeInfo, string oldSiteTableName, List <string> contentTableNameList) { var siteMetadataFilePath = oldTreeInfo.GetTableMetadataFilePath(oldSiteTableName); if (FileUtils.IsFileExists(siteMetadataFilePath)) { var siteTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(FileUtils.ReadText(siteMetadataFilePath, Encoding.UTF8)); foreach (var fileName in siteTableInfo.RowFiles) { var filePath = oldTreeInfo.GetTableContentFilePath(oldSiteTableName, fileName); var rows = TranslateUtils.JsonDeserialize <List <JObject> >(FileUtils.ReadText(filePath, Encoding.UTF8)); foreach (var row in rows) { var dict = TranslateUtils.JsonGetDictionaryIgnorecase(row); object obj; if (dict.TryGetValue("AuxiliaryTableForContent", out obj)) { if (obj != null && !contentTableNameList.Contains(obj.ToString())) { contentTableNameList.Add(obj.ToString()); } } if (dict.TryGetValue("AuxiliaryTableForGovInteract", out obj)) { if (obj != null && !contentTableNameList.Contains(obj.ToString())) { contentTableNameList.Add(obj.ToString()); } } if (dict.TryGetValue("AuxiliaryTableForGovPublic", out obj)) { if (obj != null && !contentTableNameList.Contains(obj.ToString())) { contentTableNameList.Add(obj.ToString()); } } if (dict.TryGetValue("AuxiliaryTableForJob", out obj)) { if (obj != null && !contentTableNameList.Contains(obj.ToString())) { contentTableNameList.Add(obj.ToString()); } } if (dict.TryGetValue("AuxiliaryTableForVote", out obj)) { if (obj != null && !contentTableNameList.Contains(obj.ToString())) { contentTableNameList.Add(obj.ToString()); } } } } } }
public static async Task UpdateSitesSplitTableNameAsync(TreeInfo newTreeInfo, Dictionary <int, TableInfo> splitSiteTableDict) { var siteMetadataFilePath = newTreeInfo.GetTableMetadataFilePath(DataProvider.SiteDao.TableName); if (FileUtils.IsFileExists(siteMetadataFilePath)) { var siteTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(FileUtils.ReadText(siteMetadataFilePath, Encoding.UTF8)); foreach (var fileName in siteTableInfo.RowFiles) { var filePath = newTreeInfo.GetTableContentFilePath(DataProvider.SiteDao.TableName, fileName); var oldRows = TranslateUtils.JsonDeserialize <List <JObject> >(FileUtils.ReadText(filePath, Encoding.UTF8)); var newRows = new List <Dictionary <string, object> >(); foreach (var row in oldRows) { var dict = TranslateUtils.JsonGetDictionaryIgnorecase(row); if (dict.ContainsKey(nameof(SiteInfo.Id))) { var siteId = Convert.ToInt32(dict[nameof(SiteInfo.Id)]); dict[nameof(SiteInfo.TableName)] = ContentDao.GetContentTableName(siteId); } newRows.Add(dict); } await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newRows)); } } //foreach (var siteId in splitSiteTableDict.Keys) //{ // var siteTableInfo = splitSiteTableDict[siteId]; // var siteTableName = UpdateUtils.GetSplitContentTableName(siteId); // siteTableInfo.Columns //} //var tableFilePath = newTreeInfo.GetTableMetadataFilePath(DataProvider.TableDao.TableName); //if (FileUtils.IsFileExists(tableFilePath)) //{ // var siteTableInfo = TranslateUtils.JsonDeserialize<TableInfo>(FileUtils.ReadText(tableFilePath, Encoding.UTF8)); // var filePath = newTreeInfo.GetTableContentFilePath(DataProvider.SiteDao.TableName, siteTableInfo.RowFiles[siteTableInfo.RowFiles.Count]); // var tableInfoList = TranslateUtils.JsonDeserialize<List<CMS.Model.TableInfo>>(FileUtils.ReadText(filePath, Encoding.UTF8)); // await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(tableInfoList)); //} }
public static List <Dictionary <string, object> > UpdateRows(List <JObject> oldRows, Dictionary <string, string> convertDict) { var newRows = new List <Dictionary <string, object> >(); foreach (var oldRow in oldRows) { var newRow = TranslateUtils.JsonGetDictionaryIgnorecase(oldRow); foreach (var convertKey in convertDict.Keys) { newRow[convertKey] = newRow[convertDict[convertKey]]; } newRows.Add(newRow); } return(newRows); }
public static List <Dictionary <string, object> > UpdateRows(List <JObject> oldRows, Dictionary <string, string> convertKeyDict, Dictionary <string, string> convertValueDict, Func <Dictionary <string, object>, Dictionary <string, object> > process) { var newRows = new List <Dictionary <string, object> >(); foreach (var oldRow in oldRows) { var newRow = TranslateUtils.JsonGetDictionaryIgnorecase(oldRow); foreach (var key in convertKeyDict.Keys) { var convertKey = convertKeyDict[key]; object value; if (newRow.TryGetValue(convertKey, out value)) { var valueDictKey = GetConvertValueDictKey(key, value); if (convertValueDict != null && convertValueDict.ContainsKey(valueDictKey)) { value = convertValueDict[valueDictKey]; } newRow[key] = value; } //var value = newRow [convertKeyDict[key]]; //var valueDictKey = GetConvertValueDictKey(key, value); //if (convertValueDict != null && convertValueDict.ContainsKey(valueDictKey)) //{ // value = convertValueDict[valueDictKey]; //} //newRow[key] = value; } if (process != null) { newRow = process(newRow); } newRows.Add(newRow); } return(newRows); }
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>(); var siteMetadataFilePath = oldTreeInfo.GetTableMetadataFilePath("siteserver_PublishmentSystem"); if (FileUtils.IsFileExists(siteMetadataFilePath)) { var siteTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(FileUtils.ReadText(siteMetadataFilePath, Encoding.UTF8)); foreach (var fileName in siteTableInfo.RowFiles) { var filePath = oldTreeInfo.GetTableContentFilePath("siteserver_PublishmentSystem", fileName); var rows = TranslateUtils.JsonDeserialize <List <JObject> >(FileUtils.ReadText(filePath, Encoding.UTF8)); foreach (var row in rows) { var dict = TranslateUtils.JsonGetDictionaryIgnorecase(row); object obj; if (dict.TryGetValue(nameof(TableSite.AuxiliaryTableForContent), out obj)) { if (obj != null) { contentTableNameList.Add(obj.ToString()); } } } } } 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; CliUtils.PrintRow(oldTableName, newTableName, oldTableInfo.TotalCount.ToString("#,0")); newTableNames.Add(newTableName); FileUtils.WriteText(newTreeInfo.GetTableMetadataFilePath(newTableName), Encoding.UTF8, TranslateUtils.JsonSerialize(newTableInfo)); //DataProvider.DatabaseDao.CreateSystemTable(tableName, tableInfo.Columns); //foreach (var rowFileName in tableInfo.RowFiles) //{ // var filePath = PathUtils.Combine(oldDbFilesDirectoryPath, rowFileName); // var objects = TranslateUtils.JsonDeserialize<List<JObject>>(FileUtils.ReadText(filePath, Encoding.UTF8)); // DataProvider.DatabaseDao.SyncObjects(tableName, objects, tableInfo.Columns); //} } FileUtils.WriteText(newTreeInfo.TablesFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newTableNames)); CliUtils.PrintLine(); Console.WriteLine("Well done! Thanks for Using SiteServer Cli Tool"); }