Launcher() { orgSysProxySetting = Lib.Sys.ProxySetter.GetProxySetting(); // warn-up var cache = Cache.Instance; var cmder = Cmder.Instance; setting = Setting.Instance; pacServer = PacServer.Instance; servers = Servers.Instance; notifier = Notifier.Instance; SetCulture(setting.culture); // dependency injection pacServer.Run(setting); servers.Run(setting, pacServer, cache); cmder.Run(setting, servers, pacServer); notifier.Run(setting, servers); Application.ApplicationExit += (s, a) => OnApplicationExitHandler(false); Microsoft.Win32.SystemEvents.SessionEnding += (s, a) => OnApplicationExitHandler(true); Application.ThreadException += (s, a) => SaveExceptionAndExit( a.Exception.ToString()); AppDomain.CurrentDomain.UnhandledException += (s, a) => SaveExceptionAndExit( (a.ExceptionObject as Exception).ToString()); }
public void Run( Setting setting, Servers servers, PacServer pacServer) { this.servers = servers; this.setting = setting; pacServer.RegistPostRequestHandler(RequestDispatcher); InitCmdHandler(); }
void LazyServerTrackUpdateWorker( Controller.CoreServerCtrl servCtrl, bool isStart) { var curTrackerSetting = GenCurTrackerSetting(servCtrl.config, isStart); var isGlobal = false; curTrackerSetting.curServer = null; var proxySetting = setting.GetSysProxySetting(); switch (PacServer.DetectSystemProxyMode(proxySetting)) { case Model.Data.Enum.SystemProxyMode.None: setting.SaveServerTrackerSetting(curTrackerSetting); return; case Model.Data.Enum.SystemProxyMode.Global: isGlobal = true; break; case Model.Data.Enum.SystemProxyMode.PAC: isGlobal = false; break; } foreach (var c in curTrackerSetting.serverList) { // 按trackerList的顺序来试 var serv = serverList.FirstOrDefault(s => s.config == c); if (serv == null) { continue; } if (serv.BecomeSystemProxy(isGlobal)) { curTrackerSetting.curServer = serv.config; break; } } // 没有可用服务器时不要清空代理设置 // 否则全部重启时会丢失代理设置 if (curTrackerSetting.curServer == null) { OnSendLogHandler(this, new Model.Data.StrEvent(I18N.NoServerCapableOfSysProxy)); if (serverList.Count(s => s.isServerOn && !s.isUntrack) > 0) { Task.Factory.StartNew(() => MessageBox.Show(I18N.SetSysProxyFail)); } } setting.SaveServerTrackerSetting(curTrackerSetting); }
public void Run( Setting setting, PacServer pacServer, Cache cache) { this.cache = cache; this.setting = setting; this.pacServer = pacServer; this.serverList = setting.LoadServerList(); foreach (var server in serverList) { server.Run(cache, setting, pacServer, this); BindEventsTo(server); } }