Exemple #1
0
        public static DTC GetStartDTC(string[] values)
        {
            if (values.Length > 5)
            {
                for (int i = values.Length - 1; i > 5; --i)
                {
                    string pcode1 = values[i - 4];
                    string pcode2 = values[i - 3];
                    string dfc    = values[i - 5];

                    if (IsPCode(pcode1) && IsPCode(pcode2) &&
                        (dfc == "tbd" || (dfc.Length == 4 && short.TryParse(dfc, out short dfcValue))))
                    {
                        DTC dtc = new DTC()
                        {
                            DFCCode = dfc,
                            SAECode = pcode1,
                            VAGCode = pcode2,

                            ErrorClass = values[i - 1],
                            Carb       = values[i],

                            DFCIndex = i - 5
                        };

                        dtc.Sym       = values[i - 6];
                        dtc.ErrorType = values[i - 2];

                        return(dtc);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        public static void ParseDTCs(string[] args)
        {
            string    pdf    = @"C:\Users\steveb\Desktop\Logger\Simos85.pdf";
            PdfReader reader = new PdfReader(pdf);// @"C:\Users\steve\Source\Repos\fr-pdf-parser\FR_PDF_PARSER\Siemens 3.0T Audi S4, S5, A6, Q7.pdf");

            List <DTC> dtcs    = new List <DTC>();
            DTC        current = null;

            for (int page = 5383; page <= reader.NumberOfPages; ++page)
            {
                string pageText = PdfTextExtractor.GetTextFromPage(reader, page);

                string[] lines = pageText.Split(new char[] { (char)0x0A }, StringSplitOptions.None);

                for (int i = 0; i < lines.Length; ++i)
                {
                    string line = lines[i].Trim();

                    if (line.StartsWith("Symptom based diagnostics"))
                    {
                        page = 999999999;
                        break;
                    }
                    else if (line.StartsWith("Designed by"))
                    {
                        //end of page
                        break;
                    }
                    else if (line.StartsWith("Transmittal, reproduction") ||
                             line.StartsWith("as well as utilisation") ||
                             line.StartsWith("without express") ||
                             line.StartsWith("for payment of damages") ||
                             line.StartsWith("of a utility model") ||
                             line.StartsWith("Chapter Part") ||
                             line.StartsWith("Table of failures"))
                    {
                        //start of page
                        continue;
                    }

                    string[] values = line.Split(' ');
                    DTC      start  = DTC.GetStartDTC(values);
                    if (start != null)
                    {
                        if (current != null && current.Description.Length > 0)
                        {
                            current.Description = current.Description.Substring(0, current.Description.Length - 1);
                        }

                        dtcs.Add(start);

                        int startIndex = 0;
                        if (DTC.IsErrorName(values[0]) && DTC.IsErrorName(values[1]))
                        {
                            start.GlobalError   = values[0];
                            start.ErrorLocation = values[1];
                            start.Description   = "";
                            startIndex          = 2;
                        }
                        else if (DTC.IsErrorName(values[0]))
                        {
                            start.GlobalError   = current.GlobalError;
                            start.ErrorLocation = values[0];
                            start.Description   = "";
                            startIndex          = 1;
                        }
                        else
                        {
                            start.GlobalError   = current.GlobalError;
                            start.ErrorLocation = current.ErrorLocation;
                            start.Description   = "";
                            startIndex          = 0;
                        }

                        for (int j = startIndex; j < start.DFCIndex - 1; ++j)
                        {
                            start.Description += values[j] + " ";
                        }

                        current = start;
                    }
                    else if (current != null)
                    {
                        int startIndex = 0;
                        //DO STUFF TO ADD IN DESCRIPTION
                        if (values.Length > 2 && DTC.IsErrorName(values[0]) && DTC.IsErrorName(values[1]))
                        {
                            current.GlobalError   += values[0];
                            current.ErrorLocation += values[1];
                            startIndex             = 2;
                        }
                        else if (values.Length > 1 && DTC.IsErrorName(values[0]))
                        {
                            startIndex           = 1;
                            current.GlobalError += values[0];
                        }
                        else
                        {
                            startIndex = 0;
                        }

                        for (int j = startIndex; j < values.Length; ++j)
                        {
                            current.Description += values[j] + " ";
                        }
                    }
                }
            }

            XmlSerializer ser = new XmlSerializer(typeof(List <DTC>));

            using (FileStream fs = new FileStream(@"c:\temp\parsedDTCS.xml", FileMode.Create))
            {
                ser.Serialize(fs, dtcs);
            }
        }