Ejemplo n.º 1
0
        private static void ExtractLinesStd(FileInfo fi)
        {
            try
            {
                using (StreamReader sr = new StreamReader(fi.FullName))
                {
                    int    lineNum = 1;
                    string line    = sr.ReadLine();
                    while (line != null)
                    {
                        string commentChar = "";
                        try
                        {
                            commentChar = ConfigurationManager.AppSettings["comment" + fi.Extension.ToLower()];
                        }
                        catch
                        {
                            //No comment character defined
                        }


                        if (!string.IsNullOrEmpty(commentChar))
                        {
                            if (!line.Trim().StartsWith(commentChar))
                            {
                                TestLine(lineNum, line);
                            }
                        }
                        else
                        {
                            TestLine(lineNum, line);
                        }

                        line = sr.ReadLine();
                        lineNum++;
                    }
                }
            }
            catch (System.UnauthorizedAccessException ex)
            {
                int sc = Errors.GetStatusCode("UnauthorizedAccessException");
                Console.ForegroundColor = Errors.GetColorByStatus(sc);
                Console.WriteLine(ex.Message);
                Console.ResetColor();
                Errors.ReportDiscrepancy(0, "Unable to Analyze file.", "Access Denied", sc);

                return;
            }
            catch (Exception ex)
            {
                int sc = Errors.GetStatusCode("Default");
                Console.ForegroundColor = Errors.GetColorByStatus(sc);
                Console.WriteLine(ex.Message);
                Console.ResetColor();
                Errors.ReportDiscrepancy(0, "Unable to Analyze file.", "Unknown Error.", sc);


                return;
            }
        }
Ejemplo n.º 2
0
        private static void ExtractLinesXML(FileInfo fi)
        {
            try
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings();
                readerSettings.IgnoreComments = true;
                readerSettings.DtdProcessing  = DtdProcessing.Parse;
                string content = "";
                using (XmlReader reader = XmlTextReader.Create(fi.FullName, readerSettings))
                {
                    while (reader.Read())
                    {
                        content = reader.ReadOuterXml();
                    }
                }

                using (StringReader sr = new StringReader(content))
                {
                    int    lineNum = 2;
                    string line    = sr.ReadLine();
                    while (line != null)
                    {
                        line = line.Trim();
                        TestLine(lineNum, line);

                        if (fi.Extension.ToUpper() == ".CONFIG")
                        {
                            HelperMethods.CollectAppSetting(fi, line);
                        }

                        line = sr.ReadLine();
                        lineNum++;
                    }
                }
            }
            catch (System.UnauthorizedAccessException ex)
            {
                int sc = Errors.GetStatusCode("UnauthorizedAccessException");
                Console.ForegroundColor = Errors.GetColorByStatus(sc);
                Console.WriteLine(ex.Message);
                Console.ResetColor();
                Errors.ReportDiscrepancy(0, "Unable to Analyze file.", "Access Denied", sc);

                return;
            }
            catch (Exception ex)
            {
                int sc = Errors.GetStatusCode("Default");
                Console.ForegroundColor = Errors.GetColorByStatus(sc);
                Console.WriteLine(ex.Message);
                Console.ResetColor();
                Errors.ReportDiscrepancy(0, "Unable to Analyze file.", "Unknown Error.", sc);

                return;
            }
        }