Exemplo n.º 1
0
        private void Initialize(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new Exception(string.Format("指定的文件不存在!{0}", fileName));
            }

            var iniFile = new WinIniFile(fileName);

            // Parse Local Port.
            var value = iniFile.ReadValue("Local", "Port");

            this.LocalEndPoint.Port = (int)SettingsParser.ParseDecimal(value);

            //
            var index = 1;

            while (index <= 100)
            {
                var section = string.Format("Remote{0}", index++);
                var keys    = iniFile.ReadValue(section, null);
                if (string.IsNullOrEmpty(keys))
                {
                    continue;
                }

                var remoteId = (ushort)SettingsParser.ParseDecimal(iniFile.ReadValue(section, "ID"));
                var endPoint = SettingsParser.ParseIPEndPoint(iniFile.ReadValue(section, "IPEndPoint"));

                this.RemoteEndPoints.Add(remoteId, endPoint);
            }
        }