Exemplo n.º 1
0
        public static FolderModel GetFolderInfo(string id, string path)
        {
            string        folder   = new DirectoryInfo(path).Name;
            CategoryModel category =
                JsonConvert.DeserializeObject <CategoryModel>(File.ReadAllText(Path.Combine(path, folder + ".info")));
            FolderObject fl = new FolderObject();

            fl.id   = id;
            fl.name = category.title;
            string parentName = new DirectoryInfo(path).Parent.Name;

            if (FindFolderById(parentName.Split('.')[0], PathHelper.GetRepoPath()) == null)
            {
                fl.type   = FolderType.Category.ToString();
                fl.parent = null;
            }
            else
            {
                fl.type   = FolderType.Product.ToString();
                fl.parent = parentName;
            }

            FolderModel model = new FolderModel();

            model.folder = fl;
            //string json = "{ folder:\"" + JsonConvert.SerializeObject(fl) + "\"}";
            return(model);
        }
Exemplo n.º 2
0
        public static ScenarioModel CreateScenario(string folder_id, string name, string description)
        {
            string folder = ApiHelper.FindFolderById(folder_id, PathHelper.GetRepoPath());
            string ret    = Command.CreateScenario(name, folder, description);

            folder = ApiHelper.FindFolderById(ret, PathHelper.GetRepoPath());
            return(ApiHelper.GetScenarioInfoModel(ret, folder));
        }
Exemplo n.º 3
0
        public static FolderModel CreateFolder(string folder_id, string name)
        {
            string folder = folder_id != ""
                ? ApiHelper.FindFolderById(folder_id, PathHelper.GetRepoPath())
                : PathHelper.GetRepoPath();
            string id = Command.CreateCategory(name, folder);

            folder = ApiHelper.FindFolderById(id, PathHelper.GetRepoPath());
            return(ApiHelper.GetFolderInfo(id, folder));
            //return ret;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieves data from *.info files within ~\topics folder for particular scenario
        /// </summary>
        /// <param name="scenarioId">ID of scenario to retireve topics from</param>
        /// <returns>Deserialized object from *.info file</returns>
        public static List <TopicObject> GetTopics(string scenarioId)
        {
            var scenarioRootFolder = FindFolderById(scenarioId, PathHelper.GetRepoPath());

            EnsureScenarioFoldersExist(scenarioRootFolder);

            var topicsDirectory = Path.Combine(scenarioRootFolder, "topics");
            var serializer      = new JsonSerializerUtility();

            var result = Directory.GetFiles(topicsDirectory)
                         .Select(topicFile => serializer.DeserializeFromFile <TopicModel>(topicFile))
                         .Select(topic => topic.ConvertToDto()).ToList();

            return(result);
        }
Exemplo n.º 5
0
        public static string RenameFolder(string folderPath, string oldName, string newName)
        {
            newName = FormatStringToValid(newName);

            string[] nameSplit = oldName.Split('.');
            string   oldId     = oldName.Split('.')[0];

            if (nameSplit.Length == 2)
            {
                newName = oldId;
            }
            else
            {
                newName = GenerateId(10);
            }

            if (oldName == newName)
            {
                return(oldName);
            }

            if (Directory.Exists(folderPath.Replace(oldName, newName)))
            {
                newName += new Random().Next(1000, 9999);
            }

            if (!folderPath.Contains(PathHelper.GetRepoPath()))
            {
                folderPath = Path.Combine(PathHelper.GetRepoPath(), folderPath);
            }
            string oldPath = folderPath;

            //Debug.Log (folderPath);Debug.Log (oldName);Debug.Log (newName);

            //Directory.Move(folderPath, folderPath.Replace(oldName, newName));

            folderPath = folderPath.Replace(oldName, newName);
            //File.Move(Path.Combine(folderPath, oldName + ".info"), Path.Combine(folderPath, newName + ".info"));

            ChangeVmpPath(folderPath, oldName, newName);

            return(newName);
        }
Exemplo n.º 6
0
        private static IEnumerable <PathContainer> GetFilesRepository()
        {
            string repoDir = PathHelper.GetRepoPath();

            string[] categoryDirs = Directory.GetDirectories(repoDir);

            foreach (string c in categoryDirs)
            {
                if (PathHelper.IsProject(c))
                {
                    List <PathContainer> categorys = GetFilesCategory(PathHelper.GetFilePath(c)).ToList();

                    foreach (PathContainer p in categorys)
                    {
                        yield return(p);
                    }
                }
            }
        }
        private static void Setup(string pathToVmp,
                                  string topicPath,
                                  string appName,
                                  string webRootPath,
                                  TopicModel topic,
                                  Action onStart,
                                  Action <TopicModel, string, string> onExit)
        {
            Show(topicPath, pathToVmp, appName, webRootPath,
                 () =>
            {
                _logger.LogDebug("Starting Cortona, locking files in SVN");
                SVNManager.LockFile(pathToVmp.Replace(PathHelper.GetRepoPath(), ""));
                onStart?.Invoke();
            },
                 (sender, e) =>
            {
                _logger.LogDebug("Exit Cortona");
                SVNManager.UnlockFile(pathToVmp.Replace(PathHelper.GetRepoPath(), ""));

                onExit(topic, topicPath, pathToVmp);
            });
        }
Exemplo n.º 8
0
        public static List <TopicModel> GetTopicsOrigin(string scenario_id)
        {
            string scenarioRootFolder = FindFolderById(scenario_id, PathHelper.GetRepoPath());

            EnsureScenarioFoldersExist(scenarioRootFolder);

            var topicsDirectory = Path.Combine(scenarioRootFolder, "topics");
            var objects         = new List <TopicModel>();

            foreach (string t in Directory.GetFiles(topicsDirectory))
            {
                TopicModel    topic    = JsonConvert.DeserializeObject <TopicModel>(File.ReadAllText(t));
                OldTopicModel oldTopic = JsonConvert.DeserializeObject <OldTopicModel>(File.ReadAllText(t));
                if (!string.IsNullOrEmpty(oldTopic.pathToZip))
                {
                    topic.localization = "default";
                    topic.pathToZip    = oldTopic.pathToZip;
                }

                if (!string.IsNullOrEmpty(oldTopic.vmpPath))
                {
                    topic.localization = "default";
                    topic.vmpPath      = oldTopic.vmpPath;
                }

                if (string.IsNullOrEmpty(topic.pathToZip) && !string.IsNullOrEmpty(topic.pathToZipDEFAULT))
                {
                    topic.pathToZip = topic.pathToZipDEFAULT;
                    File.WriteAllText(t, JsonConvert.SerializeObject(topic));
                }

                topic.infoPath = t;
                objects.Add(topic);
            }

            return(objects);
        }
Exemplo n.º 9
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());
        }