Beispiel #1
0
        static private void ShowBenchmarksAndBuildCSV(Engine.Path csvPath)
        {
            System.Console.Write(executionTimer.BuildStatistics());

            bool csvFileExisted = System.IO.File.Exists(csvPath);

            System.IO.StreamWriter csvFile = null;

            try
            {
                csvFile = new System.IO.StreamWriter(csvPath, true, System.Text.Encoding.UTF8);

                if (!csvFileExisted)
                {
                    csvFile.Write("\"Date\",\"Threads Used\",\"Cores Available\",\"File Changes\",");
                    csvFile.Write(executionTimer.BuildCSVHeadings());
                    csvFile.WriteLine();
                }

                csvFile.Write(
                    string.Format("\"{0:yyyy-MM-dd HH:mm:ss}\"", DateTime.Now)
                    );

                csvFile.Write(',');
                csvFile.Write(workerThreadCount);
                csvFile.Write(',');
                csvFile.Write(System.Environment.ProcessorCount);
                csvFile.Write(',');
                csvFile.Write(totalFileChanges);
                csvFile.Write(',');
                csvFile.Write(executionTimer.BuildCSVValues());
                csvFile.WriteLine();

                Console.WriteLine();
                System.Console.WriteLine(
                    Engine.Locale.Get("NaturalDocs.CLI", "Status.BenchmarksSavedIn(file)", csvPath)
                    );
            }
            catch (Exception e)
            {
                Console.WriteLine();
                System.Console.WriteLine(
                    Engine.Locale.Get("NaturalDocs.CLI", "Status.CouldNotSaveBenchmarksIn(file)", csvPath)
                    );
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (csvFile != null)
                {
                    csvFile.Dispose();
                    csvFile = null;
                }
            }
        }
Beispiel #2
0
		// Group: Primary Execution Paths
		// __________________________________________________________________________


		/* Function: Main
		 * The program entry point.
		 */
		public static void Main (string[] commandLine)
			{
			executionTimer = new ExecutionTimer();
			executionTimer.Start("Total Execution");

			engineInstance = null;

			quiet = false;
			workerThreadCount = DefaultWorkerThreadCount;
			totalFileChanges = 0;
			benchmark = false;
			pauseOnError = false;
			pauseBeforeExit = false;
			
			bool gracefulExit = false;

			var standardOutput = System.Console.Out;

			try
				{
				engineInstance = new NaturalDocs.Engine.Instance();
				
				ErrorList startupErrors = new ErrorList();
				ParseCommandLineResult parseCommandLineResult = ParseCommandLine(commandLine, out commandLineConfig, startupErrors);

				
				if (parseCommandLineResult == ParseCommandLineResult.Error)
					{
					HandleErrorList(startupErrors);
					}

				else if (parseCommandLineResult == ParseCommandLineResult.ShowCommandLineReference)
					{
					ShowCommandLineReference();
					gracefulExit = true;
					}

				else if (parseCommandLineResult == ParseCommandLineResult.ShowVersion)
					{
					ShowVersion();
					gracefulExit = true;
					}

				else // (parseCommandLineResult == ParseCommandLineResult.Run)
					{
					if (quiet)
						{  
						// This is easier and less error prone than putting conditional statements around all the non-error console
						// output, even if it's less efficient.
						System.Console.SetOut(System.IO.TextWriter.Null);
						}


					// Create project configuration files only

					if (commandLineConfig.ProjectConfigFolderPropertyLocation.IsDefined &&
						commandLineConfig.InputTargets.Count == 0 &&
						commandLineConfig.OutputTargets.Count == 0 &&
						!System.IO.File.Exists(commandLineConfig.ProjectConfigFolder + "/Project.txt"))
						{
						if (CreateProjectConfiguration(startupErrors))
							{  gracefulExit = true;  }
						else
							{  HandleErrorList(startupErrors);  }
						}


					// Normal execution

					else
						{
						if (BuildDocumentation(startupErrors))
							{  gracefulExit = true;  }
						else
							{  HandleErrorList(startupErrors);  }
						}
					}
				}

			catch (Exception e)
				{  
				HandleException(e);  
				}
				
			finally
				{
				Engine.Path projectFolder = engineInstance.Config.ProjectConfigFolder;

				engineInstance.Dispose(gracefulExit);
				engineInstance = null;

				executionTimer.End("Total Execution");

				if (benchmark)
					{  ShowBenchmarksAndBuildCSV(projectFolder + "/Benchmarks.csv");  } 

				// Restore the standard output.  We do this before "Press any key to continue" because we never want that to
				// be hidden.
				if (quiet)
					{  System.Console.SetOut(standardOutput);  }
				}
				
			if (pauseBeforeExit || (pauseOnError && !gracefulExit))
				{
				System.Console.WriteLine();
				System.Console.WriteLine(
					Engine.Locale.SafeGet("NaturalDocs.CLI", "Status.PressAnyKeyToContinue", "Press any key to continue...")
					);
				System.Console.ReadKey(true);
				}
			}
