/* * -command=upload_file -repo=InitialRepository -model=test -login=ah -pass=db -node="Engine Block" -file="O:\projects\SimDM\Testdata\Glider TestModels\ConvertedByAP209e2_API\testcbeam-out.stp" =========================================================================================*/ /*=======================================================================================*/ static void uploadFile() { string fileToUpload = arguments["file"]; //int nodeId = Int32.Parse(arguments["id"]); string nodeName = arguments["node"]; var list = service.pbs_search(sessionId, nodeName, new string[] { "NODE.NAME" }, false, true, 0, null, false, null, null, null, null, 2, 0); if (list == null || list.Length == 0) throw new Exception("No nodes was found."); else if (list.Length > 1) throw new Exception("More than one node was found."); FileInfo fileInfo = new FileInfo(fileToUpload); v_file fileSpec = new v_file() { item = new v_item() { name = System.IO.Path.GetFileNameWithoutExtension(fileToUpload), }, extension = fileInfo.Extension, @interface = "Interface specifications", original_name = fileToUpload, original_format = "file format name", // can be derived from file name by using Win API OS = "Microsoft Windows", produced_by = "EPM Thechnology AS", size = (int)fileInfo.Length, owner = 0, // organization id }; //fileSpec.item.item_type = "TEXT"; //fileSpec.item.item_type = "UNDEFINED"; fileSpec = service.file_create(sessionId, fileSpec); v_attached_file attachedFile = new v_attached_file() { domain = list[0].item.instance_id, file = fileSpec.item.instance_id, item = new v_item() { name = fileInfo.Name, description = "description must be here", }, }; attachedFile = service.attached_file_create(sessionId, attachedFile); var transferInfo = Upload(sessionId, access, fileToUpload, fileInfo.Extension); fileSpec = service.file_body_set(sessionId, fileSpec.item.instance_id, fileSpec.size, transferInfo.fileNameOnServer); if ("ANALYSIS".Equals(fileSpec.item.item_type) || "DESIGN".Equals(fileSpec.item.item_type)) { var resultFile = access.createTemporaryFile(sessionId, "name", ".cax", false); string source = transferInfo.fileNameOnServer; string result = resultFile.fileNameOnServer; service.file_CAX_generate(sessionId, fileSpec.item.instance_id, source, result, null/*log file*/, true); } else if ("STEP".Equals(fileSpec.item.item_type) && !"[NO SCHEMA]".Equals(fileSpec.model_name)) { fileSpec = service.file_import_STEP(sessionId, fileSpec.item.instance_id, "", transferInfo.fileNameOnServer, ""); if (fileSpec.CAX != -1) { var resultFile = access.createTemporaryFile(sessionId, "name", ".cax", false); string source = transferInfo.fileNameOnServer; string result = resultFile.fileNameOnServer; service.file_CAX_generate(sessionId, fileSpec.item.instance_id, source, result, null/*log file*/, true); } } }
/* * -command=model_uploadFile -repo=InitialRepository -model=test -login=ah -pass=db -node="Engine Block" -file="O:\projects\SimDM\Testdata\Glider TestModels\ConvertedByAP209e2_API\testcbeam-out.stp" =========================================================================================*/ /*=======================================================================================*/ static void model_uploadFile() { string fileToUpload = arguments["file"]; string nodeName = arguments["node"]; long model_id = plm_get_model_id(arguments["repo"], arguments["model"]); var list = service.model_pbs_search(sessionId, model_id, nodeName, new string[] { "NODE.NAME" }, false, true, 0, null, false, null, null, null, null, 2, 0); if (list == null || list.Length == 0) throw new Exception("No nodes was found."); else if (list.Length > 1) throw new Exception("More than one node was found."); FileInfo fileInfo = new FileInfo(fileToUpload); v_file fileSpec = new v_file() { item = new v_item() { name = System.IO.Path.GetFileNameWithoutExtension(fileToUpload), }, extension = fileInfo.Extension, @interface = "Interface specifications", original_name = fileToUpload, original_format = "file format name", // can be derived from file name by using Win API OS = "Microsoft Windows", produced_by = "EPM Thechnology AS", size = (int)fileInfo.Length, owner = 0, // organization id }; fileSpec = service.model_file_create(sessionId, model_id, fileSpec); v_attached_file attachedFile = new v_attached_file() { domain = list[0].item.instance_id, file = fileSpec.item.instance_id, item = new v_item() { name = fileInfo.Name, description = "description must be here", }, }; attachedFile = service.attached_file_create(sessionId, attachedFile); var transferInfo = Upload(sessionId, access, fileToUpload, fileInfo.Extension); fileSpec = service.model_file_body_set(sessionId, fileSpec.item.instance_id, fileSpec.size, transferInfo.fileNameOnServer); }