static void OutputDiagram(IProject project, EntityDiagramType diagramType, DiagramScale scale, IEntity diagramEntity, string outputPath) { IStoredView view = diagramEntity.GetDefaultStoredView(diagramType, null); DiagramExporter diagramExporter = new DiagramExporter(view) { Background = Colors.White }; String diagramName = diagramEntity.Name.Replace(@":", "_").Replace(" ", "_") + @"_" + diagramType.ToString(); String diagramFilePath = String.Format("{0}diagrams/{1}.png", outputPath, diagramName); using (MemoryStream stream = new MemoryStream()) { diagramExporter.Export(stream); using (FileStream file = new FileStream(diagramFilePath, FileMode.Create, FileAccess.Write)) { stream.WriteTo(file); } } String diagramFigurePath = String.Format("{0}diagrams/{1}.tex", outputPath, diagramName); // Write Latex Figure Definition Header dataFile = new System.IO.StreamWriter(diagramFigurePath, false); dataFile.WriteLine(@"\begin{figure}"); dataFile.WriteLine(@" \centering"); switch (scale) { case DiagramScale.LineWidth: dataFile.WriteLine(@" \includegraphics[width=\linewidth]{mbse/diagrams/" + diagramName + @".png}"); break; case DiagramScale.ThreeQuarter: dataFile.WriteLine(@" \includegraphics[scale=.75]{mbse/diagrams/" + diagramName + @".png}"); break; } dataFile.WriteLine(@" \caption{" + project.Name + @": " + diagramEntity.Name.Replace(@"_", @" ") + @": " + diagramType.ToString() + @"}"); dataFile.WriteLine(@" \label{fig:" + diagramName + @"}"); dataFile.WriteLine(@"\end{figure}"); dataFile.Close(); }
public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; bool streamToOutput = !string.IsNullOrEmpty(Options.OutputFile) || Options.OutputOnStdOut; if (Options.NoGUI || Options.RequestHelp || streamToOutput) { //if(!Options.IsRunningOnMono) //{ // if (GetConsoleWindow() == IntPtr.Zero) // ; // AllocConsole(); //} if (Options.RequestHelp || string.IsNullOrEmpty(Options.InputFile) || !streamToOutput || Options.RootElements.Count == 0 || Options.ExpandLevel < 0 || Options.Zoom < 10.0 || Options.Zoom > 1000.0) { string version = typeof(Program).Assembly.GetName().Version.ToString(); Log(usage, version, Path.GetFileName(Environment.GetCommandLineArgs()[0])); return; } Log("Loading the file: {0}\n", Options.InputFile); Schema schema = new Schema(); schema.RequestCredential += delegate(string url, string realm, int attemptCount, out string username, out string password) { username = password = ""; if (!string.IsNullOrEmpty(Options.Username)) { if (attemptCount > 1) { return(false); } username = Options.Username; password = Options.Password; return(true); } return(false); }; schema.LoadSchema(Options.InputFile); if (schema.LoadError.Count > 0) { LogError("There are errors while loading:\n"); foreach (var error in schema.LoadError) { LogError(error); } LogError("\r\n"); } Diagram diagram = new Diagram(); diagram.ShowDocumentation = Options.ShowDocumentation; diagram.ElementsByName = schema.ElementsByName; diagram.Scale = Options.Zoom / 100.0f; foreach (var rootElement in Options.RootElements) { string elementName = rootElement; string elementNamespace = null; if (!string.IsNullOrEmpty(elementName)) { var pos = rootElement.IndexOf("@"); if (pos != -1) { elementName = rootElement.Substring(0, pos); elementNamespace = rootElement.Substring(pos + 1); } } foreach (var element in schema.Elements) { if ((elementNamespace != null && elementNamespace == element.NameSpace && element.Name == elementName) || (elementNamespace == null && element.Name == elementName)) { Log("Adding '{0}' element to the diagram...\n", rootElement); diagram.Add(element.Tag, element.NameSpace); } } } Form form = new Form(); Graphics graphics = form.CreateGraphics(); graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; for (int i = 0; i < Options.ExpandLevel; i++) { Log("Expanding to level {0}...\n", i + 1); diagram.ExpandOneLevel(); } diagram.Layout(graphics); Log("Saving image...\n"); try { bool result = false; DiagramExporter exporter = new DiagramExporter(diagram); IDictionary <string, object> specificRendererParameters = new Dictionary <string, object>() { { "TextOutputFields", Options.TextOutputFields }, { "DisplayAttributes", Options.DisplayAttributes }, { "Schema", schema } //For future parameters, {} }; if (Options.OutputOnStdOut) { Stream stream = Console.OpenStandardOutput(); result = exporter.Export(stream, "." + Options.OutputOnStdOutExtension.ToLower(), graphics, new DiagramAlertHandler(ByPassSaveAlert), specificRendererParameters); stream.Flush(); } else { result = exporter.Export(Options.OutputFile, graphics, new DiagramAlertHandler(SaveAlert), specificRendererParameters); } if (result) { Log("The diagram is now saved in the file: {0}\n", Options.OutputFile); } else { Log("ERROR: The diagram has not been saved!\n"); } } catch (Exception ex) { Log("ERROR: The diagram has not been saved. {0}\n", ex.Message); } graphics.Dispose(); form.Dispose(); } else { if (Options.RequestHelp) { string version = typeof(Program).Assembly.GetName().Version.ToString(); MessageBox.Show(string.Format(usage, version, Environment.GetCommandLineArgs()[0])); } Application.ThreadException += HandleThreadException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } }