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.

120 lines
4.7 KiB

2 years ago
using BBWYB.Client.Helpers;
using BBWYB.Client.Models;
2 years ago
using BBWYB.Client.ViewModels;
2 years ago
using BBWYB.Common.Extensions;
using BBWYB.Common.Http;
using BBWYB.Common.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using System.Net.Http;
using System.Reflection;
2 years ago
using System.Threading.Tasks;
using System.Windows;
2 years ago
using System.Windows.Threading;
2 years ago
namespace BBWYB.Client
{
/// <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; }
protected override void OnStartup(StartupEventArgs e)
{
var gl = new GlobalContext();
string userToken = string.Empty;
#if DEBUG
//齐越山鸡
2 years ago
userToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNTM1MzMwMzI4ODkyMTQ5NzYwIiwidGVhbUlkIjoiMTUxNjk3NDI1MDU0MjUwMTg4OCIsInNvblRlYW1JZHMiOiIxNDM2Mjg4NTAwMjM1MjQzNTIwIiwiZXhwIjoxNjk0NjY5NjkxfQ.cSwro-7bGwOu92YejH9JhMenTai7Mvf99i2paQCmxIw";
2 years ago
2 years ago
//拳探店铺 陈默
//userToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNjI0OTUxNjgzNTc2NTAwMjI0IiwidGVhbUlkIjoiMTYyMDM0MjAxNDcwNjk3ODgxNiIsInNvblRlYW1JZHMiOiIxNjIwMzQyMDE0NzA2OTc4ODE2LDE2MjAzNDM4Mjc0NzI1ODQ3MDQsMTYyMDM0NDAzMzczNTg3MjUxMiwxNjIwMzQ0MDkyODI5NDIxNTY4LDE2MjAzNDQxNDA4NTAwMDgwNjQiLCJleHAiOjE3MjA3NjQzMjV9.Q8fiKXCHgvzbm7NDEre-MeoSju_AmC6Ae6eDY22rUAw";
2 years ago
#else
var tokenResult = ReadMMF();
if (tokenResult.isOk)
userToken = tokenResult.content;
else
{
MessageBox.Show($"读取内存数据失败\r\n{tokenResult.content}", "提示");
Environment.Exit(0);
}
#endif
gl.UserToken = userToken;
#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();
2 years ago
gl.BBWYApiHost = Configuration.GetSection("BBWYApiHost").Value;
2 years ago
gl.BBWYCApiHost = Configuration.GetSection("BBWYCApiHost").Value;
2 years ago
gl.MDSApiHost = Configuration.GetSection("MDSApiHost").Value;
2 years ago
gl.QKApiHost = Configuration.GetSection("QKApiHost").Value;
2 years ago
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddHttpClient();
serviceCollection.AddHttpClient("gzip").ConfigurePrimaryHttpMessageHandler(handler => new HttpClientHandler()
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip
});
serviceCollection.AddMemoryCache();
serviceCollection.AddSingleton<RestApiService>();
serviceCollection.AddSingleton(gl);
serviceCollection.BatchRegisterServices(new Assembly[] { Assembly.Load("BBWYB.Client") }, typeof(IDenpendency));
2 years ago
serviceCollection.AddTransient<ChoosePurchaseSchemeViewModel>();
serviceCollection.AddTransient<OnlinePurchaseViewModel>();
2 years ago
serviceCollection.AddTransient<EditPriceViewModel>();
2 years ago
serviceCollection.AddTransient<UpdatePurchaseTaskViewModel>();
2 years ago
serviceCollection.AddMapper(new MappingProfile());
ServiceProvider = serviceCollection.BuildServiceProvider();
base.OnStartup(e);
}
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{
2 years ago
2 years ago
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
2 years ago
2 years ago
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
2 years ago
2 years ago
}
public (bool isOk, string content) ReadMMF()
{
try
{
var token = MemoryHelper.GetMemoryToken();
if (string.IsNullOrEmpty(token))
return (false, "token为空");
else
return (true, token);
}
catch (Exception ex)
{
return (false, ex.Message);
}
}
2 years ago
}
}