步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.4 KiB

2 years ago
using BBWY.Common.Http;
using BBWY.Common.Models;
using BBWY.Common.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using PJZS.Models;
2 years ago
namespace PJZS
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
2 years ago
public IServiceProvider ServiceProvider { get; private set; }
public IConfiguration Configuration { get; private set; }
2 years ago
protected override void OnStartup(StartupEventArgs e)
{
var gl = new GlobalContext();
string userToken = string.Empty;
#if DEBUG
//齐越山鸡
userToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNTM1MzMwMzI4ODkyMTQ5NzYwIiwidGVhbUlkIjoiMTUxNjk3NDI1MDU0MjUwMTg4OCIsInNvblRlYW1JZHMiOiIxNDM2Mjg4NTAwMjM1MjQzNTIwIiwiZXhwIjoxNjk0NjY5NjkxfQ.cSwro-7bGwOu92YejH9JhMenTai7Mvf99i2paQCmxIw";
#else
var uid = e.Args.Count() > 0 ? e.Args.LastOrDefault(args => args.StartsWith("uid:")) : string.Empty;
if (string.IsNullOrEmpty(uid))
{
MessageBox.Show("缺少启动参数", "提示");
Environment.Exit(0);
}
var tokenResult = ReadMMF(uid);
if (tokenResult.isOk)
userToken = tokenResult.content;
else
{
MessageBox.Show($"读取内存数据失败\r\n{tokenResult.content}", "提示");
Environment.Exit(0);
}
#endif
gl.UserToken = userToken;
2 years ago
#region 注册全局异常
this.DispatcherUnhandledException += App_DispatcherUnhandledException; ;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
#endregion
var applicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var builder = new ConfigurationBuilder().SetBasePath(applicationPath).AddJsonFile("appSettings.json", false, true);
Configuration = builder.Build();
gl.BBYWApiHost = Configuration.GetSection("BBWYApiHost").Value;
gl.MDSApiHost = Configuration.GetSection("MDSApiHost").Value;
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddHttpClient();
serviceCollection.AddSingleton<RestApiService>();
serviceCollection.AddSingleton(gl);
serviceCollection.BatchRegisterServices(new Assembly[] { Assembly.Load("PJZS") }, typeof(IDenpendency));
serviceCollection.AddMapper(new MappingProfile());
ServiceProvider = serviceCollection.BuildServiceProvider();
2 years ago
base.OnStartup(e);
}
2 years ago
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
throw new NotImplementedException();
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}
2 years ago
}
}