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); }
public ImportedScenarioModel Import(string folder_id, [FromBody] ApiFormInput formData) { ImportedScenarioModel model = new ImportedScenarioModel(); if (!formData.local) { string fileName = formData.filename; string base64 = formData.file; formData.file = Path.Combine(PathHelper.GetViewerImagesFolder(), fileName); byte[] fileContent = ApiHelper.DecodeBase64(base64); IOFile.WriteAllBytes(formData.file, fileContent); } if (string.IsNullOrEmpty(formData.ticket)) { model.errors = ApiHelper.JsonError(400, new string[] { "error" }); return(model); } if (string.IsNullOrEmpty(formData.file)) { model.errors = ApiHelper.JsonError(400, new string[] { "File is required" }); return(model); } if (!PathHelper.CheckIfStringIsPathCompliant(Path.GetFileName(formData.file))) { model.errors = ApiHelper.JsonError(400, new[] { "Invalid file name provided" }); return(model); } if (!_authenticationManager.CheckAccessToken(formData.ticket)) { model.errors = ApiHelper.JsonError(400, new string[] { "wrong token" }); return(model); } formData.file = formData.file.Replace("file:///", ""); formData.file = formData.file.Replace("file://", ""); string ret = ApiHelper.FindFolderById(folder_id, PathHelper.GetRepoPath()); if (ret == null) { //return ApiHelper.JsonError(400, new string[] { "folder not exist" }); model.errors = ApiHelper.JsonError(400, new string[] { "file not exist" }); return(model); } if (!IOFile.Exists(formData.file)) { //return ApiHelper.JsonError(400, new string[] { "file not exist" }); model.errors = ApiHelper.JsonError(400, new string[] { "file not exist" }); return(model); } if (!string.IsNullOrEmpty(ret)) { ret = ret.Replace(PathHelper.GetRepoPath(), "").Replace("\\", "/"); Exporter.Import(formData.file, ret, formData.overRide, (res) => { model = res; }); } SVNManager.SaveChanges(); return(model); }