public void AutoSwitchProxy() { Logger.V(">> AppManager.AutoSwitchProxy"); if (m_detector.IsNetworkActive()) { Logger.I("AppManager.AutoSwitchProxy :: " + "Network is active and now trying to find an appropriate proxy item."); ProxyItem pi = FindMatchedProxyItem(); if (pi != null) { // Apply the found proxy since the rule matched Logger.I("AppManager.AutoSwitchProxy :: " + "The appropriate proxy item is found."); EnableProxy(pi); } else { // Disable proxy since no rule applied Logger.I("AppManager.AutoSwitchProxy :: " + "Failed to find an appropriate proxy item."); DisableProxy(); } } else { // Disable proxy if no active network Logger.I("AppManager.AutoSwitchProxy :: Network is inactive."); DisableProxy(); } Logger.V("<< AppManager.AutoSwitchProxy"); }
private void UserRequest_SelectProxyFromPool(object sender, EventArgs e) { Logger.V(">> FormMain.UserRequest_SelectProxyFromPool"); var mi = sender as MenuItem; int idx = mi.Index; foreach (MenuItem iter in m_arrayMenuItems[m_idxNiCtxProxySelection].MenuItems) { foreach (MenuItem i in iter.MenuItems) { i.Checked = false; } } foreach (MenuItem iter in m_arrayMenuItems[m_idxNiCtxProxySelection].MenuItems) { if ((idx < iter.MenuItems.Count) && (iter.MenuItems[idx].GetHashCode() == mi.GetHashCode())) { // menu item entry found ProxyItem pi = m_appManagerRef.AppProfile .m_listProxyGroups[iter.Index].m_listProxyItems[idx]; Logger.I("UserRequest :: Select proxy item from the pool (" + pi.m_szProxyAddr + ")."); m_appManagerRef.EnableProxy(m_appManagerRef.AppProfile .m_listProxyGroups[iter.Index].m_listProxyItems[idx]); mi.Checked = true; break; } } Logger.V("<< FormMain.UserRequest_SelectProxyFromPool"); }
private ProxyItem FindMatchedProxyItem() { Logger.V(">> AppManager.FindMatchedProxyItem"); ProxyItem ret = null; for (int i = 0; i < m_profile.m_listProxyGroups.Count; ++i) { ProxyGroup pg = m_profile.m_listProxyGroups[i]; if (!pg.m_isEnabled) { continue; } if (!IsRuleMatched(pg.m_applyRule)) { continue; } if (pg.m_iSelectedIndex <= 0 || pg.m_iSelectedIndex > pg.m_listProxyItems.Count) { // reset the invalid SelectedIndex value pg.m_iSelectedIndex = 0; } else if (pg.m_listProxyItems[pg.m_iSelectedIndex - 1].m_isEnabled) { // directly get the specified selected proxy item ret = pg.m_listProxyItems[pg.m_iSelectedIndex - 1]; m_idxProxyGroup = i; break; } // try to get the proxy item by default routine for (int j = 0; j < pg.m_listProxyItems.Count; ++j) { ProxyItem pi = pg.m_listProxyItems[j]; if (pi.m_isEnabled) { ret = pi; pg.m_iSelectedIndex = j + 1; m_idxProxyGroup = i; break; } } if (ret != null) { break; } else { pg.m_iSelectedIndex = 0; } } Logger.V("<< AppManager.FindMatchedProxyItem"); return(ret); }
private void UserRequest_SelectProxyFromCurrentGroup(object sender, EventArgs e) { Logger.V(">> FormMain.UserRequest_SelectProxyFromCurrentGroup"); var mi = sender as MenuItem; ProxyGroup pg = m_appManagerRef.AppProfile.m_listProxyGroups[ m_appManagerRef.AutoModeProxyGroupIndex]; pg.m_iSelectedIndex = mi.Index + 1; ProxyItem pi = pg.m_listProxyItems[pg.m_iSelectedIndex - 1]; Logger.I("UserRequest :: Select proxy item from the current group (" + pi.m_szProxyAddr + ")."); m_appManagerRef.EnableProxy(pi); Profile.Save(m_appManagerRef.AppProfile); Logger.V("<< FormMain.UserRequest_SelectProxyFromCurrentGroup"); }
public void EnableProxy(ProxyItem pi) { Logger.V(">> AppManager.EnableProxy(@1.ProxyAddr:" + pi.m_szProxyAddr + ")"); m_semaphore.WaitOne(); string args = true.ToString() + " " + "\"" + pi.m_szProxyAddr + "\" " + "\"" + pi.m_szBypass + "\" " + pi.m_isAutoConfDisabled.ToString(); RunProcessProxyAgent(args); if (IeProxyOptions.ProxyEnable != true || IeProxyOptions.ProxyAddr != pi.m_szProxyAddr || IeProxyOptions.Bypass != pi.m_szBypass || IeProxyOptions.AutoConfDisabled != pi.m_isAutoConfDisabled) { Logger.W("AppManager.EnableProxy :: " + "Failed to enable system proxy as specified for the 1st round."); RunProcessProxyAgent(args); if (IeProxyOptions.ProxyEnable != true || IeProxyOptions.ProxyAddr != pi.m_szProxyAddr || IeProxyOptions.Bypass != pi.m_szBypass || IeProxyOptions.AutoConfDisabled != pi.m_isAutoConfDisabled) { Logger.E("AppManager.EnableProxy :: " + "Failed to enable system proxy as specified for the 2nd round."); } else { Logger.I("AppManager.EnableProxy :: " + "Correctly enable system proxy as specified for the 2nd round."); } } else { Logger.I("AppManager.EnableProxy :: " + "Correctly enable system proxy as specified for the 1st round."); } NotifyGuiNetworkChanged(this, new EventArgs()); m_semaphore.Release(); Logger.V("<< AppManager.EnableProxy(@1.ProxyAddr:" + pi.m_szProxyAddr + ")"); }