Browse Source

cli

pull/1425/head siteserver-v6.6.14-beta
starlying 7 years ago
parent
commit
a8fe8b4731
  1. 3
      SiteServer.BackgroundPages/Cms/PageContentSearch.cs
  2. 53
      SiteServer.Cli/Jobs/UpdateJob.cs
  3. 6
      SiteServer.Cli/SiteServer.Cli.csproj
  4. 6
      SiteServer.Cli/Updater/ContentConverter.cs
  5. 167
      SiteServer.Cli/Updater/Model4/TableContent.cs
  6. 170
      SiteServer.Cli/Updater/Model5/TableContent.cs
  7. 54
      SiteServer.Cli/Updater/UpdateUtils.cs
  8. 6
      SiteServer.Cli/Updater/Updater3.cs
  9. 6
      SiteServer.Cli/Updater/Updater4.cs
  10. 6
      SiteServer.Cli/Updater/Updater5.cs
  11. 144
      SiteServer.Cli/Updater/UpdaterBase.cs

3
SiteServer.BackgroundPages/Cms/PageContentSearch.cs

@ -264,8 +264,9 @@ namespace SiteServer.BackgroundPages.Cms
: TextUtility.GetCommandsHtml(SiteInfo, _pluginMenus, contentInfo, PageUrl,
AuthRequest.AdminName, _isEdit);
ltlColumns.Text = $@"<td class=""text-center text-nowrap"">
ltlColumns.Text = $@"
{TextUtility.GetColumnsHtml(_nameValueCacheDict, SiteInfo, contentInfo, _attributesOfDisplay, _allStyleInfoList, _pluginColumns)}
<td class=""text-center text-nowrap"">
{specialHtml}
</td>";

53
SiteServer.Cli/Jobs/UpdateJob.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using NDesk.Options;
using SiteServer.Cli.Core;
using SiteServer.Cli.Updater;
using SiteServer.CMS.Core;
using SiteServer.Plugin;
using SiteServer.Utils;
@ -18,12 +19,15 @@ namespace SiteServer.Cli.Jobs
private static bool _isHelp;
private static string _directory;
private static string _version;
private static bool _contentSplit;
private static readonly OptionSet Options = new OptionSet() {
{ "d|directory=", "指定需要转换至最新版本的备份数据文件夹",
v => _directory = v },
{ "v|version=", "指定需要转换的备份数据版本号",
v => _version = v },
{ "content-split", "拆分内容表",
v => _contentSplit = v != null },
{ "h|help", "命令说明",
v => _isHelp = v != null }
};
@ -99,14 +103,15 @@ namespace SiteServer.Cli.Jobs
await CliUtils.PrintRowAsync("备份表名称", "升级表名称", "总条数");
await CliUtils.PrintRowLineAsync();
var siteIdList = new List<int>();
var tableNameListForContent = new List<string>();
var tableNameListForGovPublic = new List<string>();
var tableNameListForGovInteract = new List<string>();
var tableNameListForJob = new List<string>();
UpdateUtils.LoadContentTableNameList(oldTreeInfo, "siteserver_PublishmentSystem",
UpdateUtils.LoadSites(oldTreeInfo, "siteserver_PublishmentSystem", siteIdList,
tableNameListForContent, tableNameListForGovPublic, tableNameListForGovInteract, tableNameListForJob);
UpdateUtils.LoadContentTableNameList(oldTreeInfo, "wcm_PublishmentSystem",
UpdateUtils.LoadSites(oldTreeInfo, "wcm_PublishmentSystem", siteIdList,
tableNameListForContent, tableNameListForGovPublic, tableNameListForGovInteract, tableNameListForJob);
foreach (var oldTableName in oldTableNames)
@ -117,15 +122,51 @@ namespace SiteServer.Cli.Jobs
var oldTableInfo = TranslateUtils.JsonDeserialize<TableInfo>(await FileUtils.ReadTextAsync(oldMetadataFilePath, Encoding.UTF8));
var tuple = await updater.UpdateTableInfoAsync(oldTableName, oldTableInfo, tableNameListForContent, tableNameListForGovPublic, tableNameListForGovInteract, tableNameListForJob);
if (tuple != null)
if (StringUtils.ContainsIgnoreCase(tableNameListForContent, oldTableName))
{
newTableNames.Add(tuple.Item1);
if (_contentSplit)
{
var converter = ContentConverter.GetConverter(oldTableName, oldTableInfo.Columns);
var tupleList = await updater.GetNewSplitContentsTableInfoAsync(siteIdList, oldTableName,
oldTableInfo, converter);
foreach (var tuple in tupleList)
{
newTableNames.Add(tuple.Item2);
await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(tuple.Item2), Encoding.UTF8, TranslateUtils.JsonSerialize(tuple.Item3));
}
}
else
{
var converter = ContentConverter.GetConverter(oldTableName, oldTableInfo.Columns);
var tuple = await updater.GetNewTableInfoAsync(oldTableName, oldTableInfo, converter);
if (tuple != null)
{
newTableNames.Add(tuple.Item1);
await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(tuple.Item1), Encoding.UTF8, TranslateUtils.JsonSerialize(tuple.Item2));
}
}
}
else
{
var tuple = await updater.UpdateTableInfoAsync(oldTableName, oldTableInfo, tableNameListForGovPublic, tableNameListForGovInteract, tableNameListForJob);
if (tuple != null)
{
newTableNames.Add(tuple.Item1);
await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(tuple.Item1), Encoding.UTF8, TranslateUtils.JsonSerialize(tuple.Item2));
await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(tuple.Item1), Encoding.UTF8, TranslateUtils.JsonSerialize(tuple.Item2));
}
}
}
if (_contentSplit)
{
await UpdateUtils.UpdateSitesSplitTableNameAsync(newTreeInfo, DataProvider.SiteDao.TableName);
}
await FileUtils.WriteTextAsync(newTreeInfo.TablesFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newTableNames));
await CliUtils.PrintRowLineAsync();

