V() public static méthode

public static V ( string content ) : void
content string
Résultat void
Exemple #1
0
 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");
 }
Exemple #2
0
        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");
        }
Exemple #3
0
 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");
 }
Exemple #4
0
 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");
 }
Exemple #5
0
 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");
 }
Exemple #6
0
        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");
        }
Exemple #7
0
        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");
        }
Exemple #8
0
 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");
 }
Exemple #9
0
        public bool IsLoadAppProfileFailed()
        {
            Logger.V(">> AppManager.IsLoadAppProfileFailed");
            bool ret = Profile.IsLoadFailed();

            Logger.V("<< AppManager.IsLoadAppProfileFailed : " + ret.ToString());
            return(ret);
        }
 public NetworkDetector()
 {
     Logger.V(">> NetworkDetector.NetworkDetector");
     m_activeNetwork = null;
     m_activeIP      = null;
     DetectActiveNetwork();
     Logger.V("<< NetworkDetector.NetworkDetector");
 }
 public void OsNotify_NetworkChanged(object sender, EventArgs e)
 {
     Logger.V(">> NetworkDetector.OsNotify_NetworkChanged");
     System.Threading.Thread.Sleep(1000);
     DetectActiveNetwork();
     NetworkChanged(this, new EventArgs());
     Logger.V("<< NetworkDetector.OsNotify_NetworkChanged");
 }
Exemple #12
0
        public bool LoadAppEnvironment()
        {
            Logger.V(">> AppManager.LoadAppEnvironment");
            string path = Path.Combine(m_szAppDir, PROXY_AGENT_FILE_NAME);
            bool   ret  = File.Exists(path);

            Logger.V("<< AppManager.LoadAppEnvironment : " + ret.ToString());
            return(ret);
        }
Exemple #13
0
        public DialogResult ShowDialog(IWin32Window owner, Profile profile)
        {
            Logger.V(">> DlgOptions.ShowDialog");
            SetDialogLayout(profile);
            DialogResult dr = ShowDialog(owner);

            Logger.V("<< DlgOptions.ShowDialog : " + dr.ToString());
            return(dr);
        }
Exemple #14
0
        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);
        }
        public DialogResult ShowDialog(IWin32Window owner, ProxyGroup pg)
        {
            Logger.V(">> DlgOptionsProxyGroup.ShowDialog");
            m_bExitByOK = false;
            SetDialogLayout(pg);
            DialogResult dr = ShowDialog(owner);

            Logger.V("<< DlgOptionsProxyGroup.ShowDialog : " + dr.ToString());
            return(dr);
        }
Exemple #16
0
        // Method: Load from local profile
        public static Profile Load(string appDir, out bool createdNew)
        {
            Logger.V(">> Profile.Load");
            Profile profile     = null;
            string  profilePath = Path.Combine(appDir, PROFILE_FILE_NAME);

            if (File.Exists(profilePath))
            {
                XmlSerializer xs     = new XmlSerializer(typeof(Profile));
                StreamReader  reader = new StreamReader(profilePath);
                createdNew = false;
                try {
                    profile = (Profile)xs.Deserialize(reader.BaseStream);
                    profile.m_szProfilePath = profilePath;
                    reader.Close();
                } catch (Exception) {
                    reader.Close();
                    DialogResult dr = MessageBox.Show(
                        "Error occurs in loading the profile."
                        + Environment.NewLine + Environment.NewLine
                        + "- Press 'Yes' to load the default profile settings, "
                        + "but user settings will be lost."
                        + Environment.NewLine
                        + "- Press 'No' to exit for manually fixing the error in the editor.",
                        AppManager.ASSEMBLY_PRODUCT,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Error);
                    if (dr == DialogResult.Yes)
                    {
                        // create an initial profile
                        profile = new Profile();
                        profile.m_szProfilePath = profilePath;
                        Save(profile);
                        createdNew = true;
                    }
                    else
                    {
                        // exit application
                        s_bLoadFailed = true;
                        Application.Exit();
                    }
                }
            }
            else
            {
                profile = new Profile();
                profile.m_szProfilePath = profilePath;
                Save(profile);
                createdNew = true;
            }
            Logger.V("<< Profile.Load");
            return(profile);
        }
