Пример #1
0
		public static int Main(string[] args)
		{
			try
			{
				WriteLogoBanner();

				project = new Project();
				IDocumenterInfo info = InstalledDocumenters.GetDocumenter("MSDN");
				if (info == null)
				{
					//MSDN documenterConfig not found, pick the first one available.
					if (InstalledDocumenters.Documenters.Count > 0)
					{
						info = (IDocumenterInfo)InstalledDocumenters.Documenters[0];
					}
					else
					{
						throw new ApplicationException("Could not find any documenter assemblies.");
					}
				}
				project.ActiveDocumenter = info;
				documenterConfig = project.ActiveConfig;

				int maxDepth = 20; //to limit recursion depth
				bool propertiesSet = false;
				bool projectSet = false;

				if (args.Length==0)
				{
					WriteUsage();
					return 1;
				}

				if (args[0].ToLower().StartsWith("-help"))
				{
					WriteHelp(args);
					return 1;
				}

				foreach (string arg in args)
				{
					if (arg.StartsWith("-"))
					{
						if (string.Compare(arg, "-verbose", true) == 0)
						{
							Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
						}
						else
						{
							string[] pair = arg.Split('=');

							if (pair.Length == 2)
							{
								string name = pair[0].Substring(1);
								string val = pair[1];

								switch (name.ToLower())
								{
									case "documenter":
										if (propertiesSet)
										{
											throw new ApplicationException("The documenter name must be specified before any documenter specific options.");
										}
										if (projectSet)
										{
											throw new ApplicationException("The documenter name must be specified before the project file.");
										}
										info = InstalledDocumenters.GetDocumenter(val.Replace("_"," "));

										if (info == null)
										{
											throw new ApplicationException("The specified documenter name is invalid.");
										}
										project.ActiveDocumenter = info;
										documenterConfig = project.ActiveConfig;
										break;
									case "project":
										if (propertiesSet)
										{
											throw new ApplicationException("The project file must be specified before any documenter specific options.");
										}
										Console.WriteLine("using project file " + val);
										project.Read(val);
										project.ActiveDocumenter = info;
										documenterConfig = project.ActiveConfig;
										projectSet = true;
										Directory.SetCurrentDirectory(Path.GetDirectoryName(val));
										Debug.WriteLine(Directory.GetCurrentDirectory());
										break;
									case "recurse":
										string[] recPair = val.Split(',');
										if (2 == recPair.Length)
										{
											maxDepth = Convert.ToInt32(recPair[1]);
										}
										RecurseDir(recPair[0], maxDepth);
										break;
									case "namespacesummaries":
										using(StreamReader streamReader = new StreamReader(val))
										{
											XmlTextReader reader = new XmlTextReader(streamReader);
											reader.MoveToContent();
											project.Namespaces.Read(reader);
											reader.Close();
											streamReader.Close();
										}
										break;
									case "referencepath":
										project.ReferencePaths.Add(new ReferencePath(val));
										break;
									default:
										documenterConfig.SetValue(name, val);
										propertiesSet = true;
										break;
								}
							}
						}
					}
					else if (arg.IndexOf(',') != -1)
					{
						string[] pair = arg.Split(',');

						if (pair.Length == 2)
						{
							project.AssemblySlashDocs.Add(
								new AssemblySlashDoc(pair[0], pair[1]));
						}
					}
					else
					{
						string doc = Path.ChangeExtension(arg, ".xml");
						if (File.Exists(doc))
						{
							project.AssemblySlashDocs.Add(
								new AssemblySlashDoc(arg, doc));
						}
						else
						{
							project.AssemblySlashDocs.Add(
								new AssemblySlashDoc(arg, ""));
						}
					}
				}

				if (project.AssemblySlashDocs.Count == 0)
				{
					Console.WriteLine("[Error] Build cannot proceed; No assemblies were specified, or none could be found.");
					//WriteUsage();
					return 1;
				}
				else
				{
					startDateTime = DateTime.UtcNow;
					IDocumenter documenter = documenterConfig.CreateDocumenter();
					documenter.DocBuildingStep += new DocBuildingEventHandler(DocBuildingStepHandler);
					documenter.Build(project);
					TimeSpan ts = DateTime.UtcNow - startDateTime;
					Console.WriteLine(String.Format("Total build time {0:f1} s", ts.TotalSeconds));
					return 0;
				}

			}
			catch( Exception except )
			{
				string errorText= BuildExceptionText(except);
				Console.WriteLine(errorText);
				System.Diagnostics.Trace.WriteLine(errorText);
				return 2;
			}
		}