コード例 #1
0
ファイル: Tester.cs プロジェクト: guusbeckett/ForGen
        static public void generateAutomataImage(Automata <String> automata, string output_file = "", string fileformat = "svg")
        {
            string executable_file = "";
            string file_opener     = "";
            bool   no_open         = false;

            if (output_file != "")
            {
                no_open = true;
            }
            bool windows = false;
            int  p       = (int)Environment.OSVersion.Platform;

            if ((p == 4) || (p == 6) || (p == 128))               //UNIX
            {
                if (output_file == "")
                {
                    if (InputOutput.IsRunningOnMac())
                    {
                        output_file = Path.GetTempPath() + "generatedAutomata." + fileformat;
                    }
                    else
                    {
                        output_file = "/tmp/tmp." + fileformat;
                    }
                }
                executable_file = "dot";
                if (InputOutput.IsRunningOnMac())
                {
                    file_opener = "open";
                }
                else
                {
                    file_opener = "xdg-open";
                }
            }
            else
            {
                windows = true;
                if (output_file == "")
                {
                    output_file = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    output_file = output_file + "\\img." + fileformat;
                }
                executable_file = "C:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe";
            }

            string dotinfo = automata.printGraphviz();

            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow        = false;
                startInfo.UseShellExecute       = false;
                startInfo.FileName              = executable_file;
                startInfo.RedirectStandardInput = true;
                startInfo.WindowStyle           = ProcessWindowStyle.Hidden;
                startInfo.Arguments             = "  -T" + fileformat + " -o " + output_file;

                Process exeProcess = new Process();
                exeProcess.StartInfo = startInfo;
                exeProcess.Start();
                //exeProcess.WaitForInputIdle();
                StreamWriter writer = exeProcess.StandardInput;
                writer.Write(dotinfo);
                writer.Flush();
                writer.WriteLine();
                if (!windows)
                {
                    exeProcess.WaitForInputIdle();
                }
                writer.Close();
                exeProcess.WaitForExit();
                if (!no_open)
                {
                    if (!windows)
                    {
                        Process openProcess = new Process();
                        openProcess.StartInfo.FileName  = file_opener;
                        openProcess.StartInfo.Arguments = output_file;
                        openProcess.Start();
                    }
                    else
                    {
                        Process.Start(output_file);
                    }
                }
            }
            catch
            {
                Console.Write("Random exception");
            }
        }
コード例 #2
0
        private void buildAndOpenLaTeXPDF(String latexLocation)
        {
            int p = (int)Environment.OSVersion.Platform;

            if (!((p == 4) || (p == 6) || (p == 128)))             // If you're using Windows I feel bad for you son, I support 99 OS's and windows ain't one ( ͡° ͜ʖ ͡°)
            {
                return;
            }
            string file_opener = "";
            string executable  = "pdflatex";

            if (InputOutput.IsRunningOnMac())
            {
                file_opener = "open";
            }
            else
            {
                file_opener = "xdg-open";
            }
            bool no_open = false;

            if (latexLocation == "")
            {
                no_open = true;
            }
            bool windows = false;


            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow        = false;
                startInfo.UseShellExecute       = false;
                startInfo.FileName              = executable;
                startInfo.RedirectStandardInput = true;
                startInfo.WorkingDirectory      = latexLocation;
                startInfo.WindowStyle           = ProcessWindowStyle.Hidden;
                //				startInfo.Arguments = "proeftentamen.tex";

                Process exeProcess = new Process();
                exeProcess.StartInfo = startInfo;
                exeProcess.Start();
                //exeProcess.WaitForInputIdle();
                StreamWriter writer = exeProcess.StandardInput;
                writer.Write("proeftentamen.tex");
                writer.Flush();
                writer.WriteLine();
                if (!windows)
                {
                    exeProcess.WaitForInputIdle();
                }
                writer.Close();
                exeProcess.WaitForExit();
                if (!no_open)
                {
                    Process openProcess = new Process();
                    openProcess.StartInfo.FileName = file_opener;
                    Console.WriteLine(latexLocation + "proeftentamen.pdf");
                    openProcess.StartInfo.Arguments = latexLocation + "proeftentamen.pdf";
                    openProcess.Start();
                }
            }
            catch
            {
                Console.Write("Random exception");
            }
        }