예제 #1
0
 public ConfigManager()
 {
     this.commonConfig = new AppConfig();
     this.configName = "Config";
     this.profiles = new Dictionary<string, AppConfig>();
     //this.LoadData();
     // if profiles are empty
     //this.AddNewProfile();
 }
예제 #2
0
 public void LoadDataXml()
 {
     try
     {
         System.Xml.Serialization.XmlSerializer xmlS = new XmlSerializer(typeof(object[]));
         FileStream stream = new FileStream(Application.StartupPath + "\\" + this.configName + ".xcfg", FileMode.Open, FileAccess.Read);
         object[] all = (object[])xmlS.Deserialize(stream);
         this.commonConfig = (AppConfig)all[0];
         this.profiles = (Dictionary<string, AppConfig>)all[1];
         stream.Close();
         stream.Dispose();
     }
     catch (Exception ex)
     {
         this.commonConfig = new AppConfig();
         this.profiles = new Dictionary<string, AppConfig>();
         Lib.CoreLib.WriteLog(ex, "LoadData");
     }
 }
예제 #3
0
 // will add a specific profile
 public void AddNewProfile(string profileName, string profileKey)
 {
     AppConfig ac = new AppConfig();
     ac.p_name = profileName;
     ac.p_key = profileKey;
     this.profiles.Add(profileKey, ac);
 }
예제 #4
0
        public bool LoadData()
        {
            bool loadOK = true;
            object[] cfg = _loadData(this.configName);
            try
            {
                if (cfg.Length == 2)
                {
                    this.commonConfig = (AppConfig)cfg[0];
                    this.profiles = (Dictionary<string, AppConfig>)cfg[1];
                }
                else loadOK = false;
            }
            catch (Exception ex)
            {
                loadOK = false;
                this.commonConfig = new AppConfig();
                this.profiles = new Dictionary<string, AppConfig>();
                Lib.CoreLib.WriteLog(ex, "LoadData");
            }

            if (loadOK)
                return true;

            if (File.Exists(Application.StartupPath + "\\backup\\" + this.configName + ".cfg"))
                try
                {
                    File.Copy(Application.StartupPath + "\\backup\\" + this.configName + ".cfg", Application.StartupPath + "\\" + this.configName + ".cfg", true);
                    cfg = _loadData(this.configName);
                    if (cfg.Length == 2)
                    {
                        this.commonConfig = (AppConfig)cfg[0];
                        this.profiles = (Dictionary<string, AppConfig>)cfg[1];
                        loadOK = true;
                    }
                }
                catch (Exception ex)
                {
                    Lib.CoreLib.WriteLog(ex, "LoadData");
                }
            if (!loadOK)
                MessageBox.Show("Помилка завантаження конфігурації. Звяжіться з постачальником програмного забезпечення.", Application.ProductName,
                 MessageBoxButtons.OK, MessageBoxIcon.Error);

            return loadOK;
        }
예제 #5
0
 // will add en empty profile
 public void AddNewProfile()
 {
     AppConfig ac = new AppConfig();
     this.profiles.Add(ac.p_key, ac);
 }