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; }
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"); }
private void SetDialogLayout(Profile profile) { m_dlgProfile = new Profile(profile); // default work mode m_dlgInstance.rbAuto.Checked = false; m_dlgInstance.rbProxy.Checked = false; m_dlgInstance.rbDirect.Checked = false; switch (m_dlgProfile.m_defWorkMode) { case WorkMode.Auto: m_dlgInstance.rbAuto.Checked = true; break; case WorkMode.Direct: m_dlgInstance.rbDirect.Checked = true; break; case WorkMode.Proxy: m_dlgInstance.rbProxy.Checked = true; break; } // start auto m_dlgInstance.cbStartAuto.Checked = m_dlgProfile.m_isStartAuto; // start minimized m_dlgInstance.cbStartMinimized.Checked = m_dlgProfile.m_isStartMinimized; // log to file m_dlgInstance.cbLogToFile.Checked = m_dlgProfile.m_isLogToFile; // log level m_dlgInstance.cbLogLevel.Enabled = m_dlgInstance.cbLogToFile.Checked; m_dlgInstance.cbLogLevel.Items.Clear(); m_dlgInstance.cbLogLevel.Items.Add(Logger.Category.Error); m_dlgInstance.cbLogLevel.Items.Add(Logger.Category.Warning); m_dlgInstance.cbLogLevel.Items.Add(Logger.Category.Information); m_dlgInstance.cbLogLevel.Items.Add(Logger.Category.Verbose); if (profile.m_logLevel != Logger.Category.NONE) { m_dlgInstance.cbLogLevel.Text = profile.m_logLevel.ToString(); } else { // default, for forbidding NONE category m_dlgInstance.cbLogLevel.Text = Logger.Category.Information.ToString(); } // proxy group lvProxyGroups.Items.Clear(); foreach (ProxyGroup pg in m_dlgProfile.m_listProxyGroups) { ListViewItem item = CreateListViewItem(pg); lvProxyGroups.Items.Add(item); } }
// 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"); }
// 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; }
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"); }
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; }