public bool ValidateRecordParser(string id, string logName, string configBaseDirectory, string configFile, out IList <String> messages)
        {
            IConfigurationRoot config = ConfigValidator.LoadConfigFile(configBaseDirectory, configFile);

            var configFileValidator = new ConfigValidator(_schemaBaseDirectory);

            bool isValid = configFileValidator.ValidateSchema(configBaseDirectory, configFile, config, out messages);

            if (isValid)
            {
                var sourcesSection = config.GetSection("Sources");
                var sourceSections = sourcesSection.GetChildren();

                foreach (var sourceSection in sourceSections)
                {
                    string curId = config[$"{sourceSection.Path}:{"Id"}"];

                    if (curId.Equals(id))
                    {
                        string sourceType = config[$"{sourceSection.Path}:{"SourceType"}"];

                        if (!sourceType.Equals("DirectorySource"))
                        {
                            messages.Add("This tool only diagnose DirectorySource SourceType.");
                            return(true);
                        }

                        string recordParser   = config[$"{sourceSection.Path}:{"RecordParser"}"];
                        string directory      = config[$"{sourceSection.Path}:{"Directory"}"];
                        string fileNameFilter = config[$"{sourceSection.Path}:{"FileNameFilter"}"];

                        string[] files = Directory.GetFiles(directory, fileNameFilter ?? "*.*");

                        if (files.Length != 1 && logName == null)
                        {
                            messages.Add("You have no files or more than one files in this extension, please note that this tool only can validate one log file at a time: ");
                            foreach (string file in files)
                            {
                                messages.Add(file);
                            }
                            return(false);
                        }

                        if (recordParser.Equals("Timestamp"))
                        {
                            return(ValidateTimeStamp(directory, logName ?? files[0], config, sourceSection, curId, messages));
                        }
                        else if (recordParser.Equals("Regex"))
                        {
                            return(ValidateRegex(directory, logName ?? files[0], config, sourceSection, curId, messages));
                        }
                        else
                        {
                            messages.Add("No needs to validate Timestamp/Regex for the Record Parser: " + recordParser);
                            return(true);
                        }
                    }
                }

                messages.Add("Source ID not found: " + id);
                return(false);
            }

            messages.Add("Invalid configuration file format detected.");
            return(false);
        }
        public int ParseAndRunArgument(string[] args)
        {
            if (args.Length == 1 || args.Length == 2)
            {
                try
                {
                    string         configPath = null;
                    IList <string> messages;

                    ConfigValidator ConfigFileValidator = new ConfigValidator(AppContext.BaseDirectory);
                    bool            isValid             = false;

                    if (args.Length == 2)
                    {
                        configPath = args[1];
                        isValid    = ConfigFileValidator.ValidateSchema(configPath, out messages);
                    }
                    else
                    {
                        isValid = ConfigFileValidator.ValidateSchema(AppContext.BaseDirectory, Constant.CONFIG_FILE, out messages);
                    }

                    Console.WriteLine("Diagnostic Test #1: Pass! Configuration file is a valid JSON object.");

                    if (isValid)
                    {
                        Console.WriteLine("Diagnostic Test #2: Pass! Configuration file has the valid JSON schema!");
                    }
                    else
                    {
                        Console.WriteLine("Diagnostic Test #2: Fail! Configuration file doesn't have the valid JSON schema: ");
                        foreach (string message in messages)
                        {
                            Console.WriteLine(message);
                        }

                        Console.WriteLine("Please fix the Configuration file to match the JSON schema");
                    }

                    return(Constant.NORMAL);
                }
                catch (FormatException ex)
                {
                    Console.WriteLine("Diagnostic Test #1: Fail! Configuration file is not a valid JSON object.");
                    Console.WriteLine(ex.Message);
                    return(Constant.INVALID_FORMAT);
                }
                catch (FileNotFoundException ex)
                {
                    Console.WriteLine("Diagnostic Test #1: Fail! Configuration file is not found.");
                    Console.WriteLine(ex.ToString());
                    return(Constant.RUNTIME_ERROR);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    return(Constant.RUNTIME_ERROR);
                }
            }
            else
            {
                WriteUsage();
                return(Constant.INVALID_ARGUMENT);
            }
        }