Esempio n. 1
0
        /// <summary>
        /// Loads the configuration from the specified file.
        /// </summary>
        public bool Load(string fileName, out string errMsg)
        {
            SetToDefault();

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

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);
                XmlElement rootElem = xmlDoc.DocumentElement;

                DataSourceType = rootElem.GetChildAsEnum <DataSourceType>("DataSourceType");
                DbConnSettings.LoadFromXml(rootElem.SelectSingleNode("DbConnSettings"));
                SelectQuery  = rootElem.GetChildAsString("SelectQuery");
                AutoTagCount = rootElem.GetChildAsBool("AutoTagCount");
                TagCount     = rootElem.GetChildAsInt("TagCount");

                errMsg = "";
                return(true);
            } catch (Exception ex) {
                errMsg = CommPhrases.LoadKpSettingsError + ":" + Environment.NewLine + ex.Message;
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the configuration to the specified file.
        /// </summary>
        public bool Save(string fileName, out string errMsg)
        {
            try
            {
                XmlDocument    xmlDoc  = new XmlDocument();
                XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                xmlDoc.AppendChild(xmlDecl);

                XmlElement rootElem = xmlDoc.CreateElement("KpDbImportConfig");
                xmlDoc.AppendChild(rootElem);

                rootElem.AppendElem("DataSourceType", DataSourceType);
                DbConnSettings.SaveToXml(rootElem.AppendElem("DbConnSettings"));
                rootElem.AppendElem("SelectQuery", SelectQuery);
                rootElem.AppendElem("AutoTagCount", AutoTagCount);
                rootElem.AppendElem("TagCount", TagCount);

                XmlElement exportCmdsElem = rootElem.AppendElem("ExportCmds");
                foreach (ExportCmd exportCmd in ExportCmds)
                {
                    exportCmd.SaveToXml(exportCmdsElem.AppendElem("ExportCmd"));
                }

                xmlDoc.Save(fileName);
                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommPhrases.SaveKpSettingsError + ":" + Environment.NewLine + ex.Message;
                return(false);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Sets the default values.
 /// </summary>
 private void SetToDefault()
 {
     DataSourceType = DataSourceType.Undefined;
     DbConnSettings = new DbConnSettings();
     SelectQuery    = "";
     AutoTagCount   = true;
     TagCount       = 0;
 }