6
SiteServer.Cli/SiteServer.Cli.csproj

@ -97,7 +97,7 @@
<Compile Include="Core\TreeInfo.cs" />
<Compile Include="Core\TableInfo.cs" />
<Compile Include="Core\TextLogInfo.cs" />
<Compile Include="Core\UpdateUtils.cs" />
<Compile Include="Updater\UpdateUtils.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Updater\ConvertInfo.cs" />
@ -118,7 +118,6 @@
<Compile Include="Updater\Model3\TableTableStyleItem.cs" />
<Compile Include="Updater\Model3\TableTag.cs" />
<Compile Include="Updater\Model3\TableUser.cs" />
<Compile Include="Updater\Model3\TableContent.cs" />
<Compile Include="Updater\Model3\TableContentGroup.cs" />
<Compile Include="Updater\Model4\TableAdministrator.cs" />
<Compile Include="Updater\Model4\TableAdministratorsInRoles.cs" />
@ -126,7 +125,7 @@
<Compile Include="Updater\Model4\TableChannel.cs" />
<Compile Include="Updater\Model4\TableChannelGroup.cs" />
<Compile Include="Updater\Model4\TableConfig.cs" />
<Compile Include="Updater\Model4\TableContent.cs" />
<Compile Include="Updater\ContentConverter.cs" />
<Compile Include="Updater\Model4\TableContentCheck.cs" />
<Compile Include="Updater\Model4\TableContentGroup.cs" />
<Compile Include="Updater\Model4\TableDbCache.cs" />
@ -157,7 +156,6 @@
<Compile Include="Updater\Model5\TableChannel.cs" />
<Compile Include="Updater\Model5\TableChannelGroup.cs" />
<Compile Include="Updater\Model5\TableConfig.cs" />
<Compile Include="Updater\Model5\TableContent.cs" />
<Compile Include="Updater\Model5\TableContentCheck.cs" />
<Compile Include="Updater\Model5\TableContentGroup.cs" />
<Compile Include="Updater\Model5\TableDbCache.cs" />

6
SiteServer.Cli/Updater/Model3/TableContent.cs → SiteServer.Cli/Updater/ContentConverter.cs

