예제 #1
0
        /// <summary>
        /// Load application settings from file
        /// </summary>
        public bool LoadAppSettings(out string errMsg)
        {
            // setting default parameters
            AppSett.SetToDefault();

            // loading from file
            string fileName = AppData.AppDirs.ConfigDir + AppSettingsFileName;

            try {
                if (!File.Exists(fileName))
                {
                    throw new FileNotFoundException(string.Format(CommonPhrases.NamedFileNotFound, fileName));
                }

                var xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);

                // getting parameter values
                var xmlNodeList = xmlDoc.DocumentElement.SelectNodes("Param");
                foreach (XmlElement xmlElement in xmlNodeList)
                {
                    string name  = xmlElement.GetAttribute("name");
                    string nameL = name.ToLowerInvariant();
                    string val   = xmlElement.GetAttribute("value");

                    try {
                        if (nameL == "basesdffile")
                        {
                            AppSett.BaseSDFFile = val;
                        }
                        else if (nameL == "basedatdir")
                        {
                            AppSett.BaseDATDir = ScadaUtils.NormalDir(val);
                        }
                        else if (nameL == "backupdir")
                        {
                            AppSett.BackupDir = ScadaUtils.NormalDir(val);
                        }
                        else if (nameL == "commdir")
                        {
                            AppSett.CommDir = ScadaUtils.NormalDir(val);
                        }
                        else if (nameL == "backuponpassbase")
                        {
                            AppSett.AutoBackupBase = bool.Parse(val);
                        }
                    } catch {
                        throw new Exception(string.Format(CommonPhrases.IncorrectXmlParamVal, name));
                    }
                }

                errMsg = "";
                return(true);
            } catch (Exception ex) {
                errMsg = CommonPhrases.LoadAppSettingsError + ":\r\n" + ex.Message;
                AppData.ErrLog.WriteAction(errMsg, Log.ActTypes.Exception);
                return(false);
            }
        }
예제 #2
0
파일: Settings.cs 프로젝트: southasia/scada
        /// <summary>
        /// Загрузить настройки приложения из файла
        /// </summary>
        public bool LoadAppSettings(out string errMsg)
        {
            // установка параметров по умолчанию
            AppSett.SetToDefault();

            // загрузка из файла
            string fileName = AppData.ExeDir + AppSettingsFileName;

            try
            {
                if (!File.Exists(fileName))
                {
                    throw new FileNotFoundException(string.Format(CommonPhrases.NamedFileNotFound, fileName));
                }

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);

                // получение значений параметров
                XmlNodeList xmlNodeList = xmlDoc.DocumentElement.SelectNodes("Param");
                foreach (XmlElement xmlElement in xmlNodeList)
                {
                    string name  = xmlElement.GetAttribute("name");
                    string nameL = name.ToLower();
                    string val   = xmlElement.GetAttribute("value");

                    if (nameL == "basesdffile")
                    {
                        AppSett.BaseSDFFile = val;
                    }
                    else if (nameL == "basedatdir")
                    {
                        AppSett.BaseDATDir = ScadaUtils.NormalDir(val);
                    }
                    else if (nameL == "backupdir")
                    {
                        AppSett.BackupDir = ScadaUtils.NormalDir(val);
                    }
                    else if (nameL == "kpdir")
                    {
                        AppSett.KPDir = ScadaUtils.NormalDir(val);
                    }
                }

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.LoadAppSettingsError + ":\r\n" + ex.Message;
                AppData.ErrLog.WriteAction(errMsg, Log.ActTypes.Exception);
                return(false);
            }
        }