Exemple #1
0
    public static void Shutdown()
    {
        PlantUmlConnectionPool.Dispose();

        foreach (Process process in _processes)
        {
            try
            {
                process.StandardInput.WriteLine("\x3");
                process.StandardInput.Flush();

                Thread.Sleep(1);
                Debug.WriteLine(string.Format("Process {0} has exited: {1}", process.Id, process.HasExited));

                process.Kill();

                process.Dispose();
            }
            catch (Exception x)
            {
                Debug.WriteLine(x);
            }
        }
        _processes.Clear();
    }
Exemple #2
0
    public static byte[] Generate(string uploadFileName, string downloadFileName, string content)
    {
        var connection = PlantUmlConnectionPool.Get(TimeSpan.FromSeconds(15));

        if (connection == null)
        {
            throw new ApplicationException("Connection not found in pool.");
        }

        try
        {
            connection.Upload(uploadFileName, content);
            Thread.Sleep(100);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                connection.Download(downloadFileName, stream =>
                {
                    byte[] buffer = new byte[0x1000];
                    int bytesRead;
                    while ((bytesRead = stream.Read(buffer, 0, 0x1000)) > 0)
                    {
                        memoryStream.Write(buffer, 0, bytesRead);
                    }
                });
                connection.Delete(downloadFileName);
                connection.Delete(uploadFileName);
                return(memoryStream.ToArray());
            }
        }
        finally
        {
            PlantUmlConnectionPool.Put(connection);
        }
    }
Exemple #3
0
    public static void Startup()
    {
        if (_processes.Count > 0)
        {
            Shutdown();
        }

        var javaPath = ConfigurationManager.AppSettings["java"];

        if (!File.Exists(javaPath))
        {
            throw new ApplicationException("Java.exe not found: " + javaPath);
        }

        var host      = ConfigurationManager.AppSettings["plantuml.host"];
        var startPort = Convert.ToInt32(ConfigurationManager.AppSettings["plantuml.start_port"]);
        var instances = Convert.ToInt32(ConfigurationManager.AppSettings["plantuml.instances"]);

        var plantumlPath = ConfigurationManager.AppSettings["plantuml.path"];

        if (!File.Exists(plantumlPath))
        {
            throw new ApplicationException("plantuml.jar not found in " + plantumlPath);
        }

        for (int i = 0; i < instances; i++)
        {
            var argument           = "-jar " + plantumlPath + " -ftp:" + (startPort + i);
            ProcessStartInfo pInfo = new ProcessStartInfo(javaPath, argument);

            pInfo.CreateNoWindow         = true;
            pInfo.UseShellExecute        = false;
            pInfo.RedirectStandardInput  = true;
            pInfo.RedirectStandardError  = true;
            pInfo.RedirectStandardOutput = true;

            Process process = Process.Start(pInfo);
            Thread.Sleep(5000);
            _processes.Add(process);

            PlantUmlConnection connection = new PlantUmlConnection();
            connection.Connect(host, startPort + i);
            PlantUmlConnectionPool.Put(connection);
        }
    }