Пример #1
0
        protected KeyValuePair <string, TableInfo> GetNewTableInfo(string oldTableName, TableInfo oldTableInfo, string newTableName, List <TableColumn> newColumns, Dictionary <string, string> convertKeyDict, Dictionary <string, string> convertValueDict)
        {
            if (string.IsNullOrEmpty(newTableName))
            {
                newTableName = oldTableName;
            }
            if (newColumns == null || newColumns.Count == 0)
            {
                newColumns = oldTableInfo.Columns;
            }

            var newTableInfo = new TableInfo
            {
                Columns    = newColumns,
                TotalCount = oldTableInfo.TotalCount,
                RowFiles   = oldTableInfo.RowFiles
            };

            CliUtils.PrintRow(oldTableName, newTableName, oldTableInfo.TotalCount.ToString("#,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(newTableName, fileName);

                    if (convertKeyDict != null)
                    {
                        var oldRows =
                            TranslateUtils.JsonDeserialize <List <JObject> >(FileUtils.ReadText(oldFilePath, Encoding.UTF8));

                        var newRows = UpdateUtils.UpdateRows(oldRows, convertKeyDict, convertValueDict);

                        FileUtils.WriteText(newFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newRows));
                    }
                    else
                    {
                        FileUtils.CopyFile(oldFilePath, newFilePath);
                    }
                }
            }

            return(new KeyValuePair <string, TableInfo>(newTableName, newTableInfo));
        }
Пример #2
0
        public async Task UpdateSplitContentsTableInfoAsync(Dictionary <int, TableInfo> splitSiteTableDict, List <int> siteIdList, string oldTableName, TableInfo oldTableInfo, ConvertInfo converter)
        {
            if (converter == null)
            {
                converter = new ConvertInfo();
            }

            if (converter.IsAbandon)
            {
                await CliUtils.PrintRowAsync(oldTableName, "Abandon", "--");

                return;
            }

            if (converter.NewColumns == null || converter.NewColumns.Count == 0)
            {
                converter.NewColumns = oldTableInfo.Columns;
            }

            await CliUtils.PrintRowAsync(oldTableName, "#split-content#", oldTableInfo.TotalCount.ToString("#,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 newRows = new List <Dictionary <string, object> >();

                        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));

                        var siteIdWithRows = new Dictionary <int, List <Dictionary <string, object> > >();
                        foreach (var siteId in siteIdList)
                        {
                            siteIdWithRows.Add(siteId, new List <Dictionary <string, object> >());
                        }

                        foreach (var newRow in newRows)
                        {
                            if (newRow.ContainsKey(nameof(CMS.Model.ContentInfo.SiteId)))
                            {
                                var siteId = Convert.ToInt32(newRow[nameof(CMS.Model.ContentInfo.SiteId)]);
                                if (siteIdList.Contains(siteId))
                                {
                                    var rows = siteIdWithRows[siteId];
                                    rows.Add(newRow);
                                }
                            }
                        }

                        foreach (var siteId in siteIdList)
                        {
                            var siteRows      = siteIdWithRows[siteId];
                            var siteTableName = ContentDao.GetContentTableName(siteId);
                            var siteTableInfo = splitSiteTableDict[siteId];
                            siteTableInfo.TotalCount += siteRows.Count;

                            foreach (var tableColumn in converter.NewColumns)
                            {
                                if (!siteTableInfo.Columns.Any(t => StringUtils.EqualsIgnoreCase(t.AttributeName, tableColumn.AttributeName)))
                                {
                                    siteTableInfo.Columns.Add(tableColumn);
                                }
                            }

                            if (siteRows.Count > 0)
                            {
                                var siteTableFileName = $"{siteTableInfo.RowFiles.Count + 1}.json";
                                siteTableInfo.RowFiles.Add(siteTableFileName);
                                var filePath = NewTreeInfo.GetTableContentFilePath(siteTableName, siteTableFileName);
                                await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(siteRows));
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        public async Task <Tuple <string, TableInfo> > GetNewTableInfoAsync(string oldTableName, TableInfo oldTableInfo, ConvertInfo converter)
        {
            if (converter == null)
            {
                converter = new ConvertInfo();
            }

            if (converter.IsAbandon)
            {
                await CliUtils.PrintRowAsync(oldTableName, "Abandon", "--");

                return(null);
            }

            if (string.IsNullOrEmpty(converter.NewTableName))
            {
                converter.NewTableName = oldTableName;
            }
            if (converter.NewColumns == null || converter.NewColumns.Count == 0)
            {
                converter.NewColumns = oldTableInfo.Columns;
            }

            var newTableInfo = new TableInfo
            {
                Columns    = converter.NewColumns,
                TotalCount = oldTableInfo.TotalCount,
                RowFiles   = oldTableInfo.RowFiles
            };

            await CliUtils.PrintRowAsync(oldTableName, converter.NewTableName, oldTableInfo.TotalCount.ToString("#,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));
        }
Пример #4
0
        protected bool GetNewTableInfo(string oldTableName, TableInfo oldTableInfo, ConvertInfo converter, out string newTableName, out TableInfo newTableInfo)
        {
            newTableName = null;
            newTableInfo = null;

            if (converter == null)
            {
                converter = new ConvertInfo();
            }

            if (converter.IsAbandon)
            {
                CliUtils.PrintRow(oldTableName, "Abandon", "--");
                return(false);
            }

            if (string.IsNullOrEmpty(converter.NewTableName))
            {
                converter.NewTableName = oldTableName;
            }
            if (converter.NewColumns == null || converter.NewColumns.Count == 0)
            {
                converter.NewColumns = oldTableInfo.Columns;
            }

            newTableInfo = new TableInfo
            {
                Columns    = converter.NewColumns,
                TotalCount = oldTableInfo.TotalCount,
                RowFiles   = oldTableInfo.RowFiles
            };

            CliUtils.PrintRow(oldTableName, converter.NewTableName, oldTableInfo.TotalCount.ToString("#,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> >(FileUtils.ReadText(oldFilePath, Encoding.UTF8));

                        var newRows = UpdateUtils.UpdateRows(oldRows, converter.ConvertKeyDict, converter.ConvertValueDict);

                        FileUtils.WriteText(newFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newRows));
                    }
                    else
                    {
                        FileUtils.CopyFile(oldFilePath, newFilePath);
                    }
                }
            }

            newTableName = converter.NewTableName;

            return(true);
        }