Exemple #17
0
 public Profile(Profile profile)
 {
     Logger.V(">> Profile.Profile");
     m_defWorkMode      = profile.m_defWorkMode;
     m_isStartAuto      = profile.m_isStartAuto;
     m_isStartMinimized = profile.m_isStartMinimized;
     m_isLogToFile      = profile.m_isLogToFile;
     m_logLevel         = profile.m_logLevel;
     m_listProxyGroups  = new List <ProxyGroup>(profile.m_listProxyGroups);
     m_szProfilePath    = profile.m_szProfilePath;
     s_bLoadFailed      = false;
     Logger.V("<< Profile.Profile");
 }
Exemple #18
0
 // Contructor Method
 public Profile()
 {
     Logger.V(">> Profile.Profile");
     m_defWorkMode      = WorkMode.Auto;
     m_isStartAuto      = true;
     m_isStartMinimized = true;
     m_isLogToFile      = true;
     m_logLevel         = Logger.Category.Information;
     m_listProxyGroups  = new List <ProxyGroup>();
     m_szProfilePath    = String.Empty;
     s_bLoadFailed      = false;
     Logger.V("<< Profile.Profile");
 }
Exemple #19
0
        // Method: Save to local profile
        public static void Save(Profile profile)
        {
            Logger.V(">> Profile.Save");
            XmlSerializer xs     = new XmlSerializer(typeof(Profile));
            StreamWriter  writer = new StreamWriter(profile.m_szProfilePath, false);

            try {
                xs.Serialize(writer.BaseStream, profile);
            } catch (Exception x) {
                System.Diagnostics.Debug.WriteLine(x.Message);
            }
            writer.Close();
            Logger.V("<< Profile.Save");
        }
Exemple #20
0
 private void UserRequest_ShowFormMain(object sender, EventArgs e)
 {
     Logger.V(">> FormMain.UserRequest_ShowFormMain");
     if (this.WindowState == FormWindowState.Minimized)
     {
         this.Show();                      // step 1 - show
         this.ShowInTaskbar = true;        // step 2 - show
         this.WindowState   = m_prevState; // step 3 - show
     }
     else
     {
         this.Activate();
     }
     Logger.V("<< FormMain.UserRequest_ShowFormMain");
 }
Exemple #21
0
 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");
 }
Exemple #22
0
        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");
        }
Exemple #23
0
 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");
 }
Exemple #24
0
        public void ApplyProfileItemAutoStart()
        {
            Logger.V(">> AppManager.ApplyProfileItemAutoStart");
            RegistryKey rk = Registry.CurrentUser.OpenSubKey(
                @"Software\Microsoft\Windows\CurrentVersion\Run", true);

            if (m_profile.m_isStartAuto)
            {
                rk.SetValue(ASSEMBLY_PRODUCT,
                            Path.Combine(m_szAppDir, PROXY_MANAGER_FILE_NAME));
            }
            else if (rk.GetValue(ASSEMBLY_PRODUCT) != null)
            {
                rk.DeleteValue(ASSEMBLY_PRODUCT);
            }
            rk.Close();
            Logger.V("<< AppManager.ApplyProfileItemAutoStart");
        }
Exemple #25
0
 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");
 }
Exemple #26
0
        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 + ")");
        }
Exemple #27
0
        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");
        }
Exemple #28
0
        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);
        }
Exemple #29
0
        public AppManager(string appDir)
        {
            Logger.V(">> AppManager.AppManager");

            m_semaphore    = new Semaphore(1, 1);
            m_szAppDir     = appDir;
            m_detector     = new NetworkDetector();
            m_profile      = null;
            m_currWorkMode = WorkMode.Direct;

            // link NetworkDetector to AppManager
            m_detector.NetworkChanged +=
                new NetworkDetector.NotifyAppManagerNetworkChanged(
                    this.DetectorNotify_NetworkChanged);

            // link OS to NetworkDetector
            NetworkChange.NetworkAddressChanged +=
                new NetworkAddressChangedEventHandler(
                    m_detector.OsNotify_NetworkChanged);

            Logger.V("<< AppManager.AppManager");
        }
Exemple #30
0
        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");
        }