Exemplo n.º 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);
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 4
0
        private static void Sub_Main(string[] orgArgs)
        {
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            Logger.logInfo("============================================================================");
            Logger.logInfo("LogExpert " + Assembly.GetExecutingAssembly().GetName().Version.Major + "." +
                           Assembly.GetExecutingAssembly().GetName().Version.Minor + "/" +
                           Assembly.GetExecutingAssembly().GetName().Version.Build.ToString() +
                           " started.");
            Logger.logInfo("============================================================================");

            CmdLine       cmdLine    = new CmdLine();
            CmdLineString configFile = new CmdLineString("config", false, "A configuration (settings) file");

            cmdLine.RegisterParameter(configFile);
            string[] remainingArgs = cmdLine.Parse(orgArgs);

            List <string> argsList = new List <string>();

            // This loop tries to convert relative file names into absolute file names (assuming that platform file names are given).
            // It tolerates errors, to give file system plugins (e.g. sftp) a change later.
            // TODO: possibly should be moved to LocalFileSystem plugin
            foreach (string fileArg in remainingArgs)
            {
                try
                {
                    FileInfo info = new FileInfo(fileArg);
                    if (info.Exists)
                    {
                        argsList.Add(info.FullName);
                    }
                    else
                    {
                        argsList.Add(fileArg);
                    }
                }
                catch (Exception)
                {
                    argsList.Add(fileArg);
                }
            }
            string[] args = argsList.ToArray();
            if (configFile.Exists)
            {
                FileInfo cfgFileInfo = new FileInfo(configFile.Value);
                if (cfgFileInfo.Exists)
                {
                    ConfigManager.Import(cfgFileInfo, ExportImportFlags.All);
                }
                else
                {
                    MessageBox.Show("Config file not found", "LogExpert");
                }
            }

            int pId = Process.GetCurrentProcess().SessionId;

            try
            {
                Settings settings  = ConfigManager.Settings;
                bool     isCreated = false;
                Mutex    mutex     = new System.Threading.Mutex(false, "Local\\LogExpertInstanceMutex" + pId, out isCreated);
                if (isCreated)
                {
                    // first application instance
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    LogTabWindow logWin = new LogTabWindow(args.Length > 0 ? args : null, 1, false);

                    // first instance
                    //WindowsIdentity wi = WindowsIdentity.GetCurrent();
                    IpcServerChannel ipcChannel = new IpcServerChannel("LogExpert" + pId);
                    ChannelServices.RegisterChannel(ipcChannel, false);
                    RemotingConfiguration.RegisterWellKnownServiceType(typeof(LogExpertProxy),
                                                                       "LogExpertProxy",
                                                                       WellKnownObjectMode.Singleton);
                    LogExpertProxy proxy = new LogExpertProxy(logWin);
                    RemotingServices.Marshal(proxy, "LogExpertProxy");

                    LogExpertApplicationContext context = new LogExpertApplicationContext(proxy, logWin);
                    Application.Run(context);

                    ChannelServices.UnregisterChannel(ipcChannel);
                }
                else
                {
                    int              counter    = 3;
                    string           errMsg     = "";
                    IpcClientChannel ipcChannel = new IpcClientChannel("LogExpertClient#" + pId, null);
                    ChannelServices.RegisterChannel(ipcChannel, false);
                    while (counter > 0)
                    {
                        try
                        {
                            // another instance already exists
                            //WindowsIdentity wi = WindowsIdentity.GetCurrent();
                            LogExpertProxy proxy = (LogExpertProxy)Activator.GetObject(typeof(LogExpertProxy),
                                                                                       "ipc://LogExpert" + pId + "/LogExpertProxy");
                            if (settings.preferences.allowOnlyOneInstance)
                            {
                                proxy.LoadFiles(args);
                            }
                            else
                            {
                                proxy.NewWindowOrLockedWindow(args);
                            }
                            break;
                        }
                        catch (RemotingException e)
                        {
                            Logger.logError("IpcClientChannel error: " + e.Message);
                            errMsg = e.Message;
                            counter--;
                            Thread.Sleep(500);
                        }
                    }
                    if (counter == 0)
                    {
                        Logger.logError("IpcClientChannel error, giving up: " + errMsg);
                        MessageBox.Show("Cannot open connection to first instance (" + errMsg + ")", "LogExpert");
                    }
                }
                mutex.Close();
            }
            catch (Exception ex)
            {
                Logger.logError("Mutex error, giving up: " + ex.Message);
                MessageBox.Show("Cannot open connection to first instance (" + ex.Message + ")", "LogExpert");
            }
        }
Exemplo n.º 5
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;
            }
        }