1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using DevExpress.Pdf.Xmp;
- using DevExpress.Utils.Localization;
- using Ips.Library;
- using Ips.Library.Basic;
- using Ips.Library.DxpLib;
- using Ips.Library.Entity;
- using Serilog;
- using System.IO;
- using System.Reflection;
- using System.Runtime.Loader;
- using System.Text.Json.Serialization;
- namespace Ips.Service.GpuServer
- {
- internal static class Program
- {
- static Program()
- {
- //设置私有路径(NetCore移除了这种方式,因此使用Resolving事件)
- //AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "AddIns;");
- //var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
- //var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
- //m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", "AddIns;" });
- AssemblyLoadContext.Default.Resolving += Default_Resolving;
- Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
- //c++dll加入环境变量
- string paths = Environment.GetEnvironmentVariable("PATH");
- if (Directory.Exists("AddIns"))
- {
- var dirs = Directory.EnumerateDirectories("AddIns", "*", SearchOption.AllDirectories);
- List<string> list = new List<string>
- {
- Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AddIns")
- };
- foreach (var item in dirs)
- {
- list.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, item));
- }
- Environment.SetEnvironmentVariable("PATH", $"{paths};{string.Join(";", list)}");
- }
- AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
- {
- var args = e.ExceptionObject as Exception;
- IpsLogger.Error("出现未处理的异常,程序即将退出!", args);
- Thread.Sleep(5000);
- };
- Application.ThreadException += (sender, e) =>
- {
- if (e.Exception.GetType() != typeof(TaskCanceledException))
- IpsLogger.Error("出现未处理的线程异常!", e.Exception);
- };
- }
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- //必须要用一个委托包装一下,否则发布后运行不会显示UI,我也不知道为啥
- AppHelper.OneStart("GPU服务",() =>
- {
- ChsLocalizer.UseChs();
- ApplicationConfiguration.Initialize();
- Application.Run(new DirectXForm1());
- });
- }
- private static Assembly Default_Resolving(AssemblyLoadContext alc, AssemblyName assemblyName)
- {
- string pathMaybe = Path.Combine(AppContext.BaseDirectory, "AddIns", $"{assemblyName.Name}.dll");
- if (File.Exists(pathMaybe))
- return alc.LoadFromAssemblyPath(pathMaybe);
- return null;
- }
- }
- }
|