Exemple #1
0
        private static void GenerateXMLFromDirectory(string path, string writeTo, string title)
        {
            //path = Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder(), path);

            DirectoryInfo info = new DirectoryInfo(path);

            FileInfo[] files    = info.GetFiles().OrderBy(p => p.LastWriteTime).ToArray();
            string     xmlMask  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<topic>\r\n<title>{0}</title>\r\n{1}\r\n</topic>";
            string     xmlParts = "";

            foreach (FileInfo file in files)
            {
                string fileName = Path.GetFileName(file.FullName);
                if (fileName != "dita_pub_00001.xml" && Path.GetExtension(file.FullName).Contains("xml"))
                {
                    string[] lines = File.ReadAllLines(file.FullName);
                    for (int i = 2; i < lines.Length; i++)
                    {
                        xmlParts += lines[i] + "\r\n";
                    }
                }
            }

            string result = string.Format(xmlMask, title, xmlParts);

            File.WriteAllText(writeTo, result, System.Text.Encoding.UTF8);

            SVNManager.AddFile(writeTo, (res) => { SVNManager.Commit("Generate xml files", (com) => { }); });
        }
Exemple #2
0
        private static void DraftTopic(string topic, string path)
        {
            string     pathToFolder = Path.Combine(path, "default", "projects");
            TopicModel topicModel   = JsonConvert.DeserializeObject <TopicModel>(File.ReadAllText(topic));

            topicModel.localization = "default";
            string vmbFile = topicModel.vmpPath.Replace(".vmp", ".vmb");

            if (File.Exists(vmbFile))
            {
                string unzipFolder = Path.Combine(pathToFolder, topicModel.name.Replace(" ", "_"));
                if (Directory.Exists(unzipFolder))
                {
                    foreach (string f in Directory.GetFiles(unzipFolder))
                    {
                        File.Delete(f);
                    }
                }

                if (!string.IsNullOrEmpty(topicModel.pathToZip) && File.Exists(topicModel.pathToZip))
                {
                    topicModel.pathToZip = topicModel.pathToZip.Replace("data\\", UsersHelper.GetToolsFolder() + "\\");
                    topicModel.pathToZip = topicModel.pathToZip.Replace("data/", UsersHelper.GetToolsFolder() + "/");
                    string toolsDir = PathHelper.GetUserProcessingFolder();
                    string pathOne  = Path.Combine(toolsDir, "input/resourceFolder").Replace("\\", "/");
                    string pathTwo  = Path.Combine(toolsDir, "input").Replace("\\", "/");
                    File.Copy(topicModel.pathToZip, Path.Combine(pathOne, Path.GetFileName(topicModel.pathToZip)).Replace("\\", "/"), true);
                    File.Copy(topicModel.pathToZip, Path.Combine(pathTwo, Path.GetFileName(topicModel.pathToZip)).Replace("\\", "/"), true);
                }

                Unzip(vmbFile, unzipFolder);
                ConvertToX3D(unzipFolder, Path.Combine(path, "default", "pub_draft"), topicModel.name + new Random().Next(1000, 9999), topicModel.type == "info", topicModel);
            }

            if (!string.IsNullOrEmpty(topicModel.pathToZip) && File.Exists(topicModel.pathToZip))
            {
                string fileCopy = topicModel.pathToZip.Replace("pub_in", "pub_draft");
                File.Copy(topicModel.pathToZip, fileCopy, true);
                SVNManager.AddFile(fileCopy.Replace(Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder()) + "/", ""));
            }
        }
Exemple #3
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();
        }
Exemple #4
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();
        }