public void StartCurrentWorkMode() { Logger.V(">> AppManager.StartCurrentWorkMode"); switch (m_currWorkMode) { case WorkMode.Auto: Logger.I("AppManager.StartCurrentWorkMode :: " + "Apply Auto Mode by the following routines."); AutoSwitchProxy(); break; case WorkMode.Direct: Logger.I("AppManager.StartCurrentWorkMode :: " + "Apply Direct Mode by disabling system proxy option."); DisableProxy(); break; case WorkMode.Proxy: Logger.I("AppManager.StartCurrentWorkMode :: " + "Apply Proxy Mode by enabling system proxy option."); EnableProxy(); break; } Logger.V("<< AppManager.StartCurrentWorkMode"); }
public void DetectorNotify_NetworkChanged(object sender, EventArgs e) { Logger.V(">> AppManager.DetectorNotify_NetworkChanged"); switch (m_currWorkMode) { case WorkMode.Auto: Logger.I("AppManager.DetectorNotify_NetworkChanged :: " + "Apply Auto Mode by the following routines."); AutoSwitchProxy(); break; case WorkMode.Direct: Logger.I("AppManager.DetectorNotify_NetworkChanged :: " + "Apply Direct Mode by disabling system proxy option."); DisableProxy(); break; case WorkMode.Proxy: Logger.I("AppManager.DetectorNotify_NetworkChanged :: " + "Apply Proxy Mode by enabling system proxy option."); EnableProxy(); break; } Logger.V("<< AppManager.DetectorNotify_NetworkChanged"); }
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"); }
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_ExitApplication(object sender, EventArgs e) { Logger.V(">> FormMain.UserRequest_ExitApplication"); Logger.I("UserRequest :: Exit Proxy Manager."); Application.Exit(); Logger.V("<< FormMain.UserRequest_ExitApplication"); }
public void DisableProxy() { Logger.V(">> AppManager.DisableProxy"); m_semaphore.WaitOne(); RunProcessProxyAgent(false.ToString()); if (IeProxyOptions.ProxyEnable != false) { Logger.W("AppManager.DisableProxy :: " + "Failed to disable system proxy for the 1st round."); RunProcessProxyAgent(false.ToString()); if (IeProxyOptions.ProxyEnable != false) { Logger.E("AppManager.DisableProxy :: " + "Failed to disable system proxy for the 2nd round."); } else { Logger.I("AppManager.DisableProxy :: " + "Correctly disable system proxy for the 2nd round."); } } else { Logger.I("AppManager.DisableProxy :: " + "Correctly disable system proxy for the 1st round."); } NotifyGuiNetworkChanged(this, new EventArgs()); m_semaphore.Release(); Logger.V("<< AppManager.DisableProxy"); }
private void UserRequest_ShowDlgOptions(object sender, EventArgs e) { Logger.V(">> FormMain.UserRequest_ShowDlgOptions"); if (!DlgOptions.Instance.Visible) { DlgOptions.Instance.StartPosition = (this.WindowState == FormWindowState.Minimized) ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent; Logger.I("UserRequest :: Show Options dialog."); DialogResult dr = DlgOptions.Instance.ShowDialog( this, m_appManagerRef.AppProfile); if ((dr == DialogResult.OK) && (!m_appManagerRef.AppProfile.Equals(DlgOptions.DlgProfile))) { Logger.I("UserRequest :: Options dialog triggers following routines."); m_appManagerRef.AppProfile = new Profile(DlgOptions.DlgProfile); Profile.Save(m_appManagerRef.AppProfile); m_appManagerRef.ApplyProfileUpdate(); } else { Logger.I("UserRequest :: Options dialog is cancelled."); } } else { DlgOptions.Instance.Activate(); } Logger.V("<< FormMain.UserRequest_ShowDlgOptions"); }
private void UserRequest_SwitchToProxyMode(object sender, EventArgs e) { Logger.V(">> FormMain.UserRequest_SwitchToProxyMode"); Logger.I("UserRequest :: Switch to Proxy Mode."); m_appManagerRef.SetCurrentWorkMode(WorkMode.Proxy); m_appManagerRef.StartCurrentWorkMode(); Logger.V("<< FormMain.UserRequest_SwitchToProxyMode"); }
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 AppMgrNotify_NetworkChanged(object sender, EventArgs e) { Logger.V(">> FormMain.AppMgrNotify_NetworkChanged"); Logger.I("FormMain.AppMgrNotify_NetworkChanged :: " + "Front End is updating GUI as requested by AppManager."); UpdateGui_FormMainLayout(); UpdateGui_NotifyIconTextIndication(); UpdateGui_NotifyIconMenuNetwork(); UpdateGui_NotifyIconMenuWorkMode(); UpdateGui_NotifyIconMenuProxySelection(); if (WindowState == FormWindowState.Minimized) { UpdateGui_NotifyIconBalloonTip(); } Logger.V("<< FormMain.AppMgrNotify_NetworkChanged"); }
private void UserRequest_ShowDlgAbout(object sender, EventArgs e) { Logger.V(">> FormMain.UserRequest_ShowDlgAbout"); if (!DlgAboutBox.Instance.Visible) { DlgAboutBox.Instance.StartPosition = (this.WindowState == FormWindowState.Minimized) ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent; Logger.I("UserRequest :: Show About dialog"); DlgAboutBox.Instance.ShowDialog(this); } else { DlgAboutBox.Instance.Activate(); } Logger.V("<< FormMain.UserRequest_ShowDlgAbout"); }
public void ApplyProfileUpdate() { Logger.V(">> AppManager.ApplyProfileUpdate"); // XPath: /Profile/StartAuto ApplyProfileItemAutoStart(); // XPath: /Profile/LogToFile if (m_profile.m_isLogToFile) { Logger.Enable(m_profile.m_logLevel); } else { Logger.Disable(); } // restart current work mode, and update GUI Logger.I("AppManager.ApplyProfileUpdate :: " + "Trigger the current work mode restarting."); StartCurrentWorkMode(); Logger.V("<< AppManager.ApplyProfileUpdate"); }
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 + ")"); }
public void EnableProxy() { Logger.V(">> AppManager.EnableProxy"); m_semaphore.WaitOne(); string szProxyAddr = IeProxyOptions.ProxyAddr; string szBypass = IeProxyOptions.Bypass; string args = true.ToString() + " " + "\"" + szProxyAddr + "\" " + "\"" + szBypass + "\" " + true.ToString(); RunProcessProxyAgent(args); if (IeProxyOptions.ProxyEnable != true || IeProxyOptions.AutoConfDisabled != true) { Logger.W("AppManager.EnableProxy :: " + "Failed to enable system proxy for the 1st round."); System.Threading.Thread.Sleep(1000); RunProcessProxyAgent(args); if (IeProxyOptions.ProxyEnable != true || IeProxyOptions.AutoConfDisabled != true) { Logger.E("AppManager.EnableProxy :: " + "Failed to enable system proxy for the 2nd round."); } else { Logger.I("AppManager.EnableProxy :: " + "Correctly enable system proxy for the 2nd round."); } } else { Logger.I("AppManager.EnableProxy :: " + "Correctly enable system proxy for the 1st round."); } NotifyGuiNetworkChanged(this, new EventArgs()); m_semaphore.Release(); Logger.V("<< AppManager.EnableProxy"); }
public bool LoadAppProfile() { bool createdNew; m_profile = Profile.Load(m_szAppDir, out createdNew); m_currWorkMode = m_profile.m_defWorkMode; if (m_profile.m_isLogToFile) { Logger.Enable(m_profile.m_logLevel); } Logger.V(">> AppManager.LoadAppProfile"); // move to here as a countermeasure if (createdNew) { Logger.I("AppManager.LoadAppProfile :: Profile is created and loaded."); } else { Logger.I("AppManager.LoadAppProfile :: Profile exists and is loaded."); } Logger.V("<< AppManager.LoadAppProfile : " + createdNew.ToString()); return(createdNew); }
public FormMain(AppManager appManager) { Logger.V(">> FormMain.FormMain"); Logger.I("FormMain :: Initialize Front End."); // init member variables m_appManagerRef = appManager; m_prevState = FormWindowState.Normal; m_listModeMenuItems = new List <MenuItem>(); m_miNiCtxNetworkStatus = null; m_miNiCtxIPAddress = null; m_idxNiCtxProxySelection = 0; // init GUI components InitializeComponent(); this.Text = AssemblyProduct; aboutToolStripMenuItem.Text = "&About " + AssemblyProduct; InitGuiNotifyIcon(); // set GUI properties according to profile if (m_appManagerRef.AppProfile.m_isStartMinimized) { this.Visible = false; } // set registry key according to profile m_appManagerRef.ApplyProfileItemAutoStart(); // link AppManager to GUI m_appManagerRef.NotifyGuiNetworkChanged += new AppManager.NotifyNetworkChanged( this.AppMgrNotify_NetworkChanged); // start current work mode m_appManagerRef.StartCurrentWorkMode(); Logger.V("<< FormMain.FormMain"); }
static void Main() { try { string path = Process.GetCurrentProcess().MainModule.FileName; path = Path.GetDirectoryName(path); bool createdNew; Mutex instance = new Mutex(true, Process.GetCurrentProcess().ProcessName, out createdNew); if (createdNew) { Logger.Initialize( Path.Combine(path, AppManager.APP_NEW_LOG_FILE_NAME), Path.Combine(path, AppManager.APP_OLD_LOG_FILE_NAME)); AppManager appManager = new AppManager(path); if (!appManager.LoadAppEnvironment()) { string msg = @"'" + AppManager.PROXY_AGENT_FILE_NAME + "' is missing." + Environment.NewLine + @"Failed to launch " + AppManager.ASSEMBLY_PRODUCT + @"."; Logger.E(msg); MessageBox.Show(msg, AppManager.ASSEMBLY_PRODUCT, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (appManager.LoadAppProfile()) { string msg = @"New profile '" + Profile.PROFILE_FILE_NAME + @"' has been created successfully."; Logger.I(msg); DialogResult dr = MessageBox.Show(msg + Environment.NewLine + @"It is strongly recommended to set the options before using " + AppManager.ASSEMBLY_PRODUCT + @"." + Environment.NewLine + @"Would you like to set the options right now?", AppManager.ASSEMBLY_PRODUCT, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { dr = DlgOptions.Instance.ShowDialog( appManager.AppProfile); if ((dr == DialogResult.OK) && (!appManager.AppProfile.Equals(DlgOptions.DlgProfile))) { appManager.AppProfile = new Profile(DlgOptions.DlgProfile); Profile.Save(DlgOptions.DlgProfile); } } } if (!appManager.IsLoadAppProfileFailed()) { Application.Run(new FormMain(appManager)); } } instance.ReleaseMutex(); } else { MessageBox.Show( "ProxyManager is already running.", AppManager.ASSEMBLY_PRODUCT, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception x) { string msg = x.Message + Environment.NewLine + x.StackTrace; Logger.E(msg); MessageBox.Show(msg, AppManager.ASSEMBLY_PRODUCT, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Logger.Terminate(); } }