private void menuDocBuildItem_Click(object sender, System.EventArgs e) { IDocumenter documenter = (IDocumenter)project.Documenters[comboBoxDocumenters.SelectedIndex]; //make sure the current directory is the project directory if (projectFilename != untitledProjectName) { Directory.SetCurrentDirectory(Path.GetDirectoryName(projectFilename)); } string message = documenter.CanBuild(project); if (message != null) { MessageBox.Show( this, message, "NDoc", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } documenter.DocBuildingStep += new DocBuildingEventHandler(OnStepUpdate); if (!Directory.Exists(Path.GetDirectoryName(documenter.MainOutputFile))) Directory.CreateDirectory(Path.GetDirectoryName(documenter.MainOutputFile)); string logPath = Path.Combine(Path.GetDirectoryName(documenter.MainOutputFile),"ndoc.log"); using(StreamWriter logWriter = new StreamWriter(logPath,false,new System.Text.UTF8Encoding(false))) { Trace.Listeners.Add(new TextWriterTraceListener(logWriter,"ndoc")); BuildWorker buildWorker = new BuildWorker(documenter, project); buildThread = new Thread(new ThreadStart(buildWorker.ThreadProc)); buildThread.Name = "Build"; buildThread.IsBackground = true; buildThread.Priority = ThreadPriority.BelowNormal; ConfigureUIForBuild(true); try { this.Cursor = Cursors.AppStarting; UpdateProgress("Building documentation...", 0); buildThread.Start(); // Wait for thread to start while (!buildThread.IsAlive); // Now wait for thread to complete while (!buildWorker.IsComplete && buildThread.IsAlive) { // Keep GUI responsive Application.DoEvents(); // Don't chew up all CPU cycles Thread.Sleep(100); } // Wait a little for the thread to die buildThread.Join(200); } finally { // disconnect from the documenter's events documenter.DocBuildingStep -= new DocBuildingEventHandler(OnStepUpdate); // keep us from accessing parts of the window when it is closed while a build is in progress if ( !this.IsDisposed ) { // Just in case some weird exception happens, we don't get stuck // with a busy cursor. this.Cursor = Cursors.Default; ConfigureUIForBuild(false); statusBarTextPanel.Text = "Ready"; if ( !this.traceWindow1.IsDisposed && this.traceWindow1.Visible ) this.traceWindow1.Disconnect(); } } Exception ex = buildWorker.Exception; if (ex != null) { //check if thread has been aborted Exception iex = ex; Exception innermostException; do { if (iex is ThreadAbortException) { // disconnect from the trace listener Trace.Listeners.Remove("ndoc"); return; } innermostException = iex; iex = iex.InnerException; } while (iex != null); // Process exception string msg = "An error occured while trying to build the documentation."; Trace.WriteLine(msg); Trace.WriteLine(""); BuildTraceError(ex); // we do not want to show any dialogs if the app is shutting down if ( !this.IsDisposed && innermostException is DocumenterException ) { ErrorForm errorForm = new ErrorForm(msg, ex /*innermostException*/); errorForm.Text = "NDoc Documenter Error"; errorForm.ShowDialog(this); } else if ( !this.IsDisposed ) { ErrorForm errorForm = new ErrorForm(msg, ex/*innermostException*/); errorForm.ShowDialog(this); } } // disconnect from the trace listener Trace.Listeners.Remove("ndoc"); } }
/// <summary> /// See <see cref="UserControl.OnLoad"/> /// </summary> /// <param name="e">event arguments</param> protected override void OnLoad(EventArgs e) { project = new Project(); project.Modified += new ProjectModifiedEventHandler(OnProjectModified); project.ActiveConfigChanged += new EventHandler(project_ActiveConfigChanged); project.AssemblySlashDocs.Cleared += new EventHandler(AssemblySlashDocs_Cleared); project.AssemblySlashDocs.ItemAdded += new AssemblySlashDocEventHandler(AssemblySlashDocs_ItemRemovedAdded); project.AssemblySlashDocs.ItemRemoved += new AssemblySlashDocEventHandler(AssemblySlashDocs_ItemRemovedAdded); assemblyListControl.AssemblySlashDocs = project.AssemblySlashDocs; foreach ( IDocumenterInfo documenter in InstalledDocumenters.Documenters ) comboBoxDocumenters.Items.Add( documenter ); options = new NDocOptions(); ReadConfig(); Clear(); // If a project document wasn't passed in on the command line // then try loading up the most recently used project file. if ( startingProjectFilename == null ) { if ( this.options.LoadLastProjectOnStart ) { while ( recentProjectFilenames.Count > 0 ) { if ( File.Exists( recentProjectFilenames[0] ) ) { FileOpen( recentProjectFilenames[0] ); break; } else { //the project file was not found, remove it from the MRU recentProjectFilenames.RemoveAt(0); } } } } else { //load project passed on the command line if ( File.Exists( startingProjectFilename ) ) { FileOpen( startingProjectFilename ); } else { MessageBox.Show( this, "The NDoc project file '" + startingProjectFilename + "' does not exist.", "Error loading NDoc project file", MessageBoxButtons.OK, MessageBoxIcon.Stop ); } } EnableAssemblyItems(); MakeMRUMenu(); SetWindowTitle(); this.traceWindow1.TraceText = string.Format( "[NDoc version {0}]\n", Assembly.GetExecutingAssembly().GetName().Version ); m_buildWorker = new BuildWorker( this ); base.OnLoad (e); }