Ejemplo n.º 1
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);
        }
    }
Ejemplo n.º 2
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);
        }
    }