private bool ReadConfigFile(string configFile) { StreamReader FileIn; var settings = new ArrayList(); int i = 0; int chanNum; int j; try { FileIn = new StreamReader(configFile); } catch (IOException exc) { MainLabel.Text = "Ошибка открытия конфигурационного файла!\n" + exc.Message; return(false); } try { while (!FileIn.EndOfStream) { settings.Add(FileIn.ReadLine()); if (FileIn.EndOfStream && (i < 2)) { MainLabel.Text = "Файл настроек должен состоять минимум из 3-х строк!"; return(false); } ++i; } if ((i % 3) != 0) { MainLabel.Text = "Настройки для каждого канала должны" + "состоять ровно из 3-х строк!"; return(false); } chanNum = i / 3; channelsToFix = new channelParams[chanNum]; for (i = 0; i < chanNum; ++i) { j = i * 3; channelsToFix[i] = new channelParams((string)settings[j + 0], (string)settings[j + 1], (string)settings[j + 2]); } } catch (IOException exc) { MainLabel.Text = "Ошибка чтения файла:\n" + exc.Message; } finally { FileIn.Close(); } return(true); }
//Проверка ip-канала и исправление его в случае необходимости private bool ChannelIPFix(channelParams channelToFix) { int i = 0; bool checkName = false; bool isPrimIPChanged = false; bool isBackIPChanged = false; bool noError = true; int chanNumber = 0; foreach (object chanName in ChannelNames) { if (channelToFix.ChannelName.Equals(chanName)) { chanNumber = i; checkName = true; break; } ++i; } if (checkName) { MbeServ.GetPropertyData((int)ChannelHandles[chanNumber], (object)"PrimaryInterfaceDesc", ref ptrPropertyData); if (!Convert.ToString(ptrPropertyData).Contains(channelToFix.PrimaryNIC_IP)) { isPrimIPChanged = SetChannelIP(NICType.primary, channelToFix, chanNumber); } MbeServ.GetPropertyData((int)ChannelHandles[chanNumber], (object)"BackupInterfaceDesc", ref ptrPropertyData); if (!Convert.ToString(ptrPropertyData).Contains(channelToFix.BackupNIC_IP)) { isBackIPChanged = SetChannelIP(NICType.backup, channelToFix, chanNumber); } if (isPrimIPChanged || isBackIPChanged) { MbeServ.FileSave(); } HideTimer.Interval = 5000; HideTimer.Enabled = true; } else { noError = false; } return(noError); }
private bool SetChannelIP(NICType ntype, channelParams channelToFix, int channelNumber) { string sNICType; string sNICDesc; string sNIC_IP; bool isIPChanged = false; if (ntype == NICType.primary) { sNICType = "PrimaryNetworkInterface"; sNICDesc = "PrimaryInterfaceDesc"; sNIC_IP = channelToFix.PrimaryNIC_IP; } else { sNICType = "BackupNetworkInterface"; sNICDesc = "BackupInterfaceDesc"; sNIC_IP = channelToFix.BackupNIC_IP; } MbeServ.GetPropertyData((int)ChannelHandles[channelNumber], (object)sNICDesc, ref ptrPropertyData); if (!Convert.ToString(ptrPropertyData).Contains(sNIC_IP)) { for (int i = 0; i < 128; i++) { MbeServ.SetPropertyData((int)ChannelHandles[channelNumber], (object)sNICType, i); MbeServ.GetPropertyData((int)ChannelHandles[channelNumber], (object)sNICDesc, ref ptrPropertyData); if (Convert.ToString(ptrPropertyData).Contains(sNIC_IP)) { isIPChanged = true; break; } } } return(isIPChanged); }