private List <Proxy> ParseHAProxyStats(string input) { if (string.IsNullOrEmpty(input)) { return(new List <Proxy>()); } var lines = input.Split(StringSplits.NewLine); var stats = new List <Item>(); foreach (var l in lines) { //Skip the header if (string.IsNullOrEmpty(l) || l.StartsWith("#")) { continue; } //Collect each stat line as we go, group later stats.Add(Item.FromLine(l)); } var result = stats.GroupBy(s => s.UniqueProxyId).Select(g => new Proxy { Instance = this, Name = g.First().ProxyName, Frontend = g.FirstOrDefault(s => s.Type == StatusType.Frontend) as Frontend, Servers = g.OfType <Server>().ToList(), Backend = g.FirstOrDefault(s => s.Type == StatusType.Backend) as Backend, PollDate = DateTime.UtcNow }).ToList(); return(result); }
private async Task <List <Proxy> > ParseHAProxyStats(Stream stream) { var stats = new List <Item>(); using (var sr = new StreamReader(stream)) { string line; while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null) { //Skip the header if (line.IsNullOrEmpty() || line.StartsWith("#")) { continue; } //Collect each stat line as we go, group later stats.Add(Item.FromLine(line)); } } var result = stats.GroupBy(s => s.UniqueProxyId).Select(g => new Proxy { Instance = this, Name = g.First().ProxyName, Frontend = g.FirstOrDefault(s => s.Type == StatusType.Frontend) as Frontend, Servers = g.OfType <Server>().ToList(), Backend = g.FirstOrDefault(s => s.Type == StatusType.Backend) as Backend, PollDate = DateTime.UtcNow }).ToList(); return(result); }