/// <summary> /// Show the ErrorForm /// </summary> /// <param name="message">A message to display</param> /// <param name="ex">The exception to display</param> /// <param name="parent">The parent control</param> public static void ShowError( string message, Exception ex, Control parent ) { if ( parent != null && parent.IsDisposed == false ) { using ( ErrorForm errorForm = new ErrorForm( message, ex ) ) { errorForm.StartPosition = FormStartPosition.CenterParent; errorForm.ShowDialog(parent); } } }
private void NamespaceSummariesForm_Activated(object sender, System.EventArgs e) { if (!scanInitiated) { scanInitiated=true; try { statusBar1.Text="Scanning assemblies for namespace names..."; namespaceComboBox.Enabled=false; summaryTextBox.Enabled=false; okButton.Enabled=false; cancelButton.Enabled=false; Application.DoEvents(); namespaceComboBox.Items.Clear(); _Project.Namespaces.LoadNamespacesFromAssemblies(_Project); foreach (string namespaceName in _Project.Namespaces.NamespaceNames) { namespaceComboBox.Items.Add(namespaceName); } if (namespaceComboBox.Items.Count>0) namespaceComboBox.SelectedIndex = 0; namespaceComboBox.Enabled=true; summaryTextBox.Enabled=true; okButton.Enabled=true; } catch(Exception docEx) { ErrorForm errorForm = new ErrorForm("Unable to complete namspace scan...", docEx); errorForm.ShowDialog(this); } finally { statusBar1.Text=""; cancelButton.Enabled=true; } } }
private void menuFileExportNamespaces_Click(object sender, System.EventArgs e) { SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.InitialDirectory = Directory.GetCurrentDirectory(); saveFileDlg.Filter = "NDoc Namespace Summary files (*.xml)|*.xml|All files (*.*)|*.*" ; if(saveFileDlg.ShowDialog() == DialogResult.OK) { StreamWriter streamWriter=null; try { streamWriter = new StreamWriter(saveFileDlg.FileName,false,new System.Text.UTF8Encoding(false)); XmlTextWriter writer = new XmlTextWriter(streamWriter); writer.Formatting=Formatting.Indented; writer.Indentation=4; project.Namespaces.Write(writer); writer.Close(); streamWriter.Close(); } catch(Exception ex) { if (streamWriter!=null) streamWriter.Close(); if ( !this.IsDisposed ) { ErrorForm errorForm = new ErrorForm(ex.Message, ex); errorForm.ShowDialog(this); } } } }
private void menuFileImportNamespaces_Click(object sender, System.EventArgs e) { OpenFileDialog openFileDlg = new OpenFileDialog(); openFileDlg.InitialDirectory = Directory.GetCurrentDirectory(); openFileDlg.Filter = "NDoc Namespace Summary files (*.xml)|*.xml|NDoc Project files (*.ndoc)|*.ndoc|All files (*.*)|*.*" ; if(openFileDlg.ShowDialog() == DialogResult.OK) { StreamReader streamReader=null; try { streamReader = new StreamReader(openFileDlg.FileName); XmlTextReader reader = new XmlTextReader(streamReader); reader.MoveToContent(); project.Namespaces.Read(reader); reader.Close(); streamReader.Close(); } catch(Exception ex) { if (streamReader!=null) streamReader.Close(); if ( !this.IsDisposed ) { ErrorForm errorForm = new ErrorForm(ex.Message, ex); errorForm.ShowDialog(this); } } } }
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"); } }
private void FileOpen(string fileName) { bool bFailed = true; try { string directoryName = Path.GetDirectoryName(fileName); Directory.SetCurrentDirectory(directoryName); try { project.Read(fileName); } catch (DocumenterPropertyFormatException e) { WarningForm warningForm = new WarningForm("Invalid Properties in Project File.", e.Message + "Documenter defaults will be used...."); warningForm.ShowDialog(this); } projectFilename = fileName; SetWindowTitle(); RefreshPropertyGrid(); // Update the ListView assembliesListView.Items.Clear(); foreach (AssemblySlashDoc assemblySlashDoc2 in project.AssemblySlashDocs) { AddRowToListView(assemblySlashDoc2); } UpdateMRUList(); EnableMenuItems(true); bFailed = false; } catch (DocumenterException docEx) { ErrorForm errorForm = new ErrorForm("Unable to read in project file", docEx); errorForm.ShowDialog(this); } catch (Exception ex) { string msg = "An error occured while trying to read in project file:\n" + fileName + "."; ErrorForm errorForm = new ErrorForm(msg, ex); errorForm.ShowDialog(this); } if (bFailed) { recentProjectFilenames.Remove(fileName); MakeMRUMenu(); Clear(); } }