同步操作将从 Gitee 极速下载/SmartCode 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using System;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;using System.Threading.Tasks;using SmartCode.Configuration;using System.IO;using SmartCode.Configuration.ConfigBuilders;using System.Reflection;using HandlebarsDotNet;namespace SmartCode.App{public class SmartCodeApp{public SmartCodeOptions SmartCodeOptions { get; }public String AppDirectory { get { return AppDomain.CurrentDomain.BaseDirectory; } }public IConfigBuilder ConfigBuilder { get; private set; }public IServiceCollection Services { get { return SmartCodeOptions.Services; } }public IServiceProvider ServiceProvider { get; private set; }public Project Project { get; private set; }public string ConfigPath { get { return SmartCodeOptions.ConfigPath; } }public ILogger<SmartCodeApp> Logger { get; private set; }public SmartCodeApp(SmartCodeOptions smartCodeOptions){SmartCodeOptions = smartCodeOptions;BuildProject();RegisterServices();}private void BuildProject(){var pathExtension = Path.GetExtension(ConfigPath).ToUpper();switch (pathExtension){case ".JSON":{ConfigBuilder = new JsonBuilder(ConfigPath);break;}case ".YML":{ConfigBuilder = new YamlBuilder(ConfigPath);break;}default:{throw new SmartCodeException($"ConfigPath:{ConfigPath},未知扩展名:{pathExtension}");}}Project = ConfigBuilder.Build();Project.ConfigPath = ConfigPath;}private void RegisterServices(){Services.AddSingleton<SmartCodeOptions>(SmartCodeOptions);Services.AddSingleton<Project>(Project);RegisterPlugins();Services.AddSingleton<IPluginManager, PluginManager>();Services.AddSingleton<IProjectBuilder, ProjectBuilder>();ServiceProvider = Services.BuildServiceProvider();Logger = ServiceProvider.GetRequiredService<ILogger<SmartCodeApp>>();}private void RegisterPlugins(){foreach (var plugin in SmartCodeOptions.Plugins){var pluginType = Assembly.Load(plugin.AssemblyName).GetType(plugin.TypeName);if (pluginType == null){throw new SmartCodeException($"Plugin.Type:{plugin.TypeName} can not find!");}var implType = Assembly.Load(plugin.ImplAssemblyName).GetType(plugin.ImplTypeName);if (implType == null){throw new SmartCodeException($"Plugin.ImplType:{plugin.ImplTypeName} can not find!");}if (!pluginType.IsAssignableFrom(implType)){throw new SmartCodeException($"Plugin.ImplType:{implType.FullName} can not Impl Plugin.Type:{pluginType.FullName}!");}Services.AddSingleton(pluginType, implType);}}public async Task Run(){try{Handlebars.Configuration.TextEncoder = NullTextEncoder.Instance;var projectBuilder = ServiceProvider.GetRequiredService<IProjectBuilder>();Logger.LogInformation($"------- Build ConfigPath:{ConfigPath} Start! --------");await projectBuilder.Build();Logger.LogInformation($"-------- Build ConfigPath:{ConfigPath},Output:{Project.Output?.Path} End! --------");}catch (SmartCodeException scEx){Logger.LogError(new EventId(scEx.HResult), scEx, scEx.Message);}}public class NullTextEncoder : ITextEncoder{public static NullTextEncoder Instance = new NullTextEncoder();public string Encode(string value){return value;}}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。