// ReSharper disable once ReturnTypeCanBeEnumerable.Local private static List <Environment> GetEnvironments(XPathNavigator xPathNavigator) { var environments = new List <Environment>(); var nodes = xPathNavigator.Select("config/environments/environment"); while (nodes.MoveNext()) { var crt = nodes.Current; var name = crt.GetStringAttributeValue("name"); var id = crt.GetLongAttributeValue("id"); if (string.IsNullOrWhiteSpace(name)) { throw new InvalidDataException("encountered 'environment' element without name attribute value"); } if (id == null) { throw new InvalidDataException("encountered 'environment' element without id attribute value"); } var environment = new Environment(name, id.Value); environments.Add(environment); } if (environments.Count != environments.Select(e => e.Id).Distinct().Count()) { throw new InvalidDataException("duplicate ids found within environments"); } return(environments); }
private static CheckBase CompleteCheckRead( XPathNavigator crt, long id, CheckType type, Environment environment, Service service, TimeSpan interval, int?maxContentLength) { // ReSharper disable once SwitchStatementMissingSomeCases switch (type) { case CheckType.Ping: throw new NotImplementedException(); case CheckType.HttpCall: return(CompleteHttpCheck(crt, id, environment, service, interval, maxContentLength)); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
private static HttpCheck CompleteHttpCheck( XPathNavigator crt, long id, Environment environment, Service service, TimeSpan interval, int?maxContentLength) { var method = crt.GetEnumAttributeValue <HttpCheck.HttpMethod>("method"); var url = crt.GetUriAttributeValue("url"); var connectTimeout = crt.GetTimeSpanAttributeValue("connectTimeout"); var readTimeout = crt.GetTimeSpanAttributeValue("readTimeout"); if (method == null) { throw new InvalidDataException("HttpCall check is missing/has invalid the (HTTP) method"); } if (url == null) { throw new InvalidDataException("HttpCall check is missing/has invalid its URL"); } if (connectTimeout + readTimeout > interval) { throw new InvalidDataException("the combined timeouts cannot be larger than the check interval"); } var conditions = new List <HttpCheckCondition>(); var conditionsNode = crt.SelectSingleNode("conditions"); conditionsNode.MoveToFirstChild(); do { if (conditionsNode.NodeType != XPathNodeType.Element) { continue; } var conditionsClone = conditionsNode.Clone(); var conditionType = conditionsClone.Name; var attributeStrings = new List <KeyValuePair <string, string> >(); var value = conditionsClone.Value; if (conditionsClone.HasAttributes) { if (conditionsClone.MoveToFirstAttribute()) { do { attributeStrings.Add(new KeyValuePair <string, string>(conditionsClone.Name, conditionsClone.Value)); } while (conditionsClone.MoveToNextAttribute()); } } var condition = GetCondition(conditionType, attributeStrings, value); conditions.Add(condition); } while (conditionsNode.MoveToNext()); var roConditions = conditions.AsReadOnly(); var check = new HttpCheck( id, environment, service, interval, url, roConditions, method.Value, connectTimeout, readTimeout, maxContentLength ?? HttpCheck.DefaultMaxContentLength); return(check); }