示例#1
0
        public static void ReplaceFileInZip(string zipPath, string replacedFile, bool isVmp = true)
        {
            TempFolderCreate();
            string tempPath = GetTempFolderPath();

            ZipFile.ExtractToDirectory(zipPath, tempPath, true);

            if (isVmp)
            {
                foreach (string s in Directory.GetFiles(tempPath))
                {
                    if (s.Contains(".xml") && !s.Contains("Manuals.xml"))
                    {
                        string content = File.ReadAllText(s);
                        if (!content.Contains("<manual"))
                        {
                            File.Copy(replacedFile, s, true);
                        }
                    }
                }
            }
            else
            {
                File.Copy(replacedFile, Path.Combine(tempPath, "temp.xml"), true);
            }

            ZipFile.CreateFromDirectory(tempPath, zipPath);

            PathHelper.DeleteDirectory(GetTempFolderPath());
        }
示例#2
0
        public static void Import(string res, string location, bool overwrite, Action <ImportedScenarioModel> onResult)
        {
            if (string.IsNullOrEmpty(res))
            {
                return;
            }

            var fileInfo = new FileInfo(res);

            if (fileInfo.Extension != ".zip")
            {
                return;
            }

            string repoPath = Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder());

            if (location.Contains(repoPath))
            {
                location = location.Replace(repoPath, "");
            }

            location = location.Replace("\\", "/");
            TempFolderCreate();
            ZipFile.ExtractToDirectory(res, GetTempFolderPath(), true);

            tempIds.Clear();
            Thread.Sleep(1000);
            ImportHandler(0, "", GetTempFolderPath(), overwrite, location);

            foreach (DirectoryInfo dir in new DirectoryInfo(GetTempFolderPath()).GetDirectories())
            {
                string newLocation = dir.FullName.Replace("\\", "/")
                                     .Replace(GetTempFolderPath().Replace("\\", "/"), repoPath);
                MoveFolder(dir.FullName.Replace("\\", "/"), newLocation.Replace("\\", "/"));
            }

            ImportedScenarioModel model = new ImportedScenarioModel();

            model.scenarios_ids = new List <string[]>();

            //string json = "{ scenarios_ids: [ ";
            foreach (var i in tempIds)
            {
                string[] scenario = new string[2];
                scenario[0] = i.oldId;
                scenario[1] = i.newId;
                //json += string.Format("[\"{0}\",\"{1}\"],", i.oldId, i.newId);
                model.scenarios_ids.Add(scenario);
            }

            //json = json.Remove(json.Length - 1);
            //json += "]}";
            PathHelper.DeleteDirectory(GetTempFolderPath());
            onResult(model);
        }
示例#3
0
        private static IEnumerable <PathContainer> GetFilesScenario(string filePath, string root = "")
        {
            string scenario    = new FileInfo(filePath).Directory.Name;
            string scenarioDir = new FileInfo(filePath).Directory.FullName;

            string[] topicNames = Directory.GetFiles(Path.Combine(scenarioDir, "topics"), "*.info");

            foreach (string n in topicNames)
            {
                List <PathContainer> topics = GetFilesTopic(n).ToList();

                foreach (PathContainer t in topics)
                {
                    yield return(new PathContainer(t.source, Path.Combine(root, scenario, t.relative)));
                }
            }

            //create pub_offline or clean
            string offlineDir = Path.Combine(scenarioDir, "default", "pub_offline");

            if (Directory.Exists(offlineDir))
            {
                PathHelper.DeleteDirectory(offlineDir);
            }
            Directory.CreateDirectory(offlineDir);
            Directory.CreateDirectory(Path.Combine(offlineDir, "Resource"));

            foreach (string f in Directory.GetFiles(Path.Combine(scenarioDir, "default", "pub_out")))
            {
                if (new FileInfo(f).Extension.Contains(".xml"))
                {
                    string newPath = f.Replace("pub_out", "pub_offline");
                    string text    = File.ReadAllText(f);

                    text = ProcessDitaFileForOfflinePublication(text);
                    File.WriteAllText(newPath, text);

                    yield return(new PathContainer(newPath, Path.Combine(root, scenario, "default", "pub_offline", new FileInfo(newPath).Name)));
                }
                else
                {
                    string newPath = f.Replace("pub_out", Path.Combine("pub_offline", "Resource"));
                    File.Copy(f, newPath);

                    yield return(new PathContainer(newPath, Path.Combine(root, scenario, "default", "pub_offline", "Resource", new FileInfo(newPath).Name)));
                }
            }

            yield return(new PathContainer(filePath, Path.Combine(root, scenario, scenario + ".info")));
        }
