/// <summary> /// Read the current configuration from XML file /// </summary> private void LoadConfigurationFile() { XmlDocument configFile = new XmlDocument(); configFile.Load(strConfigurationFile); XmlNode curNode; curNode = configFile.SelectSingleNode("/configuration/opcservertype"); if (curNode != null) { theOPCServerType = (eOPCServerType)Enum.Parse(typeof(eOPCServerType), curNode.InnerText); } curNode = null; curNode = configFile.SelectSingleNode("/configuration/opctopicname"); if (curNode != null) { theOPCServerTopic = curNode.InnerText; } curNode = null; curNode = configFile.SelectSingleNode("/configuration/opcprocessname"); if (curNode != null) { theOPCServerProcessName = curNode.InnerText; } curNode = null; curNode = configFile.SelectSingleNode("/configuration/monitoringcycle"); if (curNode != null) { theCycleTime = int.Parse(curNode.InnerText); } curNode = null; curNode = configFile.SelectSingleNode("/configuration/monitoringenabled"); if (curNode != null) { theKeepAliveMonitorIsEnabled = bool.Parse(curNode.InnerText); } curNode = null; curNode = configFile.SelectSingleNode("/configuration/schedulerenabled"); if (curNode != null) { theSchedulerIsEnabled = bool.Parse(curNode.InnerText); } curNode = null; curNode = configFile.SelectSingleNode("/configuration/schedulertime"); if (curNode != null) { theSchedulerTime = DateTime.Parse(curNode.InnerText); } curNode = null; configFile = null; }
/// <summary> /// Configuration wizard to support the user on OPC setup /// </summary> private void ConfigurationWizardKeepAliveMonitor() { ///Variable that store the user input string userInput = ""; string defaultEnable = ""; if (theKeepAliveMonitorIsEnabled) { defaultEnable = "Yes"; } else { defaultEnable = "No"; } ///Request if the keep alive monitor will be enabled userInput = UserDecision.ShowInputComboBox(defaultEnable, "Enable auto-restart by server state?", new string[] { "Yes", "No" }); if (userInput == "") { MessageBox.Show("This value cannot be empty..."); return; } ; switch (userInput) { case "Yes": theKeepAliveMonitorIsEnabled = true; break; case "No": theKeepAliveMonitorIsEnabled = false; break; default: theKeepAliveMonitorIsEnabled = false; MessageBox.Show("Invalid value!"); return; } userInput = ""; ///Request the OPC Type userInput = UserDecision.ShowInputComboBox(theOPCServerType.ToString(), "Input the OPC server type", new string[] { eOPCServerType.DataFEED.ToString(), eOPCServerType.INAT.ToString(), eOPCServerType.KEPWare.ToString(), eOPCServerType.RsLinx.ToString(), eOPCServerType.SoftingS7.ToString() }); if (userInput == "") { MessageBox.Show("This value cannot be empty..."); return; } ; theOPCServerType = (eOPCServerType)Enum.Parse(typeof(eOPCServerType), userInput); userInput = ""; ///Request the OPC topic (address) string defaultTopicConfig; switch (theOPCServerType) { case eOPCServerType.DataFEED: defaultTopicConfig = "Softing.OPC.DF.S7.DA.1"; break; case eOPCServerType.INAT: defaultTopicConfig = "INAT TcpIpH1 OPC Server"; break; case eOPCServerType.KEPWare: defaultTopicConfig = ""; break; case eOPCServerType.RsLinx: defaultTopicConfig = "RsLinx OPC Server"; break; case eOPCServerType.SoftingS7: defaultTopicConfig = "Softing.OPC.S7.DA.1"; break; default: defaultTopicConfig = ""; break; } userInput = UserDecision.ShowInputString(defaultTopicConfig, "Input the OPC topic (address)"); if (userInput == "") { MessageBox.Show("This value cannot be empty..."); return; } ; theOPCServerTopic = userInput; userInput = ""; ///Request the process name string defaultProcessName; switch (theOPCServerType) { case eOPCServerType.DataFEED: defaultProcessName = "OSF_Service"; break; case eOPCServerType.INAT: defaultProcessName = "TCPIPH1"; break; case eOPCServerType.KEPWare: defaultProcessName = ""; break; case eOPCServerType.RsLinx: defaultProcessName = "RSLINX"; break; case eOPCServerType.SoftingS7: defaultProcessName = "S7OPCsvc"; break; default: defaultProcessName = ""; break; } userInput = UserDecision.ShowInputString(defaultProcessName, "Input the name of OPC process (Windows)"); if (userInput == "") { MessageBox.Show("This value cannot be empty..."); return; } ; theOPCServerProcessName = userInput; userInput = ""; ///Request the cycle timer userInput = UserDecision.ShowInputString(theCycleTime.ToString(), "Input the cycle timer in [ms]"); int newCycleTimer; if (userInput == "") { MessageBox.Show("This value cannot be empty..."); return; } ; if (int.TryParse(userInput, out newCycleTimer) == false) { MessageBox.Show("Input value was not valid. Please use just numbers..."); return; } ; theCycleTime = newCycleTimer; userInput = ""; //Save the new configurtaion and restart the application. GenerateConfigurationFile(); }