예제 #1
0
        public static int Main(string[] args)
        {
            if (args.Count() < 1)
            {
                Console.WriteLine("Usage: TelemetryConfigChecker.exe <Configfile path> [-v] [<manifest file path 1> <manifest file path 2> ... ]");

                return(1);
            }

            string filePath = args[0];

            // simple parse of the arguments (looks for -v on the second argument)
            bool verbose = (args.Count() > 1) ? ((args.ElementAt(1) == "-v") ? true : false) : false;

            IEnumerable <string> manifestFilePaths = args.Skip(verbose ? 2 : 1).Take(args.Length - 1);

            List <TraceAggregationConfig> telemetryConfigEntryList;

            // parsing the config file
            List <ParseResult> parseResults = SyntaxAnalyzer.Parse(filePath, manifestFilePaths, (type, format, arg) => { Console.WriteLine(type + ": " + format, arg); }, verbose, out telemetryConfigEntryList);

            if (verbose)
            {
                // printing the configurations loaded
                foreach (var telConfigEntry in telemetryConfigEntryList)
                {
                    Console.WriteLine(telConfigEntry.ToString());
                }
            }

            Console.WriteLine("#Configs Lines sucessfuly parsed   = {0}", telemetryConfigEntryList.Count);
            Console.WriteLine("#Configs Lines failed to be parsed = {0}", parseResults.Count - telemetryConfigEntryList.Count);

            if (telemetryConfigEntryList.Count != parseResults.Count)
            {
                Console.WriteLine("Parsing Failed");

                // printing the errors occurred
                foreach (var parseRes in parseResults)
                {
                    if (parseRes.ParseCode != ParseCode.Success)
                    {
                        Console.WriteLine("{0}({1},{2}) : Error : {3}", filePath, parseRes.LineNumber, parseRes.ColumnPos + 1, parseRes.ErrorMsg);
                    }
                }
            }
            else
            {
                Console.Write("Parsing Succeeded");
            }

            return(0);
        }
예제 #2
0
        // Static method which returns a list with the white-listed traces and
        //  respective aggregation configurations parsed from the config file provided
        public static List <ParseResult> Parse(
            string filePath,
            IEnumerable <string> manifestFilesPaths,
            LogErrorDelegate logErrorDelegate,
            bool verbose,
            out List <TraceAggregationConfig> telemetryConfigEntryList)
        {
            telemetryConfigEntryList = new List <TraceAggregationConfig>();
            List <ParseResult> parseResultsList = new List <ParseResult>();

            try
            {
                using (StreamReader fileStream = File.OpenText(filePath))
                {
                    SyntaxAnalyzer telemetryParser = new SyntaxAnalyzer(fileStream, manifestFilesPaths, logErrorDelegate, verbose);

                    // parse line by line using the grammar and stores the parsed trace configurations
                    int currentLine = 0;
                    while (true)
                    {
                        TraceAggregationConfig traceConfigEntry;

                        currentLine++;
                        string configLine = telemetryParser.ReadNextLine(logErrorDelegate);
                        if (configLine == null)
                        {
                            // EOL
                            break;
                        }

                        telemetryParser.lexAnalyzer = new LexicalAnalyzer(configLine);

                        var parseResult = telemetryParser.L(out traceConfigEntry);
                        parseResult.LineNumber = currentLine;

                        if (parseResult.ParseCode != ParseCode.EmptyLine &&
                            parseResult.ParseCode != ParseCode.Comment)
                        {
                            // checking if something went wrong during parsing and a null object was created
                            if (traceConfigEntry == null && parseResult.ParseCode == ParseCode.Success)
                            {
                                logErrorDelegate(LogSourceId, "Unexpected null entry generated on parsing of file - {0} - ParseResult: {1}", filePath, parseResult);
                                parseResult = new ParseResult(ParseCode.ParserError, string.Format("Previous ParseResult Value: {0}", parseResult), 0, currentLine);
                            }

                            parseResultsList.Add(parseResult);

                            if (parseResult.ParseCode == ParseCode.Success)
                            {
                                telemetryConfigEntryList.Add(traceConfigEntry);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                parseResultsList.Add(new ParseResult(ParseCode.ParserError, string.Format("Exception while opening or parsing config file - {0} - Exception: {1}", filePath, e)));
            }

            return(parseResultsList);
        }