예제 #1
0
        /// <summary>
        /// Saves the specified connections to disk
        /// </summary>
        /// <param name="OptionsFile">The File name to use</param>
        /// <param name="Options">The TCP/IP Connections to use</param>
        public static void Save(string OptionsFile, TCPIPOptions Options)
        {
            XmlTextWriter xtw = new XmlTextWriter(Path.Combine(rootPath, Helper.RemoveUnsupportedChars(OptionsFile) + ".xml"), Encoding.UTF8);

            xtw.WriteStartDocument();
            xtw.WriteStartElement("TCPIPOptions");
            xtw.WriteStartElement("HostAddress");
            xtw.WriteString(Options.HostAddress.ToString());
            xtw.WriteEndElement();
            xtw.WriteStartElement("Port");
            xtw.WriteString(Options.Port.ToString());
            xtw.WriteEndElement();
            xtw.WriteStartElement("LLPHeader");
            xtw.WriteString(Options.LLPHeader);
            xtw.WriteEndElement();
            xtw.WriteStartElement("LLPTrailer");
            xtw.WriteString(Options.LLPTrailer);
            xtw.WriteEndElement();
            xtw.WriteStartElement("WaitForAck");
            xtw.WriteString(Options.WaitForAck.ToString());
            xtw.WriteEndElement();
            xtw.WriteStartElement("SendAck");
            xtw.WriteString(Options.SendAck.ToString());
            xtw.WriteEndElement();
            xtw.WriteEndElement();
            xtw.WriteEndDocument();
            xtw.Close();
        }
예제 #2
0
        /// <summary>
        /// Loads a specific TCP/IP Options file from disk
        /// </summary>
        /// <param name="OptionsFile">The option file to load</param>
        /// <returns>The TCPIPOptions object created from the file</returns>
        public static TCPIPOptions Load(string OptionsFile)
        {
            XmlTextReader xtr = new XmlTextReader(Path.Combine(rootPath, OptionsFile + ".xml"));

            xtr.Read();
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(xtr);

            TCPIPOptions ops = new TCPIPOptions();

            if (xDoc.SelectSingleNode("TCPIPOptions/HostAddress") != null)
            {
                ops.HostAddress = IPAddress.Parse(xDoc.SelectSingleNode("TCPIPOptions/HostAddress").InnerText);
            }
            if (xDoc.SelectSingleNode("TCPIPOptions/Port") != null)
            {
                ops.Port = Int32.Parse(xDoc.SelectSingleNode("TCPIPOptions/Port").InnerText);
            }
            if (xDoc.SelectSingleNode("TCPIPOptions/LLPHeader") != null)
            {
                ops.LLPHeader = xDoc.SelectSingleNode("TCPIPOptions/LLPHeader").InnerText;
            }
            if (xDoc.SelectSingleNode("TCPIPOptions/LLPTrailer") != null)
            {
                ops.LLPTrailer = xDoc.SelectSingleNode("TCPIPOptions/LLPTrailer").InnerText;
            }
            if (xDoc.SelectSingleNode("TCPIPOptions/WaitForAck") != null)
            {
                ops.WaitForAck = Convert.ToBoolean(xDoc.SelectSingleNode("TCPIPOptions/WaitForAck").InnerText);
            }
            if (xDoc.SelectSingleNode("TCPIPOptions/SendAck") != null)
            {
                ops.SendAck = Convert.ToBoolean(xDoc.SelectSingleNode("TCPIPOptions/SendAck").InnerText);
            }
            xtr.Close();
            return(ops);
        }