using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; using Container.Common; using Container.Model; using Container.Services; using System.Diagnostics; using Container.ChildWindows; using Container.Viewmodel; using Container.Win; using Container.SaversViewModel; using System.Threading; namespace Container { /// /// App.xaml 的交互逻辑 /// public partial class App : Application { internal string shutdowntime; internal AppListModel NowNeedPlayApp;//当前时间段需要播放的app(时间轴或默认) internal string mallCode = ""; internal string mallRegKey = ""; internal string configurl = "http://192.168.0.250"; internal string configHttpUrl = ""; internal string SecurityKey = CommonLib.StringDecode("==wchF2UNFVO4cjN1QzMyEDM"); internal string configstartexe = ""; internal string configwebsocket = "ws://192.168.0.250:8080"; internal string configport = "8888"; internal string BuildingID = ""; internal string Floor = ""; internal string HttpUrl = "";// internal string LocalIP = "";//本机IP internal string DeviceType = "";//设备类型 internal string appUrl = "";//下载应用程序的路径 internal string appName = "";//应用下载文件名 //internal List NowAppList = new List(); internal bool appClick = false;//应用下载文件名 internal string NowAppType = "";//当前应用类型,exe、html。。 internal string deviceid = "";//设备编号 internal string devicemark = "";//设备备注 internal List Buildinginfo = new List();//楼栋列表 internal List DeviceTypeList = new List();//设备类型字典 internal List AppList = new List(); internal List AppTimeList = new List(); internal List Floors = new List();//楼层列表 //internal string Programname = "";//默认启动的程序名 internal string AppPlayDir = "";//需要播放的应用所在的文件夹名 internal string AppPlayName = "";//需要播放的应用启动文件名 internal string CurAppPlayName = "";//当前应用名称 internal string AppPlayNameCH = "";//中文名称 internal string Appversion = "";//应用版本号 internal string Containerversion = "";//容器版本号 //internal bool AppUpdate = false;//是否已更新 //internal string AppDownCode = "";//应用下线 //internal ExeModel Appdowninfo = new ExeModel();//应用下载对象 //internal ExeModel AppStartinfo = new ExeModel();//应用启动对象 internal AppListModel AppPlayinfo = new AppListModel();//当前应用对象 //internal List exeinfo = new List();//应用列表 //internal string icourl = "";//应用图标路径 //internal InsertADModel insertAD=new InsertADModel(); internal string bgPath = ""; internal BGPage pageBg; //internal string defaultFile = ""; internal Screensaver screensaver = new Screensaver() { EffectType = 1, ScreenEffect = 1, ScreenFile = "", ScreenType = 0 ,ScreenTime=30}; //internal int screenTime = 30; internal RabbitMQModel rabbitMQ = new RabbitMQModel(); internal bool isStartScreen = false; Class_Log log = new Class_Log(); internal List TopSubTitle = new List { }; internal List BottomSubTitle = new List { }; internal int TopSubTitleIndex = 0; internal int BottomSubTitleIndex = 0; //internal string kioskUrl = ""; internal static bool Downloaddone = false; internal int currentIndex = 0; //internal WindowView view; //internal Screensaver screensaver = new Screensaver() { EffectType = 1, ScreenEffect = 1, ScreenFile = "", ScreenType = 0 }; internal NavViewModel navModel = new NavViewModel(); System.Threading.Mutex mutex; internal bool isProgramServer = false; internal bool isProgramSync = false; internal bool isSendSync = false; internal string websocketProgramIP = string.Empty; internal WebsocketForProgramServer websocketForProgramServer = null; internal WebSocketForProgram webSocketForProgram = null; internal string kioskUrl = ""; internal bool IsCanConnect = true; internal Live live = new Live(); internal CurrentLive curLive = new CurrentLive(); internal bool LiveReload = false; internal bool isLoadLive = false; internal DateTime? CloseServerTime = null; internal List playProgList = new List(); internal List shutDownProgList = new List(); internal string BGFile = string.Empty; internal string defaultCity = string.Empty; internal bool isCheckServerTime = false; internal string kioskVersion = ""; internal string screenshotUserName = ""; //internal bool isStartHeat = false; internal bool IsDownScreen = false; internal string screenConfig = string.Empty; internal int downErrorTime = 0; internal string FileServerPath = string.Empty; internal string OBSPath = string.Empty; internal double ScreenWidth = 0; internal double ScreenHeight = 0; internal bool isStartGetProg = false; string info = ""; public MainWindow main; private void Application_Startup(object sender, StartupEventArgs e) { Class_Log clog = new Class_Log(); bool ret; mutex = new System.Threading.Mutex(true, "WpfMuerterrrterterttex11", out ret); if (!ret) { // MessageBox.Show("程序已启动"); Environment.Exit(0); } try { this.configHttpUrl = ConfigurationManager.AppSettings["HttpUrl"]; if (!string.IsNullOrEmpty(this.configHttpUrl)) { this.HttpUrl = this.configHttpUrl; this.configurl = this.configHttpUrl; } bool update = true; clog.WriteLogFile("收到:" + e.Args.Count(), "Loadargs"); if (e.Args.Count() > 0) { clog.WriteLogFile("收到:" + e.Args[0].ToString(), "Loadargs"); string[] inf = e.Args[0].ToString().Split('&'); clog.WriteLogFile("inf.Count():" + inf.Count().ToString(), "Loadargs"); if (inf.Count() > 1) update = false; } if (update) { //System.Security.Principal.WindowsIdentity identity1 = System.Security.Principal.WindowsIdentity.GetCurrent(); ////创建Windows用户主题 //System.Windows.Forms.Application.EnableVisualStyles(); //System.Security.Principal.WindowsPrincipal principal1 = new System.Security.Principal.WindowsPrincipal(identity1); ////判断当前登录用户是否为管理员 //if (!principal1.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) //{ // //创建启动对象 // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); // //设置运行文件 // startInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录 // startInfo.FileName = startInfo.WorkingDirectory + "/ConUpdate.exe"; //设置启动参数 // startInfo.Arguments = info; // //设置启动动作,确保以管理员身份运行 // startInfo.Verb = "runas"; // //如果不是管理员,则启动UAC // //log.WriteLogFile("工作路径:" + startInfo.WorkingDirectory, "APPError"); // System.Diagnostics.Process.Start(startInfo); // //退出 // System.Windows.Forms.Application.Exit(); // //System.Diagnostics.Process p = new System.Diagnostics.Process(); // //p.StartInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录 // //p.StartInfo.FileName = p.StartInfo.WorkingDirectory + "/PCScreenSavers.exe"; // //p.StartInfo.Arguments = app.info; // //p.StartInfo.Verb = "runas"; // //p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 // //p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息 // //p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息 // //p.StartInfo.RedirectStandardError = true;//重定向标准错误输出 // ////p.ProcessNa = "PCScreenUpdate"; // //p.StartInfo.CreateNoWindow = false;//不显示程序窗口 // //p.Start();//启动程序 //} //else //{ // System.Diagnostics.Process p = new System.Diagnostics.Process(); // p.StartInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录 // p.StartInfo.FileName = p.StartInfo.WorkingDirectory + "/ConUpdate.exe"; // p.StartInfo.Arguments = info; // p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 // p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息 // p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息 // p.StartInfo.RedirectStandardError = true;//重定向标准错误输出 // p.StartInfo.CreateNoWindow = false;//不显示程序窗口 // p.Start();//启动程序 //} StartConUpdate(info); Environment.Exit(0); } } catch (Exception ex) { clog.WriteLogFile(ex.ToString()); } try { System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); //创建Windows用户主题 System.Windows.Forms.Application.EnableVisualStyles(); Class_Log log = new Class_Log(); System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); //判断当前登录用户是否为管理员 if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) { //创建启动对象 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); //设置运行文件 startInfo.FileName = System.Windows.Forms.Application.ExecutablePath; startInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录 //设置启动参数 startInfo.Arguments = String.Join(" ", e); //设置启动动作,确保以管理员身份运行 startInfo.Verb = "runas"; //如果不是管理员,则启动UAC System.Diagnostics.Process.Start(startInfo); //退出 System.Windows.Forms.Application.Exit(); } else { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.Current.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException); MainWindow win = new MainWindow(); main = win; win.Show(); } } catch (Exception ex) { clog.WriteLogFile(ex.ToString()); // MessageBox.Show("程序启动失败"); } } private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { log.WriteLogFile(e.Exception.Message + e.Exception.StackTrace, "APPError"); log.WriteLogFile("---111--" + e.ToString(), "APPError"); StartConUpdate(info); Environment.Exit(0); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Exception ex = (Exception)e.ExceptionObject; log.WriteLogFile(ex.Message + ex.StackTrace, "APPError"); log.WriteLogFile("-----"+ex.ToString(), "APPError"); StartConUpdate(info); Environment.Exit(0); } void App_Startup(object sender, StartupEventArgs e) { } private void StartConUpdate(string info) { System.Security.Principal.WindowsIdentity identity1 = System.Security.Principal.WindowsIdentity.GetCurrent(); //创建Windows用户主题 System.Windows.Forms.Application.EnableVisualStyles(); System.Security.Principal.WindowsPrincipal principal1 = new System.Security.Principal.WindowsPrincipal(identity1); //判断当前登录用户是否为管理员 if (!principal1.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) { //创建启动对象 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); //设置运行文件 startInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录 startInfo.FileName = startInfo.WorkingDirectory + "/ConUpdate.exe"; //设置启动参数 startInfo.Arguments = info; //设置启动动作,确保以管理员身份运行 startInfo.Verb = "runas"; //如果不是管理员,则启动UAC //log.WriteLogFile("工作路径:" + startInfo.WorkingDirectory, "APPError"); System.Diagnostics.Process.Start(startInfo); //退出 System.Windows.Forms.Application.Exit(); //System.Diagnostics.Process p = new System.Diagnostics.Process(); //p.StartInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录 //p.StartInfo.FileName = p.StartInfo.WorkingDirectory + "/PCScreenSavers.exe"; //p.StartInfo.Arguments = app.info; //p.StartInfo.Verb = "runas"; //p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 //p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息 //p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息 //p.StartInfo.RedirectStandardError = true;//重定向标准错误输出 ////p.ProcessNa = "PCScreenUpdate"; //p.StartInfo.CreateNoWindow = false;//不显示程序窗口 //p.Start();//启动程序 } else { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录 p.StartInfo.FileName = p.StartInfo.WorkingDirectory + "/ConUpdate.exe"; p.StartInfo.Arguments = info; p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息 p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息 p.StartInfo.RedirectStandardError = true;//重定向标准错误输出 p.StartInfo.CreateNoWindow = false;//不显示程序窗口 p.Start();//启动程序 } } } }