Exemple #1
0
        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());
        }
Exemple #2
0
 public static void UpdateProxySettingOnDemand(Model.Data.ProxyRegKeyValue proxySetting)
 {
     if (!proxySetting.IsEqualTo(GetProxySetting()))
     {
         SetProxy(proxySetting);
     }
 }
Exemple #3
0
        public void ClearSysProxy()
        {
            var proxy = new Model.Data.ProxyRegKeyValue();

            setting.SaveSysProxySetting(proxy);
            Lib.Sys.ProxySetter.SetProxy(proxy);
            InvokeOnPACServerStatusChanged();
        }
Exemple #4
0
        public void SetPACProx(Model.Data.PacUrlParams param)
        {
            var proxy = new Model.Data.ProxyRegKeyValue();

            proxy.autoConfigUrl = GenPacUrl(param);
            Lib.Sys.ProxySetter.SetProxy(proxy);
            setting.SaveSysProxySetting(proxy);
            StartPacServer();
            InvokeOnPACServerStatusChanged();
        }
Exemple #5
0
        public void SetGlobalProxy(string ip, int port)
        {
            var proxy = new Model.Data.ProxyRegKeyValue();

            proxy.proxyEnable = true;
            proxy.proxyServer = string.Format("{0}:{1}", ip, port.ToString());
            Lib.Sys.ProxySetter.SetProxy(proxy);
            setting.SaveSysProxySetting(proxy);
            InvokeOnPACServerStatusChanged();
        }
Exemple #6
0
        public static void SetPacProxy(string pacUrl)
        {
            var url = pacUrl + "?&t=" + RandomHex(8);

            var proxySetting = new Model.Data.ProxyRegKeyValue
            {
                autoConfigUrl = url ?? "",
            };

            SetProxy(proxySetting);
        }
Exemple #7
0
        public static void SetProxy(Model.Data.ProxyRegKeyValue proxy)
        {
            using (var key = GetRegKey(true))
            {
                key.SetValue("AutoConfigURL", proxy.autoConfigUrl, RegistryValueKind.String);
                key.SetValue("ProxyServer", proxy.proxyServer, RegistryValueKind.String);
                key.SetValue("ProxyEnable", proxy.proxyEnable ? 1 : 0, RegistryValueKind.DWord);
            }

            RefreshSettings();
        }
Exemple #8
0
        public static Model.Data.ProxyRegKeyValue GetProxySetting()
        {
            var proxy = new Model.Data.ProxyRegKeyValue();

            using (var key = GetRegKey(false))
            {
                proxy.proxyServer   = key.GetValue("ProxyServer", "").ToString();
                proxy.proxyEnable   = key.GetValue("ProxyEnable", "0").ToString() == "1";
                proxy.autoConfigUrl = key.GetValue("AutoConfigURL", "").ToString();
            }
            return(proxy);
        }
Exemple #9
0
        public static Model.Data.Enum.SystemProxyMode DetectSystemProxyMode(Model.Data.ProxyRegKeyValue proxySetting)
        {
            if (!string.IsNullOrEmpty(proxySetting.autoConfigUrl))
            {
                return(Model.Data.Enum.SystemProxyMode.PAC);
            }

            if (proxySetting.proxyEnable)
            {
                return(Model.Data.Enum.SystemProxyMode.Global);
            }

            return(Model.Data.Enum.SystemProxyMode.None);
        }
Exemple #10
0
        public static bool IsProxyNotSet(Model.Data.ProxyRegKeyValue proxySetting)
        {
            if (!string.IsNullOrEmpty(proxySetting.autoConfigUrl))
            {
                return(false);
            }

            if (proxySetting.proxyEnable)
            {
                return(false);
            }

            return(true);
        }
Exemple #11
0
        public static void SetGlobalProxy(int port)
        {
            var proxyUrl = string.Format(
                "{0}:{1}",
                localhost,
                Clamp(port, 0, 65536));

            var proxySetting = new Model.Data.ProxyRegKeyValue
            {
                proxyEnable = true,
                proxyServer = proxyUrl,
            };

            UpdateProxySettingOnDemand(proxySetting);
        }
Exemple #12
0
        public Model.Data.ProxyRegKeyValue GetSysProxySetting()
        {
            var empty = new Model.Data.ProxyRegKeyValue();

            Model.Data.ProxyRegKeyValue proxy = null;
            try
            {
                proxy = JsonConvert.DeserializeObject <Model.Data.ProxyRegKeyValue>(
                    Properties.Settings.Default.SysProxySetting);
            }
            catch
            {
                return(empty);
            }
            return(proxy ?? empty);
        }
Exemple #13
0
        public void Run(Setting setting)
        {
            this.setting       = setting;
            orgSysProxySetting = Lib.Sys.ProxySetter.GetProxySetting();
            ClearCache();
            var pacSetting   = setting.GetPacServerSettings();
            var proxySetting = setting.GetSysProxySetting();

            if (pacSetting.isAutorun || !string.IsNullOrEmpty(proxySetting.autoConfigUrl))
            {
                RestartPacServer();
            }

            // becareful issue #9 #3
            if (!Lib.Utils.IsProxyNotSet(proxySetting))
            {
                Lib.Sys.ProxySetter.SetProxy(proxySetting);
            }
        }
Exemple #14
0
        public void Run(VgcApis.IService api)
        {
            orgSysProxySetting = Lib.Sys.ProxySetter.GetProxySetting();
            this.vgcApi        = api;

            var vgcSetting = api.GetVgcSettingService();
            var vgcServer  = api.GetVgcServersService();

            pacServer     = new PacServer();
            setting       = new PsSettings();
            serverTracker = new ServerTracker();

            // dependency injection
            setting.Run(vgcSetting);
            pacServer.Run(setting);
            serverTracker.Run(setting, pacServer, vgcServer);

            setting.DebugLog("call Luncher.run");
        }
Exemple #15
0
        public void Run(VgcApis.Models.IServices.IApiService api)
        {
            orgSysProxySetting = Lib.Sys.ProxySetter.GetProxySetting();
            VgcApis.Libs.Sys.FileLogger.Info("ProxySetter: save sys proxy settings");

            this.vgcApi = api;

            var vgcSetting = api.GetSettingService();
            var vgcServer  = api.GetServersService();

            pacServer     = new PacServer();
            setting       = new PsSettings();
            serverTracker = new ServerTracker();

            // dependency injection
            setting.Run(vgcSetting);
            pacServer.Run(setting);
            serverTracker.Run(setting, pacServer, vgcServer);

            setting.DebugLog("call Luncher.run");
        }
Exemple #16
0
 public void SaveSysProxySetting(Model.Data.ProxyRegKeyValue proxy)
 {
     Properties.Settings.Default.SysProxySetting =
         JsonConvert.SerializeObject(proxy);
     Properties.Settings.Default.Save();
 }
Exemple #17
0
 public void SaveSysProxySetting(Model.Data.ProxyRegKeyValue proxy)
 {
     userSettings.SysProxySetting =
         JsonConvert.SerializeObject(proxy);
     LazySaveUserSettings();
 }