@ -6,9 +6,9 @@ using SiteServer.CMS.Model;
using SiteServer.Plugin;
using SiteServer.Utils;
namespace SiteServer.Cli.Updater.Model3
namespace SiteServer.Cli.Updater
{
public partial class TableContent
public partial class ContentConverter
{
[JsonProperty("id")]
public long Id { get; set; }
@ -116,7 +116,7 @@ namespace SiteServer.Cli.Updater.Model3
public DateTimeOffset AddDate { get; set; }
}
public partial class TableContent
public partial class ContentConverter
{
public static ConvertInfo GetConverter(string oldTableName, List<TableColumn> oldColumns)
{

167
SiteServer.Cli/Updater/Model4/TableContent.cs

@ -1,167 +0,0 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using SiteServer.CMS.Model;
using SiteServer.Plugin;
using SiteServer.Utils;
namespace SiteServer.Cli.Updater.Model4
{
public partial class TableContent
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("nodeID")]
public long NodeId { get; set; }
[JsonProperty("publishmentSystemID")]
public long PublishmentSystemId { get; set; }
[JsonProperty("addUserName")]
public string AddUserName { get; set; }
[JsonProperty("lastEditUserName")]
public string LastEditUserName { get; set; }
[JsonProperty("lastEditDate")]
public DateTimeOffset LastEditDate { get; set; }
[JsonProperty("taxis")]
public long Taxis { get; set; }
[JsonProperty("contentGroupNameCollection")]
public string ContentGroupNameCollection { get; set; }
[JsonProperty("tags")]
public string Tags { get; set; }
[JsonProperty("sourceID")]
public long SourceId { get; set; }
[JsonProperty("referenceID")]
public long ReferenceId { get; set; }
[JsonProperty("isChecked")]
public string IsChecked { get; set; }
[JsonProperty("checkedLevel")]
public long CheckedLevel { get; set; }
[JsonProperty("comments")]
public long Comments { get; set; }
[JsonProperty("photos")]
public long Photos { get; set; }
[JsonProperty("hits")]
public long Hits { get; set; }
[JsonProperty("hitsByDay")]
public long HitsByDay { get; set; }
[JsonProperty("hitsByWeek")]
public long HitsByWeek { get; set; }
[JsonProperty("hitsByMonth")]
public long HitsByMonth { get; set; }
[JsonProperty("lastHitsDate")]
public DateTimeOffset LastHitsDate { get; set; }
[JsonProperty("settingsXML")]
public string SettingsXml { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("subTitle")]
public string SubTitle { get; set; }
[JsonProperty("imageUrl")]
public string ImageUrl { get; set; }
[JsonProperty("videoUrl")]
public string VideoUrl { get; set; }
[JsonProperty("fileUrl")]
public string FileUrl { get; set; }
[JsonProperty("linkUrl")]
public string LinkUrl { get; set; }
[JsonProperty("content")]
public string Content { get; set; }
[JsonProperty("summary")]
public string Summary { get; set; }
[JsonProperty("author")]
public string Author { get; set; }
[JsonProperty("source")]
public string Source { get; set; }
[JsonProperty("isRecommend")]
public string IsRecommend { get; set; }
[JsonProperty("isHot")]
public string IsHot { get; set; }
[JsonProperty("isColor")]
public string IsColor { get; set; }
[JsonProperty("isTop")]
public string IsTop { get; set; }
[JsonProperty("addDate")]
public DateTimeOffset AddDate { get; set; }
}
public partial class TableContent
{
public static ConvertInfo GetConverter(string oldTableName, List<TableColumn> oldColumns)
{
return new ConvertInfo
{
NewTableName = oldTableName,
NewColumns = GetNewColumns(oldColumns),
ConvertKeyDict = ConvertKeyDict,
ConvertValueDict = ConvertValueDict
};
}
private static List<TableColumn> GetNewColumns(List<TableColumn> oldColumns)
{
var columns = new List<TableColumn>();
foreach (var tableColumnInfo in oldColumns)
{
if (StringUtils.EqualsIgnoreCase(tableColumnInfo.AttributeName, nameof(NodeId)))
{
tableColumnInfo.AttributeName = nameof(ContentInfo.ChannelId);
}
else if (StringUtils.EqualsIgnoreCase(tableColumnInfo.AttributeName, nameof(PublishmentSystemId)))
{
tableColumnInfo.AttributeName = nameof(ContentInfo.SiteId);
}
else if (StringUtils.EqualsIgnoreCase(tableColumnInfo.AttributeName, nameof(ContentGroupNameCollection)))
{
tableColumnInfo.AttributeName = nameof(ContentInfo.GroupNameCollection);
}
columns.Add(tableColumnInfo);
}
return columns;
}
private static readonly Dictionary<string, string> ConvertKeyDict =
new Dictionary<string, string>
{
{nameof(ContentInfo.ChannelId), nameof(NodeId)},
{nameof(ContentInfo.SiteId), nameof(PublishmentSystemId)},
{nameof(ContentInfo.GroupNameCollection), nameof(ContentGroupNameCollection)}
};
private static readonly Dictionary<string, string> ConvertValueDict = null;
}
}

170
SiteServer.Cli/Updater/Model5/TableContent.cs

@ -1,170 +0,0 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using SiteServer.CMS.Model;
using SiteServer.Plugin;
using SiteServer.Utils;
namespace SiteServer.Cli.Updater.Model5
{
public partial class TableContent
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("nodeID")]
public long NodeId { get; set; }
[JsonProperty("publishmentSystemID")]
public long PublishmentSystemId { get; set; }
[JsonProperty("addUserName")]
public string AddUserName { get; set; }
[JsonProperty("lastEditUserName")]
public string LastEditUserName { get; set; }
[JsonProperty("writingUserName")]
public string WritingUserName { get; set; }
[JsonProperty("lastEditDate")]
public DateTimeOffset LastEditDate { get; set; }
[JsonProperty("taxis")]
public long Taxis { get; set; }
[JsonProperty("contentGroupNameCollection")]
public string ContentGroupNameCollection { get; set; }
[JsonProperty("tags")]
public string Tags { get; set; }
[JsonProperty("sourceID")]
public long SourceId { get; set; }
[JsonProperty("referenceID")]
public long ReferenceId { get; set; }
[JsonProperty("isChecked")]
public string IsChecked { get; set; }
[JsonProperty("checkedLevel")]
public long CheckedLevel { get; set; }
[JsonProperty("comments")]
public long Comments { get; set; }
[JsonProperty("photos")]
public long Photos { get; set; }
[JsonProperty("hits")]
public long Hits { get; set; }
[JsonProperty("hitsByDay")]
public long HitsByDay { get; set; }
[JsonProperty("hitsByWeek")]
public long HitsByWeek { get; set; }
[JsonProperty("hitsByMonth")]
public long HitsByMonth { get; set; }
[JsonProperty("lastHitsDate")]
public DateTimeOffset LastHitsDate { get; set; }
[JsonProperty("settingsXML")]
public string SettingsXml { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("subTitle")]
public object SubTitle { get; set; }
[JsonProperty("imageUrl")]
public object ImageUrl { get; set; }
[JsonProperty("videoUrl")]
public object VideoUrl { get; set; }
[JsonProperty("fileUrl")]
public object FileUrl { get; set; }
[JsonProperty("linkUrl")]
public object LinkUrl { get; set; }
[JsonProperty("content")]
public object Content { get; set; }
[JsonProperty("summary")]
public object Summary { get; set; }
[JsonProperty("author")]
public object Author { get; set; }
[JsonProperty("source")]
public object Source { get; set; }
[JsonProperty("isRecommend")]
public string IsRecommend { get; set; }
[JsonProperty("isHot")]
public string IsHot { get; set; }
[JsonProperty("isColor")]
public string IsColor { get; set; }
[JsonProperty("isTop")]
public string IsTop { get; set; }
[JsonProperty("addDate")]
public DateTimeOffset AddDate { get; set; }
}
public partial class TableContent
{
public static ConvertInfo GetConverter(string oldTableName, List<TableColumn> oldColumns)
{
return new ConvertInfo
{
NewTableName = oldTableName,
NewColumns = GetNewColumns(oldColumns),
ConvertKeyDict = ConvertKeyDict,
ConvertValueDict = ConvertValueDict
};
}
private static List<TableColumn> GetNewColumns(List<TableColumn> oldColumns)
{
var columns = new List<TableColumn>();
foreach (var tableColumnInfo in oldColumns)
{
if (StringUtils.EqualsIgnoreCase(tableColumnInfo.AttributeName, nameof(NodeId)))
{
tableColumnInfo.AttributeName = nameof(ContentInfo.ChannelId);
}
else if (StringUtils.EqualsIgnoreCase(tableColumnInfo.AttributeName, nameof(PublishmentSystemId)))
{
tableColumnInfo.AttributeName = nameof(ContentInfo.SiteId);
}
else if (StringUtils.EqualsIgnoreCase(tableColumnInfo.AttributeName, nameof(ContentGroupNameCollection)))
{
tableColumnInfo.AttributeName = nameof(ContentInfo.GroupNameCollection);
}
columns.Add(tableColumnInfo);
}
return columns;
}
private static readonly Dictionary<string, string> ConvertKeyDict =
new Dictionary<string, string>
{
{nameof(ContentInfo.ChannelId), nameof(NodeId)},
{nameof(ContentInfo.SiteId), nameof(PublishmentSystemId)},
{nameof(ContentInfo.GroupNameCollection), nameof(ContentGroupNameCollection)}
};
private static readonly Dictionary<string, string> ConvertValueDict = null;
}
}

