예제 #1
0
        /// <summary>
        /// Loads the settings from the specified file.
        /// </summary>
        public bool Load(string fileName, out string errMsg)
        {
            try
            {
                SetToDefault();

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

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

                if (rootElem.SelectSingleNode("PathOptions") is XmlNode pathOptionsNode)
                {
                    PathOptions.LoadFromXml(pathOptionsNode);
                }

                if (rootElem.SelectSingleNode("ChannelOptions") is XmlNode channelOptionsNode)
                {
                    ChannelOptions.LoadFromXml(channelOptionsNode);
                }

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.LoadAppSettingsError + ": " + ex.Message;
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Saves the settings 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("ScadaAdminConfig");
                xmlDoc.AppendChild(rootElem);

                PathOptions.SaveToXml(rootElem.AppendElem("PathOptions"));
                ChannelOptions.SaveToXml(rootElem.AppendElem("ChannelOptions"));

                XmlElement fileAssociationsElem = rootElem.AppendElem("FileAssociations");
                foreach (KeyValuePair <string, string> pair in FileAssociations)
                {
                    XmlElement associationElem = fileAssociationsElem.AppendElem("Association");
                    associationElem.SetAttribute("ext", pair.Key);
                    associationElem.SetAttribute("path", pair.Value);
                }

                xmlDoc.Save(fileName);
                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.SaveAppSettingsError + ": " + ex.Message;
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// Sets the default values.
        /// </summary>
        private void SetToDefault()
        {
            PathOptions      = new PathOptions();
            ChannelOptions   = new ChannelOptions();
            FileAssociations = new SortedList <string, string>();

            if (ScadaUtils.IsRunningOnWin)
            {
                FileAssociations.Add("sch", @"C:\SCADA\ScadaSchemeEditor\ScadaSchemeEditor.exe");
                FileAssociations.Add("tbl", @"C:\SCADA\ScadaTableEditor\ScadaTableEditor.exe");
            }
            else
            {
                FileAssociations.Add("sch", "/opt/scada/ScadaSchemeEditor/ScadaSchemeEditor.exe");
                FileAssociations.Add("tbl", "/opt/scada/ScadaTableEditor/ScadaTableEditor.exe");
            }
        }
예제 #4
0
        /// <summary>
        /// Loads the settings from the specified file.
        /// </summary>
        public bool Load(string fileName, out string errMsg)
        {
            try
            {
                SetToDefault();

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

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

                if (rootElem.SelectSingleNode("PathOptions") is XmlNode pathOptionsNode)
                {
                    PathOptions.LoadFromXml(pathOptionsNode);
                }

                if (rootElem.SelectSingleNode("ChannelOptions") is XmlNode channelOptionsNode)
                {
                    ChannelOptions.LoadFromXml(channelOptionsNode);
                }

                if (rootElem.SelectSingleNode("FileAssociations") is XmlNode fileAssociationsNode)
                {
                    foreach (XmlElement associationElem in fileAssociationsNode.SelectNodes("Association"))
                    {
                        string ext  = associationElem.GetAttrAsString("ext").ToLowerInvariant();
                        string path = associationElem.GetAttrAsString("path");
                        FileAssociations[ext] = path;
                    }
                }

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.LoadAppSettingsError + ": " + ex.Message;
                return(false);
            }
        }
예제 #5
0
        /// <summary>
        /// Saves the settings 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("ScadaAdminConfig");
                xmlDoc.AppendChild(rootElem);

                PathOptions.SaveToXml(rootElem.AppendElem("PathOptions"));
                ChannelOptions.SaveToXml(rootElem.AppendElem("ChannelOptions"));

                xmlDoc.Save(fileName);
                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.SaveAppSettingsError + ": " + ex.Message;
                return(false);
            }
        }
예제 #6
0
 /// <summary>
 /// Sets the default values.
 /// </summary>
 private void SetToDefault()
 {
     PathOptions    = new PathOptions();
     ChannelOptions = new ChannelOptions();
 }