// Start is called before the first frame update void Start() { json = "{\"jsonapi\": {\"version\": \"1.0\"},\"links\": {\"self\": {\"href\": \"https://developer.api.autodesk.com/project/v1/hubs/a.cGVyc29uYWw6cGUyOWNjZjMy/projects\"}},\"data\": [{\"type\": \"projects\",\"id\": \"a.cGVyc29uYWw6cGUyOWNjZjMyI0QyMDE2MDUyNDEyOTI5NzY\",\"attributes\": {\"name\": \"Demo Project\",\"extension\": {\"type\": \"projects:autodesk.core:Project\",\"version\": \"1.0\",\"schema\": {\"href\": \"https://developer.api.autodesk.com/schema/v1/versions/projects%3Aautodesk.core%3AProject-1.0\"},\"data\": {}}},\"links\": {\"self\": {\"href\": \"https://developer.api.autodesk.com/project/v1/hubs/a.cGVyc29uYWw6cGUyOWNjZjMy/projects/a.cGVyc29uYWw6cGUyOWNjZjMyI0QyMDE2MDUyNDEyOTI5NzY\"}},\"relationships\": {\"hub\": {\"data\": {\"type\": \"hubs\",\"id\": \"a.cGVyc29uYWw6cGUyOWNjZjMy\"},\"links\": {\"related\": {\"href\": \"https://developer.api.autodesk.com/project/v1/hubs/a.cGVyc29uYWw6cGUyOWNjZjMy\"}}},\"rootFolder\": {\"data\": {\"type\": \"folders\",\"id\": \"urn:adsk.wipprod:fs.folder:co.uvDiLQ5DRYidDQ_EFW1OOg\"},\"meta\": {\"link\": {\"href\": \"https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6cGUyOWNjZjMyI0QyMDE2MDUyNDEyOTI5NzY/folders/urn%3Aadsk.wipprod%3Afs.folder%3Aco.uvDiLQ5DRYidDQ_EFW1OOg\"}}}}}]}"; projects = new ProjectJSON(); projects = JsonUtility.FromJson <ProjectJSON>(json); RefreshDisplay(); }
public static EditorModelData GetProjectEditorData(FrontEditorContext _context, int projectId) { ProjectJSON data = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault(); if (data == null) { data = new ProjectJSON() { ProjectId = projectId, ProjectData = parser.SerializeData(new EditorModelData()) }; _context.Add(data); _context.SaveChanges(); } return(parser.DeserializeData(data.ProjectData)); }
public static void DeleteProject(FrontEditorContext _context, int projectId, int userId) { Project project = _context.Projects.Where(x => x.Id == projectId).FirstOrDefault(); if (!UsersBL.UserIsAdmin(_context, userId) && project.Owner.Id != userId) { throw new Exception("Nincs jogosultsága a kért művelet elvégzéséhez!"); } ProjectJSON jsondata = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault(); if (jsondata != null) { _context.ProjectJSONDatas.Remove(jsondata); } _context.Projects.Remove(project); _context.SaveChanges(); }
public static string ExportProjectJson(FrontEditorContext _context, int projectId, string rootPath) { ProjectJSON data = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault(); if (data == null) { throw new Exception("Projekt nem található!"); } string fileName = projectId + "-export-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".zip"; string exportPath = rootPath + "/export/" + fileName; string tempPath = rootPath + "/export/" + projectId + "-export-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + "/"; string templatePath = rootPath + "/export-template/"; string imagesPath = rootPath + "/images/projects/" + projectId + "/"; //Create temp folder and copy template and images System.IO.Directory.CreateDirectory(tempPath); foreach (string dirPath in Directory.GetDirectories(templatePath, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(templatePath, tempPath)); } foreach (string newPath in Directory.GetFiles(templatePath, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(templatePath, tempPath), true); } if (Directory.Exists(imagesPath)) { foreach (string newPath in Directory.GetFiles(imagesPath, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(imagesPath, tempPath + "images/"), true); } } //Create template json file using (FileStream fs = File.Create(tempPath + "project.json")) { Byte[] html = new UTF8Encoding(true).GetBytes(data.ProjectData); fs.Write(html, 0, html.Length); } //Create .zip file ZipFile.CreateFromDirectory(tempPath, exportPath); //Remove temp folder Directory.Delete(tempPath, true); return("/export/" + fileName); }
public static void ImportProjectFromZip(FrontEditorContext _context, int projectId, string rootPath, string zipPath) { try { string tempPath = rootPath + "/import/" + projectId + "-import-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + "/"; string imagesPath = rootPath + "/images/projects/" + projectId + "/"; ZipFile.ExtractToDirectory(zipPath, tempPath); //Parse json and Save it string importedData = System.IO.File.ReadAllText(tempPath + "project.json"); EditorModelData data = parser.DeserializeData(importedData); ProjectJSON jsonData = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault(); if (jsonData == null) { jsonData = new ProjectJSON() { ProjectId = projectId, ProjectData = parser.SerializeData(data) }; _context.Add(jsonData); } else { jsonData.ProjectData = parser.SerializeData(data); _context.Update(jsonData); } _context.SaveChanges(); //Empty files folder and copy new files to files folder foreach (string file in Directory.GetFiles(imagesPath, "*.*", SearchOption.AllDirectories)) { File.Delete(file); } foreach (string file in Directory.GetFiles(tempPath + "images/", "*.*", SearchOption.AllDirectories)) { File.Copy(file, file.Replace(imagesPath, tempPath), true); } //Delete import files from temp folder Directory.Delete(tempPath, true); } catch (Exception ex) { throw new Exception("Hiba történta projekt impotálása közben!"); } }
public static void SaveProjectEditorData(FrontEditorContext _context, int projectId, EditorModelData saveData) { ProjectJSON data = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault(); if (data == null) { data = new ProjectJSON() { ProjectId = projectId, ProjectData = parser.SerializeData(saveData) }; _context.Add(data); } else { data.ProjectData = parser.SerializeData(saveData); _context.Update(data); } _context.SaveChanges(); }