private void Window_Loaded(object sender, RoutedEventArgs e) { if (bool.Parse(PBS.APP.Classes.AppUtility.ReadConfig("InstantCache", "False"))) { (DataContext as VMMainView).initInstantCache(); } var runningMode = AppUtility.ReadConfig("RunningMode", "OFFLINE"); this.Title += runningMode == "OFFLINE" ? "[离线]" : "[在线]"; }
private void Application_Startup(object sender, StartupEventArgs e) { //log4net init. log4net will take care of the creation of log directory if necessary. try { Utility.InitLog4net(); new BaiDuMapManager(); if (!Directory.Exists("cache")) { Directory.CreateDirectory("cache"); } BaiDuMapManager.inst.maxThreadCount = int.Parse(AppUtility.ReadConfig("MaxDownloadThread", "100")); BaiDuMapManager.inst.roundInterval = long.Parse(AppUtility.ReadConfig("RoundInterval", "300000")); BaiDuMapManager.inst.refreshInterval = long.Parse(AppUtility.ReadConfig("VersionRefreshInterval", "7200000")); BaiDuMapManager.inst.RunMode = AppUtility.ReadConfig("RunningMode", "OFFLINE"); BaiDuMapManager.inst.bundleSize = int.Parse(AppUtility.ReadConfig("BundleSize", "16")); BaiDuMapManager.inst.streetudt = AppUtility.ReadConfig("StreetUDT", "20160330"); if (!Directory.Exists("site/" + "Pics/" + BaiDuMapManager.inst.streetudt)) { Directory.CreateDirectory("site/" + "Pics/" + BaiDuMapManager.inst.streetudt); } } catch (Exception ex) { MessageBox.Show(Application.Current.FindResource("ReadLog4netConfigError").ToString() + "\r\n" + ex.Message); Application.Current.Shutdown(1); return; } //avoid multiple start of PBS if (!bool.Parse(AppUtility.ReadConfig("AllowMultiInst", "False"))) { string processName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;//"PortableBasemapServer"; int processCount = 0; foreach (Process p in Process.GetProcesses()) { if (p.ProcessName == processName) { processCount++; } } if (processCount > 1) { Application.Current.Shutdown(); if (e.Args.Length == 1 && e.Args[0] == "/runasservice")//try to start windows service after exe started { //when come to here, it's another process to write to the same log file. //ref:Can Log4net have multiple appenders write to the same file? //http://stackoverflow.com/questions/3010407/can-log4net-have-multiple-appenders-write-to-the-same-file Utility.Log(LogLevel.Error, null, Application.Current.FindResource("WindowsServiceStartError").ToString() + Application.Current.FindResource("ProcessStarted").ToString()); } else if (PBS.Util.Utility.IsWindowsServiceStarted(processName))//try to start exe after windows service started { MessageBox.Show(Application.Current.FindResource("WindowsServiceStarted").ToString()); } else//try to start another exe after exe started { MessageBox.Show(Application.Current.FindResource("ProcessStarted").ToString()); //throw new Exception(Application.Current.FindResource("ProcessStarted").ToString()); } return; } } if (e.Args.Length == 1) { switch (e.Args[0]) { case "/runasservice": ServiceBase[] servicesToRun = new ServiceBase[] { new PBSWindowsService() }; ServiceBase.Run(servicesToRun); break; //case "/getServices": // Console.WriteLine("Runing Services Count:"); // break; default: break; } } else { MainWindow mw = new MainWindow(new VMMainView()); } }