Exemple #1
0
        private static EmailMessage CreateEmailMessage(ConsoleCmdLine cmdLine, string[] args)
        {
            CmdLineString emailBodyPathParam = new CmdLineString("file", true, "Email body file path.");
            CmdLineString emailAddressParam  = new CmdLineString("email", false, "Comma-separated emails: [email protected];[email protected]");
            CmdLineString subjectParam       = new CmdLineString("subject", false, "Email subject.");

            cmdLine.RegisterParameter(emailBodyPathParam);
            cmdLine.RegisterParameter(emailAddressParam);
            cmdLine.RegisterParameter(subjectParam);
            cmdLine.Parse(args);

            if (!File.Exists(emailBodyPathParam))
            {
                Console.WriteLine("File email body not exists");
                return(null);
            }

            string emailBody    = File.ReadAllText(emailBodyPathParam);
            var    emailMessage = new EmailMessage
            {
                To      = GetEmailsOrDefault(emailAddressParam),
                Body    = emailBody,
                Subject = subjectParam.Exists ? subjectParam : "Test email"
            };

            return(emailMessage);
        }
Exemple #2
0
        //you can invoke it like this: EmailSenderConsoleApplication.exe -help
        // or EmailSenderConsoleApplication.exe "..\..\templates\invoice.html"
        static void Main(string[] args)
        {
            string       emailBodyPath;
            EmailMessage emailMessage = null;

            ConsoleCmdLine cmdLine = new ConsoleCmdLine();

            if (args.Length == 1 && !string.Equals(args[0], "-help", StringComparison.OrdinalIgnoreCase))
            {
                emailBodyPath = args[0];
                emailMessage  = CreateDefaultEmailMessage(emailBodyPath);
            }
            else
            {
                emailMessage = CreateEmailMessage(cmdLine, args);
            }

            if (emailMessage == null)
            {
                Console.WriteLine("Invalid parameters.");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Email message:");
            Console.WriteLine(emailMessage);


            SendEmail(emailMessage);
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
Exemple #3
0
 /*
  * cmd example : -src "E:/proto" -csharp "E:/GenCSharp"
  * call bool bResult = Builder.DoBuilder(args);
  */
 public static bool DoBuilder(string[] args)
 {
     try
     {
         ConsoleCmdLine c         = new ConsoleCmdLine();
         CmdLineString  srcDir    = new CmdLineString("src", true, "源文件目录");
         CmdLineString  csharpDir = new CmdLineString("csharp", false, "生成C#文件的目录");
         CmdLineString  cppDir    = new CmdLineString("cpp", false, "生成C++文件的目录");
         c.RegisterParameter(srcDir);
         c.RegisterParameter(csharpDir);
         c.RegisterParameter(cppDir);
         c.Parse(args);
         bool bResult = ProtoPackage.Parse(srcDir.Value);
         if (bResult)
         {
             Gen(c);
         }
         return(bResult);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.InnerException.Message);
         //Console.WriteLine(ex.StackTrace);
         return(false);
     }
 }
Exemple #4
0
        static void Main(string[] args)
        {
            try
            {
                ConsoleCmdLine c         = new ConsoleCmdLine();
                CmdLineString  srcDir    = new CmdLineString("src", true, "源文件目录");
                CmdLineString  csharpDir = new CmdLineString("csharp", false, "生成C#文件的目录");
                CmdLineString  cppDir    = new CmdLineString("cpp", false, "生成C++文件的目录");
                CmdLineString  nameSpace = new CmdLineString("ns", false, "命名空间");
                c.RegisterParameter(srcDir);
                c.RegisterParameter(csharpDir);
                c.RegisterParameter(cppDir);
                c.RegisterParameter(nameSpace);
                c.Parse(args);
                ProtoResult result = Builder.BuildProto(srcDir);
                if (csharpDir.Exists)
                {
                    Builder.GenCSharpFile(result, CodeGenHelper.InputDirHandle(csharpDir), nameSpace);
                }
                if (cppDir.Exists)
                {
                    Builder.GenCppFile(result, CodeGenHelper.InputDirHandle(cppDir), nameSpace);
                }
            }
            catch (System.Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.ResetColor();

                Console.WriteLine("Please press any key to continue ... ");
                Console.ReadKey();
            }
        }
Exemple #5
0
        private static void Gen(ConsoleCmdLine cmd)
        {
            List <ICodeGen> list = new List <ICodeGen>();

            if (cmd["csharp"].Exists)
            {
                list.AddRange(CreadCSharpGen(cmd["src"].Value, cmd["csharp"].Value));
            }
            List <Task> tasks = new List <Task>();

            foreach (var gen in list)
            {
                Task task = Task.Factory.StartNew(() => GenCode(gen));
                tasks.Add(task);
            }
            Task.WaitAll(tasks.ToArray());
        }
Exemple #6
0
        static void Main(string[] args)
        {
            try
            {
                ConsoleCmdLine   ccl            = new ConsoleCmdLine();
                CmdLineString    outputFileName = new CmdLineString("output-file", false, "Output File Name - defaults to SeleniumJasmineResults.xml");
                CmdLineString    chromeBaseDir  = new CmdLineString("chrome-path", false, @"Path to ChromeDriver.exe - defaults to c:\selenium\chromedriver_win32_2.2");
                CmdLineString    ieBaseDir      = new CmdLineString("ie-path", false, @"Path to IEDriverServer.exe - defaults to c:\selenium\IEDriverServer_x86_2.34.0");
                CmdLineString    inputUrlList   = new CmdLineString("input-url-file", false, "Input file containing urls to test - defaults to SpecRunnerList.txt");
                CmdLineParameter runChrome      = new CmdLineParameter("chrome", false, "Run Selenium with the chrome driver");
                CmdLineParameter runIE          = new CmdLineParameter("ie", false, "Run Selenium with the ie driver");
                CmdLineParameter runFireFox     = new CmdLineParameter("firefox", false, "Run Selenium with the FireFox driver");

                CmdLineParameter timeout     = new CmdLineParameter("timeout", false, "Timeout value (seconds) to wait for the tests to finish. defaults to 90.");
                CmdLineParameter reporter    = new CmdLineParameter("reporter", false, "Reporter type : jenkins | teamcity.  Defaults to teamcity reporter ");
                CmdLineParameter resultInput = new CmdLineParameter("reporter-input", false, "Reporter type : trivialreporter | logreporter.  Use trivial reporter for jasmine < 2.0 , use logreporter otherwise. ");


                ccl.RegisterParameter(outputFileName);
                ccl.RegisterParameter(chromeBaseDir);
                ccl.RegisterParameter(ieBaseDir);
                ccl.RegisterParameter(inputUrlList);
                ccl.RegisterParameter(runChrome);
                ccl.RegisterParameter(runIE);
                ccl.RegisterParameter(runFireFox);
                ccl.RegisterParameter(timeout);
                ccl.RegisterParameter(reporter);
                ccl.RegisterParameter(resultInput);
                ccl.Parse(args);


                string strOutputFileName     = !string.IsNullOrEmpty(outputFileName.Value) ? outputFileName.Value : "SeleniumTestRunner.xml";
                string strChromeBaseDir      = !string.IsNullOrEmpty(chromeBaseDir.Value) ? chromeBaseDir.Value : @"E:\source\github\selenium-jasmine-runner\chromedriver_win32_2.2";
                string strIEBaseDir          = !string.IsNullOrEmpty(ieBaseDir.Value) ? ieBaseDir.Value : @"E:\source\github\selenium-jasmine-runner\IEDriverServer_x64_2.34.0";
                string strSpecRunnerListFile = !string.IsNullOrEmpty(inputUrlList.Value) ? inputUrlList.Value : "SpecRunnerList.txt";
                string strReporter           = !string.IsNullOrEmpty(reporter.Value) ? reporter.Value : "teamcity";

                string strInput = !string.IsNullOrEmpty(resultInput.Value) ? resultInput.Value : "logreporter";

                short timeoutValue = 90;
                if (!string.IsNullOrEmpty(timeout.Value))
                {
                    Int16.TryParse(timeout.Value, out timeoutValue);
                }

                TestSuites testSuites = new TestSuites(TestReporterFactory.GetTestReporter(strReporter));

                List <string> strFileList = new List <string> ();
                using (FileStream fs = new FileStream(strSpecRunnerListFile, FileMode.Open, FileAccess.Read))
                {
                    StreamReader streamReader = new StreamReader(fs);

                    string strLine = streamReader.ReadLine();

                    while (!string.IsNullOrEmpty(strLine))
                    {
                        strFileList.Add(strLine);
                        strLine = streamReader.ReadLine();
                    }
                }

                if (runFireFox.Exists)
                {
                    using (var firefoxDriver = new OpenQA.Selenium.Firefox.FirefoxDriver())
                    {
                        foreach (string strSpecRunner in strFileList)
                        {
                            string strPageName = strSpecRunner.Substring(strSpecRunner.LastIndexOf('/') + 1);
                            if (strPageName.IndexOf('.') > 0)
                            {
                                strPageName = strPageName.Substring(0, strPageName.IndexOf('.'));
                            }

                            if (strInput == "logreporter")
                            {
                                RunAllJasmineTestsAndReport_LogReporter(firefoxDriver, timeoutValue, strSpecRunner,
                                                                        strPageName,
                                                                        "Chrome", ref testSuites);
                            }
                            else
                            {
                                RunAllJasmineTestsAndReportTrivialReporter(firefoxDriver, timeoutValue, strSpecRunner,
                                                                           strPageName, "FireFox", ref testSuites);
                            }
                        }
                    }
                }

                if (runChrome.Exists)
                {
                    using (var driver = new OpenQA.Selenium.Chrome.ChromeDriver(strChromeBaseDir))
                    {
                        foreach (string strSpecRunner in strFileList)
                        {
                            string strPageName = strSpecRunner.Substring(strSpecRunner.LastIndexOf('/') + 1);
                            if (strPageName.IndexOf('.') > 0)
                            {
                                strPageName = strPageName.Substring(0, strPageName.IndexOf('.'));
                            }

                            if (strInput == "logreporter")
                            {
                                RunAllJasmineTestsAndReport_LogReporter(driver, timeoutValue, strSpecRunner, strPageName,
                                                                        "Chrome", ref testSuites);
                            }
                            else
                            {
                                RunAllJasmineTestsAndReportTrivialReporter(driver, timeoutValue, strSpecRunner,
                                                                           strPageName, "Chrome", ref testSuites);
                            }
                        }
                    }
                }

                if (runIE.Exists)
                {
                    InternetExplorerOptions options = new InternetExplorerOptions();
                    options.EnableNativeEvents = false;
                    options.EnsureCleanSession = true;

                    using (var driver = new OpenQA.Selenium.IE.InternetExplorerDriver(strIEBaseDir))

                    {
                        foreach (string strSpecRunner in strFileList)
                        {
                            string strPageName = strSpecRunner.Substring(strSpecRunner.LastIndexOf('/') + 1);
                            if (strPageName.IndexOf('.') > 0)
                            {
                                strPageName = strPageName.Substring(0, strPageName.IndexOf('.'));
                            }

                            if (strInput == "logreporter")
                            {
                                RunAllJasmineTestsAndReport_LogReporter(driver, timeoutValue, strSpecRunner, strPageName, "IE", ref testSuites);
                            }
                            else
                            {
                                RunAllJasmineTestsAndReportTrivialReporter(driver, timeoutValue, strSpecRunner, strPageName, "IE", ref testSuites);
                            }
                        }
                    }
                }



                Console.WriteLine("-----------");

                if (strInput != "logreporter")
                {
                    testSuites.WriteToConsole();

                    using (FileStream fs = new FileStream(strOutputFileName, FileMode.Create, FileAccess.Write))
                    {
                        StreamWriter streamWriter = new StreamWriter(fs);

                        testSuites.WriteToStream(streamWriter);

                        streamWriter.Flush();
                    }

                    using (StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()))
                    {
                        sw.AutoFlush = true;
                        testSuites.WriteToStream(sw);
                        sw.Flush();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("");
                Console.WriteLine("Unhandled Exception " + ex.ToString());
                Console.WriteLine("");
                Console.WriteLine(ex.ToString());
                throw ex;
            }
        }