Beispiel #1
0
        private static EmailReportingConfiguration LoadConfiguration(XDocument configDoc, List <string> reportKeys)
        {
            ReportsElement reportsElement = ReportsElement.Parse(
                configDoc.Element(ReportsElement.TAG),
                reportKeys
                );

            return(reportsElement.ToEmailReportingConfiguration());
        }
Beispiel #2
0
        public static ReportsElement Parse(XElement element, List <string> reportKeys)
        {
            if (element == null)
            {
                throw new FormatException($"'{TAG}' tag not found.");
            }

            XAttribute senderEmailAttribute = element.Attribute(SENDER_EMAIL_ATTRIBUTE);
            XAttribute passwordAttribute    = element.Attribute(PASSWORD_ATTRIBUTE);
            XAttribute mailServerAttribute  = element.Attribute(MAIL_SERVER_ATTRIBUTE);
            XAttribute portAttribute        = element.Attribute(PORT_ATTRIBUTE);

            if (senderEmailAttribute == null)
            {
                throw new FormatException($"'{SENDER_EMAIL_ATTRIBUTE}' attribute of {TAG} element is missing.");
            }

            if (passwordAttribute == null)
            {
                throw new FormatException($"'{PASSWORD_ATTRIBUTE}' attribute of {TAG} element is missing.");
            }

            if (mailServerAttribute == null)
            {
                throw new FormatException($"'{MAIL_SERVER_ATTRIBUTE}' attribute of {TAG} element is missing.");
            }

            if (portAttribute == null)
            {
                throw new FormatException($"'{PORT_ATTRIBUTE}' attribute of {TAG} element is missing.");
            }

            ReportsElement configElement = new ReportsElement(
                senderEmailAttribute.Value,
                passwordAttribute.Value,
                mailServerAttribute.Value,
                portAttribute.Value
                );

            foreach (string key in reportKeys)
            {
                configElement.AddReport(ReportElement.Parse(element.Element(key), key));
            }

            return(configElement);
        }