54
SiteServer.Cli/Core/UpdateUtils.cs → SiteServer.Cli/Updater/UpdateUtils.cs

@ -1,9 +1,13 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using SiteServer.Cli.Core;
using SiteServer.CMS.Model;
using SiteServer.Utils;
using TableInfo = SiteServer.Cli.Core.TableInfo;
namespace SiteServer.Cli.Core
namespace SiteServer.Cli.Updater
{
public static class UpdateUtils
{
@ -50,7 +54,7 @@ namespace SiteServer.Cli.Core
return newRows;
}
public static void LoadContentTableNameList(TreeInfo oldTreeInfo, string oldSiteTableName, List<string> tableNameListForContent, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob)
public static void LoadSites(TreeInfo oldTreeInfo, string oldSiteTableName, List<int> siteIdList, List<string> tableNameListForContent, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob)
{
var siteMetadataFilePath = oldTreeInfo.GetTableMetadataFilePath(oldSiteTableName);
if (FileUtils.IsFileExists(siteMetadataFilePath))
@ -64,6 +68,14 @@ namespace SiteServer.Cli.Core
{
var dict = TranslateUtils.JsonGetDictionaryIgnorecase(row);
object obj;
if (dict.TryGetValue("PublishmentSystemID",
out obj))
{
if (obj != null && !siteIdList.Contains((int)obj))
{
siteIdList.Add((int)obj);
}
}
if (dict.TryGetValue("AuxiliaryTableForContent",
out obj))
{
@ -108,5 +120,43 @@ namespace SiteServer.Cli.Core
}
}
}
public static string GetSplitContentTableName(int siteId)
{
return $"model_SiteContent_{siteId}";
}
public static async Task UpdateSitesSplitTableNameAsync(TreeInfo newTreeInfo, string newSiteTableName)
{
var siteMetadataFilePath = newTreeInfo.GetTableMetadataFilePath(newSiteTableName);
if (FileUtils.IsFileExists(siteMetadataFilePath))
{
var siteTableInfo = TranslateUtils.JsonDeserialize<TableInfo>(FileUtils.ReadText(siteMetadataFilePath, Encoding.UTF8));
foreach (var fileName in siteTableInfo.RowFiles)
{
var filePath = newTreeInfo.GetTableContentFilePath(newSiteTableName, 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);
object obj;
if (dict.TryGetValue("Id",
out obj))
{
if (obj != null)
{
var siteId = (int) obj;
dict[nameof(SiteInfo.TableName)] = GetSplitContentTableName(siteId);
}
}
newRows.Add(dict);
}
await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newRows));
}
}
}
}
}

