using _29WxOrderWpf.BaseWindows; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media.Imaging; using Work; using Work.BaseForms; namespace _29WxOrderWpf { /// /// App.xaml 的交互逻辑 /// public partial class App : Application { public static string[] args = new List().ToArray(); protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); if (e.Args.Length > 0) { args = e.Args; } try { //设置应用程序处理异常方式:ThreadException处理 //Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 //Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //StartUp.Init(); new Initialization().Get(); #region 贴牌 //本地缓存文件 string IgPakFile = "locales/ig.pak";//贴牌客服端码 string OenVersionFile = "locales/igv.pak";//贴牌资源配置版本 string IaPakFile = "locales/ia.pak";//logo string IbPakFile = "locales/ib.pak";//ico string IcPakFile = "locales/ic.pak";//功能配置 //OenMechanism(IgPakFile, OenVersionFile, IaPakFile, IbPakFile, IcPakFile); #region 后台修改logo 贴牌用 //// 替换字典程序logo等 //Uri imageUri = new Uri("pack://application:,,,/Resources/WindowBoxes/close.hover.png"); // 新的图片路径 //BitmapImage newBitmapImage = new BitmapImage(imageUri); //// 获取资源字典 //ResourceDictionary dict = Application.Current.Resources; //// 添加或更新资源 //dict["main29WeixinIcon"] = newBitmapImage; #endregion #endregion } catch (Exception ex) { string str = GetExceptionMsg(ex, string.Empty); NaiBa.Util.Helper.LogHelper.WriteWithTime("SystemError:" + str); //BaseMsgForm.ShowError(str, "系统错误"); BaseMsgWindow.ShowError(null, str, "系统错误"); } } //static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) //{ // string str = GetExceptionMsg(e.Exception, e.ToString()); // NaiBa.Util.Helper.LogHelper.WriteWithTime("SystemError:" + str); // BaseMsgWindow.ShowError(null, str, "系统错误"); //} private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { string str = GetExceptionMsg(e.Exception, e.ToString()); NaiBa.Util.Helper.LogHelper.WriteWithTime("SystemError:" + str); BaseMsgWindow.ShowError(null, str, "系统错误"); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString()); NaiBa.Util.Helper.LogHelper.WriteWithTime("SystemError:" + str); BaseMsgWindow.ShowError(null, str, "系统错误"); } /// /// 生成自定义异常消息 /// /// 异常对象 /// 备用异常消息:当ex为null时有效 /// 异常字符串文本 static string GetExceptionMsg(Exception ex, string backStr) { StringBuilder sb = new StringBuilder(); sb.AppendLine("****************************异常文本****************************"); sb.AppendLine("【出现时间】:" + DateTime.Now.ToString()); if (ex != null) { sb.AppendLine("【异常类型】:" + ex.GetType().Name); sb.AppendLine("【异常信息】:" + ex.Message); sb.AppendLine("【堆栈调用】:" + ex.StackTrace); } else { sb.AppendLine("【未处理异常】:" + backStr); } sb.AppendLine("***************************************************************"); NaiBa.Util.Helper.LogHelper.WriteWithTime("Error:" + sb); BaseMsgWindow.ShowError(null, sb.ToString(), "系统错误"); return sb.ToString(); } /// /// Oen贴牌机制 /// /// 贴牌商客户端码文件 /// 贴牌配置版本号文件 /// ico本地缓存文件 /// logo本地缓存文件 /// 贴牌配置本地缓存文件 private static void OenMechanism(string IgPakFile, string OenVersionFile, string IaPakFile, string IbPakFile, string IcPakFile) { //todo: 贴牌相关处理逻辑 } } }