Beispiel #3
0
        /* Function: HandleException
         */
        static private void HandleException(Exception e)
        {
            var errorOutput = Console.Error;

            errorOutput.Write("\n\n------------------------------------------------------------\n");
            errorOutput.WriteLine(Locale.SafeGet("NaturalDocs.CLI", "Crash.Exception",
                                                 "Natural Docs has closed because of the following error:"));
            errorOutput.WriteLine();
            errorOutput.WriteLine(e.Message);


            // If it's not a user friendly exception or a thread exception wrapping a user friendly exception...
            if (e.GetType() != typeof(Engine.Exceptions.UserFriendly) &&
                (e.GetType() == typeof(Engine.Exceptions.Thread) &&
                 e.InnerException.GetType() == typeof(Engine.Exceptions.UserFriendly)) == false)
            {
                Engine.Path crashFile = EngineInstance.BuildCrashReport(e);

                if (crashFile != null)
                {
                    errorOutput.WriteLine();
                    errorOutput.Write(Locale.SafeGet("NaturalDocs.CLI", "Crash.ReportAt(file).multiline",
                                                     "A crash report has been generated at {0}.\n" +
                                                     "Please include this file when asking for help at naturaldocs.org.\n", crashFile));
                }

                else
                {
                    errorOutput.WriteLine();
                    errorOutput.WriteLine(e.StackTrace);

                    // If it's a thread exception, skip the first inner one because that's the wrapped one, which we already got the
                    // message for.
                    if (e is Engine.Exceptions.Thread)
                    {
                        e = e.InnerException;
                    }

                    while (e.InnerException != null)
                    {
                        e = e.InnerException;

                        errorOutput.WriteLine();
                        errorOutput.WriteLine(Locale.SafeGet("NaturalDocs.CLI", "Crash.NestedException",
                                                             "This error was caused by the following error:") + "\n");

                        errorOutput.WriteLine(e.Message);
                    }

                    try
                    {
                        errorOutput.WriteLine();
                        errorOutput.WriteLine(Locale.SafeGet("NaturalDocs.CLI", "Crash.Version", "Version") +
                                              ": " + Engine.Instance.VersionString);
                        errorOutput.WriteLine(Locale.SafeGet("NaturalDocs.CLI", "Crash.Platform", "Platform") +
                                              ": " + Environment.OSVersion.VersionString +
                                              " (" + Environment.OSVersion.Platform + ")");
                        errorOutput.WriteLine("SQLite: " + Engine.SQLite.API.LibVersion());
                        errorOutput.WriteLine();
                        errorOutput.WriteLine(Locale.SafeGet("NaturalDocs.CLI", "Crash.CommandLine", "Command Line") + ":");
                        errorOutput.WriteLine();
                        errorOutput.WriteLine("   " + Environment.CommandLine);
                    }
                    catch
                    {
                    }

                    errorOutput.WriteLine();
                    errorOutput.WriteLine(Locale.SafeGet("NaturalDocs.CLI", "Crash.IncludeInfoAndGetHelp",
                                                         "Please include this information when asking for help at naturaldocs.org."));
                }
            }

            errorOutput.Write("\n------------------------------------------------------------\n\n");
        }