6
SiteServer.Cli/Updater/Updater3.cs

@ -18,7 +18,7 @@ namespace SiteServer.Cli.Updater
{
}
public override async Task<Tuple<string, TableInfo>> UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List<string> tableNameListForContent, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob)
public override async Task<Tuple<string, TableInfo>> UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob)
{
ConvertInfo converter = null;
@ -174,10 +174,6 @@ namespace SiteServer.Cli.Updater
{
converter = TableGovPublicIdentifierSeq.Converter;
}
else if (StringUtils.ContainsIgnoreCase(tableNameListForContent, oldTableName))
{
converter = TableContent.GetConverter(oldTableName, oldTableInfo.Columns);
}
else if (StringUtils.ContainsIgnoreCase(tableNameListForGovPublic, oldTableName))
{
converter = TableGovPublicContent.GetConverter(oldTableInfo.Columns);

6
SiteServer.Cli/Updater/Updater4.cs

@ -19,7 +19,7 @@ namespace SiteServer.Cli.Updater
}
public override async Task<Tuple<string, TableInfo>> UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List<string> tableNameListForContent, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob)
public override async Task<Tuple<string, TableInfo>> UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob)
{
ConvertInfo converter = null;
@ -179,10 +179,6 @@ namespace SiteServer.Cli.Updater
{
converter = TableGovPublicIdentifierSeq.Converter;
}
else if (StringUtils.ContainsIgnoreCase(tableNameListForContent, oldTableName))
{
converter = TableContent.GetConverter(oldTableName, oldTableInfo.Columns);
}
else if (StringUtils.ContainsIgnoreCase(tableNameListForGovPublic, oldTableName))
{
converter = TableGovPublicContent.GetConverter(oldTableInfo.Columns);

6
SiteServer.Cli/Updater/Updater5.cs

@ -19,7 +19,7 @@ namespace SiteServer.Cli.Updater
}
public override async Task<Tuple<string, TableInfo>> UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List<string> tableNameListForContent, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob)
public override async Task<Tuple<string, TableInfo>> UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob)
{
ConvertInfo converter = null;
@ -183,10 +183,6 @@ namespace SiteServer.Cli.Updater
{
converter = TableGovPublicIdentifierSeq.Converter;
}
else if (StringUtils.ContainsIgnoreCase(tableNameListForContent, oldTableName))
{
converter = TableContent.GetConverter(oldTableName, oldTableInfo.Columns);
}
else if (StringUtils.ContainsIgnoreCase(tableNameListForGovPublic, oldTableName))
{
converter = TableGovPublicContent.GetConverter(oldTableInfo.Columns);

144
SiteServer.Cli/Updater/UpdaterBase.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
@ -20,7 +21,7 @@ namespace SiteServer.Cli.Updater
protected TreeInfo NewTreeInfo { get; }
protected async Task<Tuple<string, TableInfo>> GetNewTableInfoAsync(string oldTableName, TableInfo oldTableInfo, ConvertInfo converter)
public async Task<Tuple<string, TableInfo>> GetNewTableInfoAsync(string oldTableName, TableInfo oldTableInfo, ConvertInfo converter)
{
if (converter == null)
{
@ -51,36 +52,149 @@ namespace SiteServer.Cli.Updater
await CliUtils.PrintRowAsync(oldTableName, converter.NewTableName, oldTableInfo.TotalCount.ToString("#,0"));
var i = 0;
if (oldTableInfo.RowFiles.Count > 0)
{
var i = 0;
using (var progress = new ProgressBar())
{
foreach (var fileName in oldTableInfo.RowFiles)
{
progress.Report((double)i++ / oldTableInfo.RowFiles.Count);
var oldFilePath = OldTreeInfo.GetTableContentFilePath(oldTableName, fileName);
var newFilePath = NewTreeInfo.GetTableContentFilePath(converter.NewTableName, fileName);
if (converter.ConvertKeyDict != null)
{
var oldRows =
TranslateUtils.JsonDeserialize<List<JObject>>(await FileUtils.ReadTextAsync(oldFilePath, Encoding.UTF8));
var newRows = UpdateUtils.UpdateRows(oldRows, converter.ConvertKeyDict, converter.ConvertValueDict);
await FileUtils.WriteTextAsync(newFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newRows));
}
else
{
FileUtils.CopyFile(oldFilePath, newFilePath);
}
}
}
}
return new Tuple<string, TableInfo>(converter.NewTableName, newTableInfo);
}
public async Task<List<Tuple<int, string, TableInfo>>> GetNewSplitContentsTableInfoAsync(List<int> siteIdList, string oldTableName, TableInfo oldTableInfo, ConvertInfo converter)
{
if (converter == null)
{
converter = new ConvertInfo();
}
if (converter.IsAbandon)
{
await CliUtils.PrintRowAsync(oldTableName, "Abandon", "--");
return null;
}
if (converter.NewColumns == null || converter.NewColumns.Count == 0)
{
converter.NewColumns = oldTableInfo.Columns;
}
await CliUtils.PrintRowAsync(oldTableName, "#split-content#", oldTableInfo.TotalCount.ToString("#,0"));
var newRows = new List<Dictionary<string, object>>();
foreach (var fileName in oldTableInfo.RowFiles)
{
var oldFilePath = OldTreeInfo.GetTableContentFilePath(oldTableName, fileName);
var oldRows =
TranslateUtils.JsonDeserialize<List<JObject>>(await FileUtils.ReadTextAsync(oldFilePath, Encoding.UTF8));
newRows.AddRange(UpdateUtils.UpdateRows(oldRows, converter.ConvertKeyDict, converter.ConvertValueDict));
}
using (var progress = new ProgressBar())
var siteIdWithRows = new Dictionary<int, List<Dictionary<string, object>>>();
foreach (var siteId in siteIdList)
{
foreach (var fileName in oldTableInfo.RowFiles)
siteIdWithRows.Add(siteId, new List<Dictionary<string, object>>());
}
foreach (var newRow in newRows)
{
if (newRow.ContainsKey("siteId"))
{
progress.Report((double)i++ / oldTableInfo.RowFiles.Count);
var siteId = (int)newRow["siteId"];
if (siteIdList.Contains(siteId))
{
var rows = siteIdWithRows[siteId];
rows.Add(newRow);
}
}
}
var oldFilePath = OldTreeInfo.GetTableContentFilePath(oldTableName, fileName);
var newFilePath = NewTreeInfo.GetTableContentFilePath(converter.NewTableName, fileName);
var tupleList = new List<Tuple<int, string, TableInfo>>();
if (converter.ConvertKeyDict != null)
foreach (var siteId in siteIdList)
{
var rows = siteIdWithRows[siteId];
var tableName = UpdateUtils.GetSplitContentTableName(siteId);
var tableInfo = new TableInfo
{
Columns = converter.NewColumns,
TotalCount = rows.Count,
RowFiles = new List<string>()
};
if (tableInfo.TotalCount > 0)
{
var current = 1;
if (tableInfo.TotalCount > CliUtils.PageSize)
{
var oldRows =
TranslateUtils.JsonDeserialize<List<JObject>>(await FileUtils.ReadTextAsync(oldFilePath, Encoding.UTF8));
var pageCount = (int)Math.Ceiling((double)tableInfo.TotalCount / CliUtils.PageSize);
using (var progress = new ProgressBar())
{
for (; current <= pageCount; current++)
{
progress.Report((double)(current - 1) / pageCount);
var newRows = UpdateUtils.UpdateRows(oldRows, converter.ConvertKeyDict, converter.ConvertValueDict);
var fileName = $"{current}.json";
tableInfo.RowFiles.Add(fileName);
var offset = (current - 1) * CliUtils.PageSize;
var limit = tableInfo.TotalCount - offset < CliUtils.PageSize ? tableInfo.TotalCount - offset : CliUtils.PageSize;
await FileUtils.WriteTextAsync(newFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newRows));
var pageRows = rows.Skip(offset).Take(limit);
//var rows = DataProvider.DatabaseDao.GetPageObjects(tableName, identityColumnName, offset, limit);
var filePath = NewTreeInfo.GetTableContentFilePath(tableName, fileName);
await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(pageRows));
}
}
}
else
{
FileUtils.CopyFile(oldFilePath, newFilePath);
var fileName = $"{current}.json";
tableInfo.RowFiles.Add(fileName);
var filePath = NewTreeInfo.GetTableContentFilePath(tableName, fileName);
await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(rows));
}
}
tupleList.Add(new Tuple<int, string, TableInfo>(siteId, tableName, tableInfo));
}
return new Tuple<string, TableInfo>(converter.NewTableName, newTableInfo);
return tupleList;
}
public abstract Task<Tuple<string, TableInfo>> UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List<string> tableNameListForContent, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob);
public abstract Task<Tuple<string, TableInfo>> UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List<string> tableNameListForGovPublic, List<string> tableNameListForGovInteract, List<string> tableNameListForJob);
}
}
Loading…
Cancel
Save