Пример #1
0
        private static IDiagnosticControllerDto GetController(string text)
        {
            // Check Input.
            if (text == null)
            {
                return(null);
            }

            var split          = text.Split(new[] { ' ' }, 2);
            var controllerText = split[1];


            var index          = controllerText.IndexOf(".", 0, StringComparison.Ordinal);
            var controllerName = controllerText.Substring(0, index);

            // Populate Controller.
            var controller = new DiagnosticControllerDto
            {
                TroubleCodes = new List <IDiagnosticTroubleCodeDto>(),
                FreezeFrames = new List <IDiagnosticFreezeFrameDto>()
            };

            controller.ControllerName = controllerName;
            controller.TroubleCodes.Add(GetDiagnosticTroubleCodeResult(text));
            // Return.
            return(controller);
        }
Пример #2
0
        private static DiagnosticResultDto MapDiagnosticResult(Dictionary <int, DiagnosticResultDto> resultDictionary,
                                                               DiagnosticResultDto r, DiagnosticControllerDto c, DiagnosticTroubleCodeDto tc, dynamic ff)
        {
            if (!r.ResultId.HasValue)
            {
                return(null);
            }

            if (!resultDictionary.TryGetValue(r.ResultId.Value, out var result))
            {
                result             = r;
                result.Controllers = new List <IDiagnosticControllerDto>();
                resultDictionary.Add(r.ResultId.Value, result);
            }

            if (c == null)
            {
                return(result);
            }

            var controller = result.Controllers.FirstOrDefault(rc => rc.ControllerId == c.ControllerId);

            if (controller == null)
            {
                controller = c;
                controller.TroubleCodes = new List <IDiagnosticTroubleCodeDto>();
                controller.FreezeFrames = new List <IDiagnosticFreezeFrameDto>();
                result.Controllers.Add(controller);
            }

            if (controller.TroubleCodes.All(ctc => ctc.DiagnosticTroubleCodeId != tc.DiagnosticTroubleCodeId))
            {
                controller.TroubleCodes.Add(tc);
            }

            if (string.IsNullOrEmpty(ff?.SensorGroupsJson))
            {
                return(result);
            }
            if (controller.FreezeFrames.Any(cff => cff.FreezeFrameDiagnosticTroubleCode == ff.FreezeFrameDiagnosticTroubleCode))
            {
                return(result);
            }

            List <DiagnosticFreezeFrameSensorGroupDto> groups = JsonConvert.DeserializeObject <ICollection <DiagnosticFreezeFrameSensorGroupDto> >(ff.SensorGroupsJson);

            var freezeFrame = new DiagnosticFreezeFrameDto
            {
                FreezeFrameDiagnosticTroubleCode = ff.FreezeFrameDiagnosticTroubleCode,
                FreezeFrameSensorGroups          = groups.ToList <IDiagnosticFreezeFrameSensorGroupDto>()
            };

            controller.FreezeFrames.Add(freezeFrame);

            return(result);
        }
Пример #3
0
        private static IDiagnosticControllerDto GetController(List <string> lines)
        {
            // Check Input.
            if (!lines?.Any() ?? true)
            {
                return(null);
            }

            // Create Controller.
            var controller = new DiagnosticControllerDto
            {
                TroubleCodes = new List <IDiagnosticTroubleCodeDto>(),
                FreezeFrames = new List <IDiagnosticFreezeFrameDto>()
            };

            // Populate Controller.
            for (var i = 0; i < lines.Count - 1; ++i)
            {
                // Check Line.
                if (CheckLine(lines[i], lines[i + 1]))
                {
                    continue;
                }

                // Load Values.
                var endIndex = i;
                switch (lines[i])
                {
                case "<CONTROLLER_NAME>":
                    controller.ControllerName = controller.ControllerName ?? GetValue(lines[i + 1]);
                    break;

                case "<DTC_RESULTS>":
                    endIndex = lines.FindIndex(i + 1, e => e.EndsWith("DTC_RESULTS>")) - 1;
                    controller.TroubleCodes.Add(GetDiagnosticTroubleCodeResult(lines.Skip(i + 1).Take(endIndex - i).ToList()));
                    i = endIndex;
                    break;

                case "<FF_INFO>":
                    endIndex = lines.FindIndex(i + 1, e => e.EndsWith("FF_INFO>")) - 1;
                    controller.FreezeFrames.Add(GetFreezeFrameInfo(lines.Skip(i + 1).Take(endIndex - i).ToList()));
                    i = endIndex;
                    break;
                }
            }

            // Return.
            return(controller);
        }
Пример #4
0
        private static IDiagnosticControllerDto GetController(string text)
        {
            // Check Input.
            if (text == null)
            {
                return(null);
            }

            // Populate Controller.
            var controller = new DiagnosticControllerDto
            {
                ControllerName = GetFieldValue(text, "CONTROLLER_NAME"),
                TroubleCodes   = new List <IDiagnosticTroubleCodeDto>(),
                FreezeFrames   = new List <IDiagnosticFreezeFrameDto>()
            };

            // Process Info.
            var textList = Regex.Split(text, @"(DTC_DESCRIPTION?|FF_INFO?)").Skip(1).ToList();

            for (var i = 0; i < textList.Count; i++)
            {
                switch (textList[i])
                {
                case "DTC_DESCRIPTION":
                    controller.TroubleCodes.Add(GetDiagnosticTroubleCodeResult(textList[i] + textList[i + 1]));
                    i = i + 1;
                    break;

                case "FF_INFO":
                    controller.FreezeFrames.Add(GetFreezeFrameInfo(textList[i] + textList[i + 1]));
                    i = i + 1;
                    break;
                }
            }

            // Return.
            return(controller);
        }