コード例 #1
0
        private static void X3DTrans(string copyTo)
        {
            string basePath = AppContext.BaseDirectory.Replace("\\", "/");

            string binaryToolsPath    = PathHelper.GetToolsPath();
            string userProcessingPath = PathHelper.GetUserProcessingFolder();

            string command = "cd \"" + userProcessingPath + "\" & \"" + binaryToolsPath + "/PublishEngineExecute.exe\" \"" + userProcessingPath + "/input\" \"" + userProcessingPath + "/input/resourceFolder\" -p XmlCompass -f";

            ProcessStartInfo processInfo;
            Action           onFinish = () =>
            {
                string   pathToFile = "";
                string[] files      = Directory.GetFiles(Path.Combine(userProcessingPath, "input/resourceFolder"));

                foreach (string fileName in files)
                {
                    if (fileName.ToLower().Contains("x3d") || fileName.ToLower().Contains("zip") || fileName.ToLower().Contains("rar"))
                    {
                        string copyFile = Path.Combine(copyTo.Replace(Path.GetFileName(copyTo), ""), Path.GetFileName(fileName));
                        File.Copy(fileName, copyFile, true);
                        string repoPath = Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder());
                        SVNManager.AddFile(copyFile.Replace(repoPath + "/", ""));
                        pathToFile = copyFile;
                        if (fileName.ToLower().Contains("x3d"))
                        {
                            _logger.LogInformation($"Processing X3D file: '{fileName}'");

                            DirectoryInfo    dInfo      = new DirectoryInfo(binaryToolsPath);
                            string           newDPath   = dInfo.FullName.Replace("\\", "/");
                            string           x3dCommand = "cd \"" + PathHelper.GetUserProcessingFolder() + "\" & \"" + newDPath + "/remgeom.bat\" \"" + copyFile + "\" \"" + newDPath + "\"";
                            ProcessStartInfo processBat = new ProcessStartInfo("cmd.exe", "/C " + x3dCommand);

                            processBat.CreateNoWindow         = true;
                            processBat.UseShellExecute        = false;
                            processBat.RedirectStandardOutput = true;
                            processBat.RedirectStandardError  = true;
                            processBat.WorkingDirectory       = newDPath;

                            var    processB = Process.Start(processBat);
                            string outputt  = processB.StandardOutput.ReadToEnd();
                            string errors   = processB.StandardError.ReadToEnd();

                            if (!string.IsNullOrEmpty(errors))
                            {
                                _logger.LogError($"Error while performing X3D transformation: '{errors}' Command: {x3dCommand}");
                            }

                            processB.WaitForExit();
                        }
                    }
                }

                foreach (string s in Directory.GetFiles(Path.Combine(userProcessingPath, "input")))
                {
                    if (s.ToLower().Contains(".xml"))
                    {
                        string ditaText = File.ReadAllText(s);

                        File.WriteAllText(s, ditaText);
                        File.Copy(s, CopyTo, true);
                    }
                }

                OnFinishDrafting();

                onResultAction("");
            };

            processInfo = new ProcessStartInfo("cmd.exe", "/C " + command);
            processInfo.CreateNoWindow         = true;
            processInfo.UseShellExecute        = false;
            processInfo.RedirectStandardOutput = true;
            processInfo.RedirectStandardError  = true;

            var    process = Process.Start(processInfo);
            string output  = process.StandardOutput.ReadToEnd();
            string errorss = process.StandardError.ReadToEnd();

            if (!string.IsNullOrEmpty(errorss))
            {
                _logger.LogError($"Error '{errorss}' while executing command: {command} ");
            }

            process.WaitForExit();

            command = "cd \"" + userProcessingPath + "\" & \"" + binaryToolsPath + "/PublishEngineExecute.exe\" \"" + userProcessingPath + "/input\" \"" + userProcessingPath + "/input/resourceFolder\" -p Cortona –f";

            processInfo = new ProcessStartInfo("cmd.exe", "/C " + command);
            processInfo.CreateNoWindow         = false;
            processInfo.UseShellExecute        = false;
            processInfo.RedirectStandardOutput = true;
            processInfo.RedirectStandardError  = true;

            process = Process.Start(processInfo);
            output  = process.StandardOutput.ReadToEnd();
            errorss = process.StandardError.ReadToEnd();
            if (!string.IsNullOrEmpty(errorss))
            {
                _logger.LogError($"Error '{errorss}' while executing command: {command} ");
            }

            process.WaitForExit();
            onFinish();
        }
