|  |  |  | using SunlightCentralizedControlManagement_SCCM_.UserClass; | 
					
						
							|  |  |  | using LiveChartsCore; | 
					
						
							|  |  |  | using LiveChartsCore.SkiaSharpView; | 
					
						
							|  |  |  | using SkiaSharp; | 
					
						
							|  |  |  | using System; | 
					
						
							|  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  | using System.Configuration; | 
					
						
							|  |  |  | using System.Data; | 
					
						
							|  |  |  | using System.Globalization; | 
					
						
							|  |  |  | using System.IO; | 
					
						
							|  |  |  | using System.Linq; | 
					
						
							|  |  |  | using System.Reflection; | 
					
						
							|  |  |  | using System.Runtime.InteropServices; | 
					
						
							|  |  |  | using System.Threading.Tasks; | 
					
						
							|  |  |  | using System.Windows; | 
					
						
							|  |  |  | using System.Windows.Markup; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace SunlightCentralizedControlManagement_SCCM_ | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /// <summary>
 | 
					
						
							|  |  |  |     /// App.xaml 的交互逻辑
 | 
					
						
							|  |  |  |     /// </summary>
 | 
					
						
							|  |  |  |     public partial class App : Application | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /// <summary>
 | 
					
						
							|  |  |  |      ///公共变量来自Login的用户名
 | 
					
						
							|  |  |  |      /// </summary>
 | 
					
						
							|  |  |  |         public static string USER_Purview { get; set; } | 
					
						
							|  |  |  |         private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Assembly executingAssembly = Assembly.GetExecutingAssembly(); | 
					
						
							|  |  |  |             var executingAssemblyName = executingAssembly.GetName(); | 
					
						
							|  |  |  |             var resName = executingAssemblyName.Name + ".resources"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             AssemblyName assemblyName = new AssemblyName(args.Name); string path = ""; | 
					
						
							|  |  |  |             if (resName == assemblyName.Name) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 path = executingAssemblyName.Name + ".g.resources"; ; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 path = assemblyName.Name + ".dll"; | 
					
						
							|  |  |  |                 if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             using (Stream stream = executingAssembly.GetManifestResourceStream(path)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (stream == null) | 
					
						
							|  |  |  |                     return null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 byte[] assemblyRawBytes = new byte[stream.Length]; | 
					
						
							|  |  |  |                 stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length); | 
					
						
							|  |  |  |                 return Assembly.Load(assemblyRawBytes); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         protected override void OnStartup(StartupEventArgs e) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             base.OnStartup(e); | 
					
						
							|  |  |  |             AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; | 
					
						
							|  |  |  |             this.DispatcherUnhandledException += App_DispatcherUnhandledException; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('温'))); | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('度'))); | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('水'))); | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('位'))); | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('主'))); | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('附'))); | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('料'))); | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('药'))); | 
					
						
							|  |  |  |             LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('缸'))); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         private UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public App() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             this.Startup += new StartupEventHandler(App_Startup); | 
					
						
							|  |  |  |             this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             SunlightCentralizedControlManagement_SCCM_.Properties.Resources.Culture = new System.Globalization.CultureInfo(Configini.IniReadvalue("SYS", "Language"));//设定语言
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         System.Threading.Mutex mutex; | 
					
						
							|  |  |  |         void App_Startup(object sender, StartupEventArgs e) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             bool ret; | 
					
						
							|  |  |  |             mutex = new System.Threading.Mutex(true, "SCCM", out ret);//程序只允许启动一次
 | 
					
						
							|  |  |  |             if (!ret) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 LogGing.LogGingDATA("800_The program has been launched"); | 
					
						
							|  |  |  |                 MessageBox.Show("The program has been launched"); | 
					
						
							|  |  |  |                 Environment.Exit(0); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           //  LogGing.LogGingDATA("800_Start");
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             SystemSleepTool.PreventSleep(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             //return Container.Resolve<MainWindow>();
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //   protected override void OnStartup(StartupEventArgs e)  //跟踪报错信息
 | 
					
						
							|  |  |  |         //     {
 | 
					
						
							|  |  |  |         //         base.OnStartup(e);
 | 
					
						
							|  |  |  |         //         //UI线程的异常捕捉
 | 
					
						
							|  |  |  |         //         this.DispatcherUnhandledException += App_DispatcherUnhandledException;
 | 
					
						
							|  |  |  |         //     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             e.Handled = true; | 
					
						
							|  |  |  |             if (e.Exception.InnerException == null) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!" | 
					
						
							|  |  |  |                     + "(1)错误" + Environment.NewLine | 
					
						
							|  |  |  |                     + "(2)错误源:" + e.Exception.Source + Environment.NewLine | 
					
						
							|  |  |  |                                 //  + (3)详细信息:" + e.Exception.Message + Environment.NewLine                             
 | 
					
						
							|  |  |  |                                 //  + "(4)报错区域:" + e.Exception.StackTrace
 | 
					
						
							|  |  |  |                                 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!" | 
					
						
							|  |  |  |                     + "(1)错误" + Environment.NewLine | 
					
						
							|  |  |  |                           + "(2)错误源:" + e.Exception.InnerException.Source + Environment.NewLine   | 
					
						
							|  |  |  |                     + "(3)错误信息:" + e.Exception.Message + Environment.NewLine | 
					
						
							|  |  |  |                       + "(4)详细信息:" + e.Exception.InnerException.Message + Environment.NewLine | 
					
						
							|  |  |  |                       + "(5)报错区域:" + e.Exception.InnerException.StackTrace | 
					
						
							|  |  |  |                                 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             string Log_time = DateTime.Now.ToString("yyyy-MM-dd"); | 
					
						
							|  |  |  |             string logpath = System.Environment.CurrentDirectory + "\\ERR";//日志文件目录
 | 
					
						
							|  |  |  |            // string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
 | 
					
						
							|  |  |  |            // System.IO.DirectoryInfo log = new System.IO.DirectoryInfo();//生成日志文件目录
 | 
					
						
							|  |  |  |             string log_path = logpath + "\\ERR" + Log_time + ".txt"; | 
					
						
							|  |  |  |             string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); | 
					
						
							|  |  |  |             if (Directory.Exists(logpath))//检查日志路径
 | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (!File.Exists(log_path))//检查文件并写入
 | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件 
 | 
					
						
							|  |  |  |                     StreamWriter wr = new StreamWriter(fs);//创建文件
 | 
					
						
							|  |  |  |                     wr.Close(); | 
					
						
							|  |  |  |                     FileStream fil = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件 
 | 
					
						
							|  |  |  |                     StreamWriter wfil = new StreamWriter(fil);//创建文件
 | 
					
						
							|  |  |  |                     wfil.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString()); | 
					
						
							|  |  |  |                     wfil.WriteLine("[" + Log_timehms + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString()); | 
					
						
							|  |  |  |                     wfil.WriteLine("[" + Log_timehms + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString()); | 
					
						
							|  |  |  |                     wfil.WriteLine("[" + Log_timehms + "];[Error area] ||" + e.Exception.StackTrace.ToString()); | 
					
						
							|  |  |  |                     wfil.Close(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件 
 | 
					
						
							|  |  |  |                     StreamWriter wr = new StreamWriter(fs);//创建文件
 | 
					
						
							|  |  |  |                     wr.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString()); | 
					
						
							|  |  |  |                     wr.WriteLine("[" + Log_timehms + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString()); | 
					
						
							|  |  |  |                     wr.WriteLine("[" + Log_timehms + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString()); | 
					
						
							|  |  |  |                     wr.WriteLine("[" + Log_timehms + "];[Error area] ||" + e.Exception.StackTrace.ToString()); | 
					
						
							|  |  |  |                     wr.Close(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 DirectoryInfo directoryInfo = new DirectoryInfo(logpath); | 
					
						
							|  |  |  |                 directoryInfo.Create(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         /// <summary>
 | 
					
						
							|  |  |  |         /// 启动初始页面
 | 
					
						
							|  |  |  |         /// </summary>   
 | 
					
						
							|  |  |  |         private void Application_Startup(object sender, StartupEventArgs e) | 
					
						
							|  |  |  |         {             | 
					
						
							|  |  |  |             Current.StartupUri = new Uri("Login.xaml", UriKind.Relative);  | 
					
						
							|  |  |  |            //Current.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);//和MainWindwo同一目录          
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public static class SystemSleepTool | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             //定义API函数
 | 
					
						
							|  |  |  |             [DllImport("kernel32.dll")] | 
					
						
							|  |  |  |             static extern uint SetThreadExecutionState(ExecutionFlag flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             [Flags] | 
					
						
							|  |  |  |             enum ExecutionFlag : uint | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 ES_SYSTEM_REQUIRED = 0x00000001, | 
					
						
							|  |  |  |                 ES_DISPLAY_REQUIRED = 0x00000002, | 
					
						
							|  |  |  |                 ES_CONTINUOUS = 0x80000000, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             /// <summary>
 | 
					
						
							|  |  |  |             ///阻止系统休眠
 | 
					
						
							|  |  |  |             /// </summary>
 | 
					
						
							|  |  |  |             public static void PreventSleep() | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 SetThreadExecutionState(ExecutionFlag.ES_SYSTEM_REQUIRED | ExecutionFlag.ES_DISPLAY_REQUIRED | ExecutionFlag.ES_CONTINUOUS); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             /// <summary>
 | 
					
						
							|  |  |  |             ///恢复系统休眠
 | 
					
						
							|  |  |  |             /// </summary>
 | 
					
						
							|  |  |  |             public static void RestoreSleep() | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 SetThreadExecutionState(ExecutionFlag.ES_CONTINUOUS); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |