feat:完成导入功能
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
{
|
||||
public abstract class AbstractArticleImport
|
||||
{
|
||||
public virtual List<ArticleEntity> Import(Guid discussId, List<FileObject> fileObjs)
|
||||
{
|
||||
var articles = Convert(fileObjs);
|
||||
articles.ForEach(article =>
|
||||
{
|
||||
article.DiscussId = discussId;
|
||||
});
|
||||
return articles;
|
||||
}
|
||||
public abstract List<ArticleEntity> Convert(List<FileObject> fileObjs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
{
|
||||
internal class DefaultArticleImport : AbstractArticleImport
|
||||
{
|
||||
public override List<ArticleEntity> Convert(List<FileObject> fileObjs)
|
||||
{
|
||||
return fileObjs.OrderBy(x => x.FileName).Select(x => new ArticleEntity { Name = x.FileName, Content = x.Content }).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
{
|
||||
internal class VuePressArticleImport : AbstractArticleImport
|
||||
{
|
||||
public override List<ArticleEntity> Convert(List<FileObject> fileObjs)
|
||||
{
|
||||
//排序及处理目录名称
|
||||
var fileNameHandler = fileObjs.OrderBy(x => x.FileName).Select(x =>
|
||||
{
|
||||
var f = new FileObject { Content = x.Content };
|
||||
|
||||
//除去数字
|
||||
f.FileName = x.FileName.Split('.')[1];
|
||||
return f;
|
||||
});
|
||||
|
||||
|
||||
//处理内容
|
||||
var fileContentHandler= fileNameHandler.Select(x =>
|
||||
{
|
||||
var f = new FileObject { FileName = x.FileName };
|
||||
var lines = x.Content.SplitToLines();
|
||||
|
||||
var num = 0;
|
||||
var startIndex = 0;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (lines[i] == "---")
|
||||
{
|
||||
num++;
|
||||
if (num == 2)
|
||||
{
|
||||
startIndex = i;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
lines.ToList().RemoveRange(0, num);
|
||||
var result = string.Join(Environment.NewLine, lines);
|
||||
f.Content = result;
|
||||
return f;
|
||||
});
|
||||
|
||||
var output = fileContentHandler.Select(x => new ArticleEntity() { Content = x.Content, Name = x.FileName }).ToList();
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user