ProxyManager.Profile.Load C# (CSharp) Method

Load() public static method

public static Load ( string appDir, bool &createdNew ) : Profile
appDir string
createdNew bool
return 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;
        }

Usage Example

示例#1
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);
        }