private bool ImportAssembly(string fileName, ClassDiagram diagram, ImportSettings settings) { if (string.IsNullOrEmpty(fileName)) { MessageBox.Show(Strings.Error_NoAssembly, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } try { NETImport importer = new NETImport(diagram, settings); return(importer.ImportAssembly(fileName)); } catch (UnsafeTypesPresentException) { MessageBox.Show(null, Strings.UnsafeTypesPresent, Strings.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(true); } catch (ReflectionTypeLoadException) { MessageBox.Show(Strings.Error_MissingReferencedAssemblies, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (FileLoadException) { MessageBox.Show(Strings.Error_MissingReferencedAssemblies, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (BadImageFormatException) { MessageBox.Show(Strings.Error_BadImageFormat, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (Exception ex) { DetailsErrorDialog.Show(Strings.Error_MessageBoxTitle, Strings.Error_GeneralException, ex.ToString(), MessageBoxIcon.Error); return(false); } }
// ======================================================================== // Methods #region === Methods /// <summary> /// Starts the functionality of the plugin. /// </summary> protected void Launch() { if (!DocumentManager.HasDocument) { return; } string fileName; using (SaveFileDialog dialog = new SaveFileDialog()) { dialog.Filter = Strings.SaveDialogFilter; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.Cancel) { return; } fileName = dialog.FileName; } PDFExportOptions optionsForm = new PDFExportOptions(); if (optionsForm.ShowDialog() == DialogResult.Cancel) { return; } Padding padding = new Padding((int)new XUnit(optionsForm.PDFPadding.Left, optionsForm.Unit).Point, (int)new XUnit(optionsForm.PDFPadding.Top, optionsForm.Unit).Point, (int)new XUnit(optionsForm.PDFPadding.Right, optionsForm.Unit).Point, (int)new XUnit(optionsForm.PDFPadding.Bottom, optionsForm.Unit).Point); MainForm mainForm = Application.OpenForms.OfType <MainForm>().FirstOrDefault(); var g = mainForm.CreateGraphics(); PDFExportProgress.ShowAsync(mainForm); PDFExporter exporter = new PDFExporter(fileName, DocumentManager.ActiveDocument, optionsForm.SelectedOnly, padding); Application.DoEvents(); try { exporter.Export(g); // Running the exporter within an extra thread isn't a good idea since // the exporter uses GDI+. NClass uses GDI+ also if it has to redraw the // diagram. GDI+ can't be used by two threads at the same time. //Thread exportThread = new Thread(exporter.Export) // { // Name = "PDFExporterThread", // IsBackground = true // }; //exportThread.Start(); //while (exportThread.IsAlive) //{ // Application.DoEvents(); // exportThread.Join(5); //} //exportThread.Join(); PDFExportProgress.CloseAsync(); } catch (Exception e) { PDFExportProgress.CloseAsync(); DetailsErrorDialog.Show("Error", $"Export failed: {e.Message}", e.StackTrace, MessageBoxIcon.Error, true); } if (!exporter.Successful) { return; } if (new PDFExportFinished().ShowDialog(mainForm) == DialogResult.OK) { try { if (MonoHelper.IsRunningOnMono) { Process.Start("xdg-open", fileName); } else { Process.Start(fileName); } } catch (Exception e) { DetailsErrorDialog.Show("PDF Export", e.Message, e.StackTrace, MessageBoxIcon.Error, true); } } }