69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Net;
|
|
|
|
namespace YLErp
|
|
{
|
|
class Program
|
|
{
|
|
static IServiceProvider ServiceProvider;
|
|
|
|
[STAThread]
|
|
public static void Main()
|
|
{
|
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
|
|
|
Application.ThreadException += (sender, e) =>
|
|
{
|
|
LogFactory.GetLogger("Application.ThreadException").Error(e.Exception, "发生未处理的错误");
|
|
|
|
MessageBox.Show(e.Exception.ToString());
|
|
};
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (sender, ex) =>
|
|
{
|
|
LogFactory.GetLogger("AppDomain.UnhandledException").Error("发生未处理的错误:" + ex.ExceptionObject);
|
|
};
|
|
|
|
IConfiguration configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
|
|
|
|
var services = new ServiceCollection();
|
|
|
|
services.AddHttpClient("")
|
|
.ConfigurePrimaryHttpMessageHandler(messageHandler =>
|
|
{
|
|
var handler = new HttpClientHandler();
|
|
if (handler.SupportsAutomaticDecompression)
|
|
{
|
|
handler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
|
|
}
|
|
return handler;
|
|
});
|
|
services.AddSingleton(configuration);
|
|
ServiceProvider = services.BuildServiceProvider();
|
|
|
|
AppManager.Initialize(Enums.SubSystemName.UnitTest, configuration);
|
|
|
|
OtcAppContext.Initialize(path =>
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(path))
|
|
{
|
|
Console.WriteLine("请求MapPath:" + path);
|
|
path = Path.Combine(AppContext.BaseDirectory, path.TrimStart().TrimStart('/').Replace("/", "\\"));
|
|
Console.WriteLine("MapPath结果:" + path);
|
|
}
|
|
return path;
|
|
});
|
|
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Application.Run(new Forms.Form1());
|
|
}
|
|
|
|
public static T GetService<T>()
|
|
{
|
|
return ServiceProvider.GetService<T>();
|
|
}
|
|
}
|
|
}
|