示例#4
0
        public static void ImportTopic(string res, string location, bool overwrite, Action <ImportedTopicModel> onResult)
        {
            if (string.IsNullOrEmpty(res))
            {
                return;
            }

            string repoPath = Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder()).Replace("\\", "/");

            location = location.Replace("\\", "/");
            if (location.Contains(repoPath))
            {
                location = location.Replace(repoPath, "");
            }

            location = location.Replace("\\", "/");

            TempFolderCreate();
            var topicTempFoler = Path.Combine(GetTempFolderPath(), new FileInfo(res).Name + DateTime.Now.Millisecond);

            ZipFile.ExtractToDirectory(res, topicTempFoler, true);

            tempIds.Clear();

            ImportHandler(0, "", topicTempFoler, overwrite, location, true);
            List <string> directories = GetDirectories(new DirectoryInfo(topicTempFoler).FullName, "*", SearchOption.AllDirectories);

            foreach (string dir in directories)
            {
                if (dir.Contains("topics") || dir.Contains("default"))
                {
                    string newLocation = dir.Replace("\\", "/").Replace(topicTempFoler.Replace("\\", "/"), repoPath);
                    MoveFolder(dir.Replace("\\", "/"), newLocation.Replace("\\", "/"));
                }
            }

            PathHelper.DeleteDirectory(topicTempFoler);

            ImportedTopicModel model = new ImportedTopicModel();

            onResult(model);
        }
示例#5
0
        public static void Export(string res, string file, ExportType exportType)
        {
            if (string.IsNullOrEmpty(res))
            {
                return;
            }

            string root = file.Replace(PathHelper.GetRepoPath(), "").Replace("\\", "/");

            string[] rootParts = root.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            if (!file.Contains(PathHelper.GetRepoPath()))
            {
                file = Path.Combine(PathHelper.GetRepoPath(), file);
            }

            TempFolderCreate();

            List <PathContainer> files = new List <PathContainer>();

            if (exportType == ExportType.Topic)
            {
                files = GetFilesTopic(file, Path.Combine(rootParts[0], rootParts[1], rootParts[2])).ToList();
                string categoryInfo = Path.Combine(rootParts[0], rootParts[0] + ".info");
                files.Add(new PathContainer(Path.Combine(PathHelper.GetRepoPath(), categoryInfo), categoryInfo));
                string productInfo = Path.Combine(rootParts[0], rootParts[1], rootParts[1] + ".info");
                files.Add(new PathContainer(Path.Combine(PathHelper.GetRepoPath(), productInfo), productInfo));
                string scenarioInfo = Path.Combine(rootParts[0], rootParts[1], rootParts[2], rootParts[2] + ".info");
                files.Add(new PathContainer(Path.Combine(PathHelper.GetRepoPath(), scenarioInfo), scenarioInfo));
            }
            else if (exportType == ExportType.Scenario)
            {
                files = GetFilesScenario(file, Path.Combine(rootParts[0], rootParts[1])).ToList();
                string categoryInfo = Path.Combine(rootParts[0], rootParts[0] + ".info");
                files.Add(new PathContainer(Path.Combine(PathHelper.GetRepoPath(), categoryInfo), categoryInfo));
                string productInfo = Path.Combine(rootParts[0], rootParts[1], rootParts[1] + ".info");
                files.Add(new PathContainer(Path.Combine(PathHelper.GetRepoPath(), productInfo), productInfo));
            }
            else if (exportType == ExportType.Product)
            {
                files = GetFilesProduct(file, rootParts[0]).ToList();
                string categoryInfo = Path.Combine(rootParts[0], rootParts[0] + ".info");
                files.Add(new PathContainer(Path.Combine(PathHelper.GetRepoPath(), categoryInfo), categoryInfo));
            }
            else if (exportType == ExportType.Category)
            {
                files = GetFilesCategory(file).ToList();
            }
            else if (exportType == ExportType.All)
            {
                files = GetFilesRepository().ToList();
            }

            foreach (PathContainer f in files)
            {
                string tempName = new FileInfo(f.relative).Name;
                string dirName  = f.relative.Replace(tempName, "");
                Directory.CreateDirectory(Path.Combine(GetTempFolderPath(), dirName));
                if (File.Exists(f.source))
                {
                    File.Copy(f.source, Path.Combine(GetTempFolderPath(), f.relative), true);
                }
            }

            string zipPath = res + ".zip";

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

            try
            {
                if (File.Exists(zipPath))
                {
                    File.Delete(zipPath);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error deleting existing folder export ZIP.", ex);
            }

            ZipFile.CreateFromDirectory(GetTempFolderPath(), zipPath);

            PathHelper.DeleteDirectory(GetTempFolderPath());
        }