コード例 #2
0
        private static void XSLTTransformation(string fromFolder, string copyTo)
        {
            string        path = PathHelper.GetUserProcessingFolder();
            DirectoryInfo dir  = new DirectoryInfo(path);

            path = dir.FullName.Replace("\\", "/");
            string aPath = Path.Combine(path, "xslt/a.xml").Replace("\\", "/");

            if (!Directory.Exists(Path.GetDirectoryName(aPath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(aPath));
            }

            File.Copy(fromFolder, Path.Combine(path, "xslt/a.xml"), true);
            File.Copy(Path.Combine(path, "xslt/a.xml"), Path.Combine(path, "input/1_1.xml"), true);
            string command = "";

            var xsltConfigFileName = Path.Combine(path, "xslt.config");

            if (!File.Exists(xsltConfigFileName))
            {
                File.WriteAllText(xsltConfigFileName, JsonConvert.SerializeObject(new XsltConfigModel {
                    port = 9000, ticket = "ytrewq654321", url = "http://127.0.0.1"
                }));
            }

            string configContent = File.ReadAllText(xsltConfigFileName);

            var xspConfigFilePath = Path.Combine(path, "xsp.config");

            if (!File.Exists(xspConfigFilePath))
            {
                File.WriteAllText(xspConfigFilePath, JsonConvert.SerializeObject(new XSPConfigModel {
                    port = 0
                }));
            }
            string          xspContent = File.ReadAllText(Path.Combine(path, "xsp.config"));
            XsltConfigModel config     = JsonConvert.DeserializeObject <XsltConfigModel>(configContent);
            XsltConfigModel xspConfig  = JsonConvert.DeserializeObject <XsltConfigModel>(xspContent);
            string          fileNameWithoutExtension = Path.GetFileNameWithoutExtension(copyTo.Replace("\\", "/"));
            string          parameters = "id=" + fileNameWithoutExtension + " server_host={SERVER}:{PORT} ticket=" + config.ticket;

            CopyTo = copyTo;
            Action onFinish = () =>
            {
                foreach (string s in Directory.GetFiles(path))
                {
                    if (s.ToLower().Contains("b.xml"))
                    {
                        string textToReplace = File.ReadAllText(s);
                        while (textToReplace.Contains("res://res://"))
                        {
                            textToReplace = textToReplace.Replace("res://res://", "res://");
                        }
                        textToReplace = textToReplace.Replace("/document", "/viewer/document");
                        textToReplace = textToReplace.Replace(config.ticket, "{TICKET}");
                        File.WriteAllText(copyTo, textToReplace);
                        File.Copy(copyTo, Path.Combine(path, "input/1_1.xml"), true);
                        string repoPath = Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder());
                        SVNManager.AddFile(copyTo.Replace(repoPath + "/", ""));
                    }
                }

                X3DTrans(copyTo);
            };

            Thread th = new Thread(new ThreadStart(() =>
            {
                command = "cd \"" + path + "\" & java -jar \"" + PathHelper.GetToolsPath() + "/saxon9he.jar\" \"" + path + "/xslt/a.xml\" \"" + PathHelper.GetToolsPath() + "/xslt/c.xsl\" " + parameters + " > \"" + path + "/b.xml\"";
                ProcessStartInfo processInfo;
                processInfo = new ProcessStartInfo("cmd.exe", "/C " + command);

                processInfo.CreateNoWindow         = true;
                processInfo.UseShellExecute        = false;
                processInfo.RedirectStandardOutput = true;
                processInfo.RedirectStandardError  = true;

                var process    = Process.Start(processInfo);
                string outputt = process.StandardOutput.ReadToEnd();
                string errors  = process.StandardError.ReadToEnd();

                if (!string.IsNullOrEmpty(errors))
                {
                    _logger.LogError($"Error executing command: \"{command}\". Message: '{errors}'");
                }

                process.WaitForExit();
                onFinish();
            }));

            th.Start();
        }