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); } }
private void BuildLocalWorkParameter() { this.WorkPeriod = (int)SettingsParser.ParseDecimal(_iniFile.ReadValue("Local", "WorkPeriod")); this.LocalWorkParameter = new WorkParameters(); this.LocalWorkParameter.IndexError = (uint)SettingsParser.ParseDecimal(_iniFile.ReadValue("Local", "IndexError")); this.LocalWorkParameter.MaxUserDataLen = (uint)SettingsParser.ParseDecimal(_iniFile.ReadValue("Local", "MaxUserDataLen")); this.LocalWorkParameter.TimeoutCycle = (uint)SettingsParser.ParseDecimal(_iniFile.ReadValue("Local", "TimeoutCycle")); }
private void ReadIniFiles() { var fileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Resources.ini"; var iniFile = new WinIniFile(fileName, System.Text.Encoding.UTF8); var section = "String"; // ProjectCode var value = iniFile.ReadValue(section, "ProjectCode"); ProjectCode = Convert.ToUInt16(value, 16); // ApplicationDescription = iniFile.ReadValue(section, "AppDescription", Resources.AppDescription); CompanyChsAbbrName = iniFile.ReadValue(section, "CompanyChsAbbrName", Resources.CompanyChsAbbrName); CompanyChsFullName = iniFile.ReadValue(section, "CompanyChsFullName", Resources.CompanyChsFullName); Copyright = iniFile.ReadValue(section, "CopyRight", Resources.CopyRight); ProductNumericVersion = iniFile.ReadValue(section, "ProductNumericVersion", Resources.ProductNumericVersion).Split('.').Select(p => byte.Parse(p)).ToArray(); ProductStringVersion = iniFile.ReadValue(section, "ProductStringVersion", Resources.ProductStringVersion); ProductEnName = iniFile.ReadValue(section, "ProductEnName", Resources.ProductEnName); ProjectEnName = iniFile.ReadValue(section, "ProjectEnName", Resources.ProjectEnName); ProjectChsName = iniFile.ReadValue(section, "ProjectChsName", Resources.ProjectChsName); CompanyEnFullName = iniFile.ReadValue(section, "CompanyEnFullName", Resources.CompanyEnFullName); CompanyEnAbbrName = iniFile.ReadValue(section, "CompanyEnAbbrName", Resources.CompanyEnAbbrName); }