public static Config GetConfig(string options) { XmlDocument document = GetDocument(options); var configNames = new[] { AsciiConfig.Name, AsciiViaTcpConfig.Name, RtuConfig.Name, RTUviaTCPConfig.Name, TcpConfig.Name }; string rootTagName = document.ChildNodes.OfType <XmlNode>() .First(n => configNames.Contains(n.Name)) .Name; Config config; switch (rootTagName) { case AsciiConfig.Name: config = new AsciiConfig(); break; case AsciiViaTcpConfig.Name: config = new AsciiViaTcpConfig(); break; case RtuConfig.Name: config = new RtuConfig(); break; case RTUviaTCPConfig.Name: config = new RTUviaTCPConfig(); break; case TcpConfig.Name: config = new TcpConfig(); break; default: throw new NotSupportedException(rootTagName); } config.SetDocument(document); return(config); }
public static Config GetConfig(string options) { var document = GetDocument(options); var configNames = new [] { AsciiConfig.Name, AsciiViaTcpConfig.Name, RtuConfig.Name, RTUviaTCPConfig.Name, TcpConfig.Name }; var rootTagName = document.ChildNodes.OfType<XmlNode>() .First(n => configNames.Contains(n.Name)) .Name; Config config; switch (rootTagName) { case AsciiConfig.Name: config = new AsciiConfig(); break; case AsciiViaTcpConfig.Name: config = new AsciiViaTcpConfig(); break; case RtuConfig.Name: config = new RtuConfig(); break; case RTUviaTCPConfig.Name: config = new RTUviaTCPConfig(); break; case TcpConfig.Name: config = new TcpConfig(); break; default: throw new NotSupportedException(rootTagName); } config.SetDocument(document); return config; }
private void UpdateConfig() { switch (ConfigType) { case ConfigType.Ascii: if (AsciiConfig == null) { Config = new AsciiConfig(); } break; case ConfigType.AsciiViaTcp: if (AsciiViaTcpConfig == null) { Config = new AsciiViaTcpConfig(); } break; case ConfigType.Rtu: if (RtuConfig == null) { Config = new RtuConfig(); } break; case ConfigType.RtuViaTcp: if (RtuViaTcpConfig == null) { Config = new RTUviaTCPConfig(); } break; case ConfigType.Tcp: if (TcpConfig == null) { Config = new TcpConfig(); } break; default: throw new NotSupportedException(ConfigType.ToString()); } }