-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentProcessPlugin.cs
77 lines (66 loc) · 2.81 KB
/
DocumentProcessPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Text.Json;
using Bee.Base.Abstractions.Navigation;
using Bee.Base.Abstractions.Plugin;
using Bee.Base.Abstractions.Tasks;
using Bee.Base.ViewModels;
using Bee.Plugin.DocumentProcess.Models;
using Bee.Plugin.DocumentProcess.Navigation.Commands;
using Bee.Plugin.DocumentProcess.Tasks;
using Bee.Plugin.DocumentProcess.ViewModels;
using Bee.Plugin.DocumentProcess.Views;
using Ke.Bee.Localization.Providers.Abstractions;
using Ke.DocumentProcess.Abstrations;
using Ke.DocumentProcess.Pandoc;
using Ke.DocumentProcess.Pandoc.Models;
using Microsoft.Extensions.DependencyInjection;
namespace Bee.Plugin.DocumentProcess;
/// <summary>
/// 文档处理插件
/// </summary>
/// <param name="serviceProvider"></param>
public class DocumentProcessPlugin(IServiceProvider serviceProvider) : PluginBase(serviceProvider)
{
public override string PluginName => DocumentProcessConsts.PluginName;
public override void RegisterServices(IServiceCollection services)
{
services.AddTransient<IPlugin, DocumentProcessPlugin>();
services.AddSingleton<ILocalizationResourceContributor, DocumentProcessLocalizationResourceContributor>();
services.AddSingleton<INavigationCommand, DocumentConvertNavigationCommand>();
// 注入视图模型
services.AddTransient<IndexViewModel>();
// 注入文档转换页视图与视图模型
services.AddTransient<DocumentConvertView>();
services.AddTransient<DocumentConvertViewModel>();
// 任务列表视图模型
services.AddTransient<TaskListViewModel<DocumentConvertArguments>>();
// 任务处理器
services.AddTransient<ITaskHandler<DocumentConvertArguments>, DocumentConvertTaskHandler>();
//注册文档转换器
services.AddTransient<IDocumentConverter, PandocDocumentConverter>();
AddPandoc(services);
}
private void AddPandoc(IServiceCollection services)
{
// 插件根目录
var pluginRootPath = Path.Combine(AppSettings.PluginPath, PluginName);
// pandoc 配置文件
var pandocConfigPath = Path.Combine(pluginRootPath, "Configs", "pandoc.json");
// 文档转换配置
PandocDocumentProcessOptions pandocOptions;
// 优先使用配置文件中指定的配置
if (File.Exists(pandocConfigPath))
{
pandocOptions = JsonSerializer.Deserialize<PandocDocumentProcessOptions>(File.ReadAllBytes(pandocConfigPath))!;
}
else
{
pandocOptions = new PandocDocumentProcessOptions
{
PandocPath = Path.Combine(pluginRootPath, "packages/pandoc-3.6/pandoc.exe"),
PdfEnginePath = Path.Combine(pluginRootPath, "packages/TinyTeX/bin/windows/xelatex.exe")
};
}
services.AddSingleton(pandocOptions);
}
}