服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-10-24 38bde3e8210c41e9d0d219daba0c075cd676efce
Tiger.Api/Controllers/Test/TestController.R.cs
@@ -23,6 +23,8 @@
using Swifter.Tools;
using Tiger.Model.Entitys.MES.Position;
using Microsoft.CodeAnalysis.Options;
using System.IO;
using System.Runtime.Loader;
namespace Tiger.Api.Controllers.Test
{
@@ -306,7 +308,7 @@
    public partial class _TestController : ControllerBase
    {
        [HttpGet]
        public async Task<IActionResult> DoSomething(int duration)
        public async Task<IActionResult> DoSomething(int duration, string code)
        {
            Barcode b = new("asdasd");
            var begin = DateTime.Now;
@@ -333,6 +335,50 @@
            return Ok(result?.ToJson());
        }
        [HttpGet]
        public async Task<IActionResult> RefreashPlugin(string path)
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES");
            // 查找指定名称的程序集
            //var assembly = Array.Find(assemblies, a => a.GetName().Name == "Tiger.Business.MES");
            //var ass = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "\\Tiger.Business.MES1.dll");
            var mes1 = new AssemblyLoadContext("mes1", true);
            var assembly1 = mes1.LoadFromAssemblyPath(AppDomain.CurrentDomain.BaseDirectory + "\\Tiger.Business1.MES.dll");
            mes1.Unloading += context => { Console.WriteLine($"当前卸载{context.Name}程序集:" + string.Join(',', context.Assemblies.Select(x => x.FullName))); };
            assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES");
            var mes2 = new AssemblyLoadContext("mes2", true);
            var assembly2 = mes2.LoadFromAssemblyPath(AppDomain.CurrentDomain.BaseDirectory + "\\Tiger.Business2.MES.dll");
            mes2.Unloading += context => { Console.WriteLine($"当前卸载{context.Name}程序集:" + string.Join(',', context.Assemblies.Select(x => x.FullName))); };
            assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES");
            mes1.Unload();
            assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES");
            mes2.Unload();
            assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES");
            //var newBuilder = new ContainerBuilder();
            ////AutoFac 配置文件注入
            //AutoFacContainer.Init(newBuilder);
            //newBuilder.RegisterBuildCallback(scope =>
            //{
            //    AutoFacContainer.Instance = (IContainer)scope;
            //});
            //var newContainer = newBuilder.Build();
            //var trans = AutoFacContainer.Instance.Resolve<ITestNode>().Init("action.ID", "Request.Host.Value", "action.Data?.USER_CODE", "OQC001");
            //var d = trans.GetDefects();
            return Ok($"");
        }
    }
    /// <summary>