public void Read(XmlNode node) { if (node == null) { throw new ArgumentNullException("node"); } XmlAttributeCollection attrs = node.Attributes; string host = attrs.GetRequired <string> ("host"); if (host.Length == 0) { throw new InvalidOperationException("The host attribute must not be empty."); } Host = host; int port = attrs.GetOptional <int> ("port", 25); if (port < 1 || port > 65535) { throw new InvalidOperationException("Port must be an integer between 1 and 65535"); } Port = port; EnableSSL = attrs.GetOptional <bool> ("enableSSL", true); user = attrs.GetOptional <string> ("user", null); password = attrs.GetOptional <string> ("password", null); }
Author ReadEmail(XmlNode node) { if (node == null) { return(null); } string name, address; XmlAttributeCollection attrs = node.Attributes; name = attrs.GetOptional <string> ("name", null); address = attrs.GetOptional <string> ("address", null); if (address == null) { Log(LogSeverity.Warning, "Email address without the 'address' attribute in the commit source with id '{0}'", ID); return(null); } return(new Author() { Email = address, Name = name }); }
public static T GetRequired <T> (this XmlAttributeCollection coll, string name) { T value = coll.GetOptional <T> (name, default(T)); if (value == null) { throw new InvalidOperationException(String.Format("Required attribute '{0}' not found", name)); } return(value); }
public void Read(XmlNode node) { if (node == null) { return; } XmlAttributeCollection attrs = node.Attributes; ID = attrs.GetRequired <string> ("id"); SendAsCommitter = attrs.GetOptional("sendAsCommitter", false); UseCommitterAsSenderName = attrs.GetOptional("useCommitterAsSenderName", false); Author addr = ReadEmail(node.SelectSingleNode("//from")); if (!SendAsCommitter && addr == null) { throw new InvalidOperationException(String.Format("Required <from> element is missing from commit source with id '{0}'", ID)); } From = addr; addr = ReadEmail(node.SelectSingleNode("//replyTo")); if (addr == null) { ReplyTo = From; } else { ReplyTo = addr; } ReadEmails(node.SelectNodes("//to/email"), TORecipients); if (TORecipients.Count == 0) { throw new InvalidOperationException("List of TO addresses must have at least one element"); } ReadEmails(node.SelectNodes("//cc/email"), CCRecipients); ReadEmails(node.SelectNodes("//bcc/email"), BCCRecipients); }