StandardResponse IResponseProcessor.ProcessResponse(IEnumerable<string> responseLines, int exitCode, String splitRegEx = null) { var lines = responseLines.ToList(); var standardResponse = new StandardResponse(); ((IResponseProcessor)standardResponse).ProcessResponse(lines, exitCode); if (exitCode != 0) return standardResponse; var objects = new List<dynamic>(); var currentObjectRows = new List<string>(); foreach (var line in lines.Skip(3)) { if (String.IsNullOrWhiteSpace(line)) { if (currentObjectRows.Count > 0) objects.Add(currentObjectRows.ProcessRawData(splitRegEx)); currentObjectRows = new List<string>(); } else currentObjectRows.Add(line); } standardResponse.ResponseObject = objects; return standardResponse; }
StandardResponse IResponseProcessor.ProcessResponse(IEnumerable<string> responseLines, int exitCode, String splitRegEx = null) { var lines = responseLines.ToList(); var standardResponse = new StandardResponse(); ((IResponseProcessor)standardResponse).ProcessResponse(lines, exitCode); if (exitCode != 0) return standardResponse; var regex = new Regex(@"[ ]{4}"); var tabulatedLines = lines.ToList().Select(x => { while (Regex.IsMatch(x, @"^\t*([ ]{4})+")) // Ensures we are still working on a tab at the beginning of the line x = regex.Replace(x, "\t", 1); return x; }).ToList(); //Convert the beginning spaces to tabs if (tabulatedLines.Any(x => !Regex.IsMatch(x, @"^\t"))) // If any lines start with a tab level of 0, we need to tab everything over by 1 tab tabulatedLines = tabulatedLines.Select(x => { if (!String.IsNullOrWhiteSpace(x)) return "\t" + x; return x; }).ToList(); var root = new Tree(); RecursivelyProcessToTree(tabulatedLines.Skip(3).GetEnumerator(), root, splitRegEx); standardResponse.ResponseObject = root.Children.Select(child => RecursivelyFlattenToDynamic(child)).ToList(); // Remove the root and add the dynamic objects to the response return standardResponse; }
StandardResponse IResponseProcessor.ProcessResponse(IEnumerable<string> responseLines, int exitCode, String splitRegEx = null) { IResponseProcessor response = new StandardResponse(); var entries = new List<String>(); entries = responseLines.Skip(3).Where(line => !String.IsNullOrWhiteSpace(line)).Select(line => line.Trim()).ToList(); var respObj = response.ProcessResponse(entries, exitCode); respObj.ResponseObject = entries; return respObj; }
StandardResponse IResponseProcessor.ProcessResponse(IEnumerable <string> responseLines, int exitCode, String splitRegEx = null) { var lines = responseLines.ToList(); var standardResponse = new StandardResponse(); ((IResponseProcessor)standardResponse).ProcessResponse(lines, exitCode); if (exitCode != 0) { return(standardResponse); } var regex = new Regex(@"[ ]{4}"); var tabulatedLines = lines.ToList().Select(x => { while (Regex.IsMatch(x, @"^\t*([ ]{4})+")) // Ensures we are still working on a tab at the beginning of the line { x = regex.Replace(x, "\t", 1); } return(x); }).ToList(); //Convert the beginning spaces to tabs if (tabulatedLines.Any(x => !Regex.IsMatch(x, @"^\t"))) // If any lines start with a tab level of 0, we need to tab everything over by 1 tab { tabulatedLines = tabulatedLines.Select(x => { if (!String.IsNullOrWhiteSpace(x)) { return("\t" + x); } return(x); }).ToList(); } var root = new Tree(); RecursivelyProcessToTree(tabulatedLines.Skip(3).GetEnumerator(), root, splitRegEx); standardResponse.ResponseObject = root.Children.Select(child => RecursivelyFlattenToDynamic(child)).ToList(); // Remove the root and add the dynamic objects to the response return(standardResponse); }
StandardResponse IResponseProcessor.ProcessResponse(IEnumerable<string> responseLines, int exitCode, String splitRegEx = null) { IResponseProcessor response = new StandardResponse(); response.ProcessResponse(responseLines, exitCode); return (StandardResponse)response; }