private bool PrepareTestNGXmlForExecution()
        {
            TestNGSuiteXML customizedSuiteXML = null;

            try
            {
                switch (ExecutionMode)
                {
                case eExecutionMode.XML:
                case eExecutionMode.FreeCommand:
                    //Parameters
                    if (TestNgSuiteXMLObj != null && TestngXmlParametersToOverwrite != null && TestngXmlParametersToOverwrite.Count > 0)
                    {
                        General.AddInfoToConsole("Create Custom TestNG Xml for Execution");
                        customizedSuiteXML = new TestNGSuiteXML(TestngXmlPath);
                        customizedSuiteXML.OverrideXMLParameters(TestngXmlParametersToOverwrite);
                    }
                    break;
                }

                //create temp XML
                if (customizedSuiteXML != null)
                {
                    General.AddInfoToConsole("Save Custom TestNG Xml for Execution");
                    if (OverwriteOriginalTestngXml)
                    {
                        customizedSuiteXML.SuiteXml.Save(TestngXmlPath);//overwrite original TestNG xml
                        TestNgSuiteXMLObj = new TestNGSuiteXML(TestngXmlPath);
                        General.AddInfoToConsoleAndAction(GingerAction, String.Format("The Parameters of '{0}' TestNG XML were overwritten", TestngXmlPath));
                    }
                    else
                    {
                        string customeXMLFilePath = Path.Combine(TempWorkingFolder, "Custom " + Path.GetFileName(TestngXmlPath));
                        customizedSuiteXML.SuiteXml.Save(customeXMLFilePath);
                        mOriginalTestngXmlPath = TestngXmlPath;
                        TestngXmlPath          = customeXMLFilePath;
                        TestNgSuiteXMLObj      = new TestNGSuiteXML(TestngXmlPath);
                        General.AddInfoToConsoleAndAction(GingerAction, String.Format("Customized TestNG XML path: '{0}'", TestNgSuiteXMLObj.XmlFilePath));
                    }
                }
                else
                {
                    General.AddInfoToConsole("TestNG Xml customization is not needed");
                }
                return(true);
            }
            catch (Exception ex)
            {
                General.AddErrorToConsoleAndAction(GingerAction, string.Format("Failed to Prepare TestNG Xml for execution, Error is: '{0}'", ex.Message));
                return(false);
            }
        }
        public bool ValidateAndPrepareConfigs()
        {
            //validate general inputes
            if (Directory.Exists(TempWorkingFolder) == false)
            {
                General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to create temp working folder at: '{0}'", TempWorkingFolder));
                return(false);
            }
            else
            {
                General.AddInfoToConsoleAndAction(GingerAction, String.Format("Temp working folder path: '{0}'", TempWorkingFolder));
            }

            if (ExecuterType == eExecuterType.Java)
            {
                if (Path.GetFileName(JavaExeFullPath).ToLower().Contains("java") == false || File.Exists(JavaExeFullPath) == false)
                {
                    General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find Java Executor file at: '{0}'", JavaExeFullPath));
                    return(false);
                }
                else
                {
                    General.AddInfoToConsoleAndAction(GingerAction, String.Format("Path of Java Executor file: '{0}'", JavaExeFullPath));
                }
            }
            else//Maven Executer
            {
                if (Path.GetFileName(MavenCmdFullPath).ToLower().Contains("mvn") == false || File.Exists(MavenCmdFullPath) == false)
                {
                    General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find MVN Executor file at: '{0}'", MavenCmdFullPath));
                    return(false);
                }
                else
                {
                    General.AddInfoToConsoleAndAction(GingerAction, String.Format("Path of MVN Executor file: '{0}'", MavenCmdFullPath));
                }
            }

            switch (ExecutionMode)
            {
            case eExecutionMode.XML:
            case eExecutionMode.DynamicXML:
                if (JavaProjectType == eJavaProjectType.Regular)
                {
                    if (Directory.Exists(JavaProjectResourcesPath.Trim().TrimEnd('*')) == false)
                    {
                        General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the TestNG resources folder at: '{0}'", JavaProjectResourcesPath));
                        return(false);
                    }
                    else
                    {
                        General.AddInfoToConsoleAndAction(GingerAction, String.Format("TestNG resources path: '{0}'", JavaProjectResourcesPath));
                    }

                    if (Directory.Exists(JavaProjectBinPath) == false)
                    {
                        General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the TestNG testing project Bin folder at: '{0}'", JavaProjectBinPath));
                        return(false);
                    }
                    else
                    {
                        General.AddInfoToConsoleAndAction(GingerAction, String.Format("TestNG testing project Bin folder path: '{0}'", JavaProjectBinPath));
                    }
                }
                else     //Maven Project
                {
                    if (Directory.Exists(MavenProjectFolderPath) == false)
                    {
                        General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the Maven Java project folder at: '{0}'", MavenProjectFolderPath));
                        return(false);
                    }
                    else
                    {
                        General.AddInfoToConsoleAndAction(GingerAction, String.Format("Maven Java project path: '{0}'", MavenProjectFolderPath));
                    }
                }

                if (ExecutionMode == eExecutionMode.DynamicXML)
                {
                    if (XmlTestsToExecute != null && XmlTestsToExecute.Count > 0)
                    {
                        string testsListStr = "Tests to execute: ";
                        foreach (TestNGTest test in XmlTestsToExecute)
                        {
                            test.Name = test.Name.Trim();
                            if (!TestNgSuiteXMLObj.IsTestExistInXML(test.Name))
                            {
                                General.AddErrorToConsoleAndAction(GingerAction, string.Format("The Test '{0}' do not exist in the TestNG Suite XML", test.Name));
                                return(false);
                            }
                            else
                            {
                                testsListStr += string.Format("'{0}', ", test.Name);
                            }
                        }
                        testsListStr.TrimEnd(',');
                        General.AddInfoToConsoleAndAction(GingerAction, testsListStr);
                    }

                    if (TestGroupsToInclude != null && TestGroupsToInclude.Count > 0)
                    {
                        string groupsToIncludeListStr = "Tests Groups to include: ";
                        foreach (TestNGTestGroup group in TestGroupsToInclude)
                        {
                            groupsToIncludeListStr += string.Format("'{0}', ", group.Name);
                        }
                        groupsToIncludeListStr.TrimEnd(',');
                        General.AddInfoToConsoleAndAction(GingerAction, groupsToIncludeListStr);
                    }
                    if (TestGroupsToExclude != null && TestGroupsToExclude.Count > 0)
                    {
                        string groupsToExcludeListStr = "Tests Groups to exclude: ";
                        foreach (TestNGTestGroup group in TestGroupsToExclude)
                        {
                            groupsToExcludeListStr += string.Format("'{0}', ", group.Name);
                        }
                        groupsToExcludeListStr.TrimEnd(',');
                        General.AddInfoToConsoleAndAction(GingerAction, groupsToExcludeListStr);
                    }
                }
                break;

            case eExecutionMode.FreeCommand:
                if (JavaProjectType == eJavaProjectType.Regular)
                {
                    if (!string.IsNullOrEmpty(JavaWorkingFolder))
                    {
                        if (Directory.Exists(JavaWorkingFolder) == false)
                        {
                            General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the Java Working folder at: '{0}'", JavaWorkingFolder));
                            return(false);
                        }
                        else
                        {
                            General.AddInfoToConsoleAndAction(GingerAction, String.Format("Java Working folder path: '{0}'", JavaWorkingFolder));
                        }
                    }
                }

                if (string.IsNullOrEmpty(FreeCommandArguments.Trim()))
                {
                    General.AddErrorToConsoleAndAction(GingerAction, String.Format("Provided Free Command Arguments are not valid: '{0}'", FreeCommandArguments));
                    return(false);
                }
                else
                {
                    General.AddInfoToConsoleAndAction(GingerAction, String.Format("Free Command Arguments: '{0}'", FreeCommandArguments));
                }

                if (CommandParametersToOverride != null && CommandParametersToOverride.Count > 0)
                {
                    string paramsListStr = "Command Parameters to override: ";
                    foreach (CommandParameter param in CommandParametersToOverride)
                    {
                        param.Name = param.Name.Trim();
                        if (!FreeCommandArguments.Contains(param.Name))
                        {
                            General.AddErrorToConsoleAndAction(GingerAction, string.Format("The Command Parameter '{0}' do not exist in the Command Arguments", param.Name));
                            return(false);
                        }
                        else
                        {
                            paramsListStr += string.Format("'{0}'='{1}', ", param.Name, param.Value);
                        }
                    }
                    paramsListStr.TrimEnd(',');
                    General.AddInfoToConsoleAndAction(GingerAction, paramsListStr);
                }
                break;
            }

            if (ExecutionMode != eExecutionMode.FreeCommand ||
                (ExecutionMode == eExecutionMode.FreeCommand && string.IsNullOrEmpty(TestngXmlPath) == false))
            {
                TestNgSuiteXMLObj = new TestNGSuiteXML(TestngXmlPath);
                if (TestNgSuiteXMLObj.LoadError != null)
                {
                    General.AddErrorToConsoleAndAction(GingerAction, TestNgSuiteXMLObj.LoadError);
                    return(false);
                }
                else
                {
                    General.AddInfoToConsoleAndAction(GingerAction, String.Format("TestNG XML path: '{0}'", TestNgSuiteXMLObj.XmlFilePath));
                }
            }

            if (TestNgSuiteXMLObj != null && TestngXmlParametersToOverwrite != null && TestngXmlParametersToOverwrite.Count > 0)
            {
                string paramsListStr = "Parameters to override: ";
                foreach (TestNGTestParameter param in TestngXmlParametersToOverwrite)
                {
                    if (param == null || string.IsNullOrEmpty(param.Name))
                    {
                        continue;
                    }
                    else
                    {
                        param.Name = param.Name.Trim();
                    }
                    if (!string.IsNullOrEmpty(param.ParentNodeName))
                    {
                        param.ParentNodeName = param.ParentNodeName.Trim();
                    }
                    if (!TestNgSuiteXMLObj.IsParameterExistInXML(param.Name, param.ParentNodeName))
                    {
                        if (string.IsNullOrEmpty(param.ParentNodeName))
                        {
                            General.AddErrorToConsoleAndAction(GingerAction, string.Format("The Parameter '{0}' do not exist in the TestNG Suite XML", param.Name));
                        }
                        else
                        {
                            General.AddErrorToConsoleAndAction(GingerAction, string.Format("The Parameter '{0}\\{1}' do not exist in the TestNG Suite XML", param.ParentNodeName, param.Name));
                        }
                        return(false);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(param.ParentNodeName))
                        {
                            paramsListStr += string.Format("'{0}'='{1}', ", param.Name, param.Value);
                        }
                        else
                        {
                            paramsListStr += string.Format("'{0}\\{1}'='{2}', ", param.ParentNodeName, param.Name, param.Value);
                        }
                    }
                }
                paramsListStr.TrimEnd(',');
                General.AddInfoToConsoleAndAction(GingerAction, paramsListStr);
            }

            if (ParseTestngResultsXml == true)
            {
                if (Directory.Exists(TestngResultsXmlFolderPath) == false)
                {
                    General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the TestNG output report root folder at: '{0}'", TestngResultsXmlFolderPath));
                    return(false);
                }
                else
                {
                    General.AddInfoToConsoleAndAction(GingerAction, String.Format("TestNG output report root folder path: '{0}'", TestngResultsXmlFolderPath));
                }
            }

            return(true);
        }