private static void single_cycle() { DateTime time_single_cycle_start = DateTime.Now; lastResult = CycleResult.TIMEOUT; lastLogMsg = "Starting single_cycle"; lastIDR = null; // Get a single MSG from Queue_Requests bool msg_found; Amazon.SQS.Model.Message msg; useLowPrioirty_Q = false; if (!SQS_Utils.Get_Msg_From_Q(request_Q_url, out msg, out msg_found)) { lastLogMsg = "Get_Msg_From_Q() failed !!!"; log(lastLogMsg); lastResult = CycleResult.FAIL; return; } // if there is No Msg - Sleep & continue; if (!msg_found) { if (delayer && !disable_low_priority) // this means we may also check on the lowprioirty Q { bool lowPrioirty_msg_found = false; if (!SQS_Utils.Get_Msg_From_Q(request_lowpriority_Q_url, out msg, out lowPrioirty_msg_found)) { lastLogMsg = "Get_Msg_From_Q(lowprioirty) failed !!!"; log(lastLogMsg); lastResult = CycleResult.FAIL; return; } if (!lowPrioirty_msg_found) { lastLogMsg = "No MSG"; UtilsDLL.Win32_API.sendWindowsStringMessage(whnd, id, "no_msg"); lastResult = CycleResult.NO_MSG; return; } useLowPrioirty_Q = true; } else { lastLogMsg = "No MSG"; UtilsDLL.Win32_API.sendWindowsStringMessage(whnd, id, "no_msg"); lastResult = CycleResult.NO_MSG; return; } } // Extract the ImageData ImageDataRequest imageData = null; if (!ImageDataRequest.deciferImageDataFromBody(msg.Body, out imageData)) { lastLogMsg = "deciferImagesDataFromJSON(msg.Body=" + msg.Body + ", out imagesDatas) failed!!!"; log(lastLogMsg); lastResult = CycleResult.FAIL; return; } if (imageData.operation == Constants.RENDER_CMD) { lastIDR = imageData; DateTime time_msg_decifered = DateTime.Now; int prevFuckups_this_image = Fuckups_DB.Get_Fuckups(imageData.item_id); if (prevFuckups_this_image >= imageData.retries) { // send an error msg telling that this image was deleted // delete the message... Delete_Msg_From_Req_Q(msg, useLowPrioirty_Q); lastResult = CycleResult.FUCKUPS_DELETED; return; } if (prevFuckups_this_image > 0) { adjust_numeric_params(imageData.propValues); } // Add Msg to Queue_Readies TimeSpan duration = DateTime.Now - time_single_cycle_start; Dictionary<String, Object> tempDict = new Dictionary<string, object>(); tempDict["item_id"] = imageData.item_id; tempDict[Constants.URL_JSON_KEY] = @"http://s3.amazonaws.com/" + bucket_name + @"/" + imageData.item_id + ".jpg"; tempDict["duration"] = Math.Round(duration.TotalSeconds, 3); tempDict["status"] = RenderStatus.STARTED.ToString(); if (!Send_Dict_Msg_To_Readies_Q(tempDict, 3)) { lastLogMsg = "Send_Msg_To_Readies_Q(status=STARTED,imageData.item_id=" + imageData.item_id + ") failed"; log(lastLogMsg); lastResult = CycleResult.FAIL; return; } DateTime time_before_Process_Into_Image_File = DateTime.Now; Console.WriteLine("EntireJSON = " + imageData.entireJSON); // inform manager UtilsDLL.Win32_API.sendWindowsStringMessage(whnd, id, Constants.RENDER_CMD+" starting " + imageData.item_id + " " + imageData.entireJSON); // Process Msg to picture String resultingLocalImageFilePath; if (!Process_Into_Image_File(imageData, out resultingLocalImageFilePath)) { String logLine = "Process_Msg_Into_Image_File(msg) failed!!! (). ImageData=" + imageData.ToString(); lastLogMsg = logLine; log(logLine); // Send_Msg_To_ERROR_Q(imageData.item_id, logLine, beforeProcessingTime); lastResult = CycleResult.FAIL; return; } DateTime time_after_Process_Into_Image_File = DateTime.Now; if (!imageData.getSTL) { if (!skip_empty_check) { // check with empty images Color[] shortCut; if (!UtilsDLL.Image_Utils.shortCut(resultingLocalImageFilePath, out shortCut)) { String logLine = "UtilsDLL.Image_Utils.shortCut(file=" + resultingLocalImageFilePath + " failed!!! ()."; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } String size_key = imageData.imageSize.Width + "_" + imageData.imageSize.Height; if (!emptyShortCuts.ContainsKey(size_key)) { String logLine = "Found no empty image file to compare to (size_key=" + size_key + " )!!"; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } if (!emptyShortCuts[size_key].ContainsKey(imageData.viewName)) { String logLine = "Found no empty image file to compare to (viewName=" + imageData.viewName + " )!!"; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } if (emptyShortCuts[size_key][imageData.viewName].Count == 0) { String logLine = "Found no empty image file to compare to (Count==0)!!"; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } foreach (String key in emptyShortCuts[size_key][imageData.viewName].Keys) { Color[] emptyImageSC = emptyShortCuts[size_key][imageData.viewName][key]; bool compRes = false; if (!UtilsDLL.Image_Utils.compare_shortcuts(shortCut, emptyImageSC, out compRes)) { String logLine = "Failed because comparing failed rendered image (" + resultingLocalImageFilePath + ") to file:" + imageData.gh_fileName + Path.DirectorySeparatorChar + size_key + Path.DirectorySeparatorChar + imageData.viewName + Path.DirectorySeparatorChar + key; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } if (compRes) { String logLine = "Failed because rendered image (" + resultingLocalImageFilePath + ") identical to empty image file:" + imageData.gh_fileName + Path.DirectorySeparatorChar + size_key + Path.DirectorySeparatorChar + imageData.viewName + Path.DirectorySeparatorChar + key; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } } } } DateTime time_after_empty_check = DateTime.Now; /* if (imageData.item_id.EndsWith("22")) { String logLine = "Delibiretly failing item - ends with 22. ImageData=" + imageData.ToString(); lastLogMsg = logLine; log(logLine); MessageBox.Show(logLine); lastResult = CycleResult.FAIL; return; } */ TimeSpan stl_timespan = new TimeSpan(0,0,0,99); if (imageData.getSTL) { if (imageData.reduceMesh > 0) { if (!Rhino.ReduceMesh(rhino_wrapper, imageData.reduceMesh, imageData.reduceBy)) { String logLine = "Rhino.ReduceMEsh failed !!!"; log(logLine); lastLogMsg = logLine; // Send_Msg_To_ERROR_Q(imageData.item_id, logLine, beforeProcessingTime); lastResult = CycleResult.FAIL; return; } } DateTime beforeSTL = DateTime.Now; String resulting_3dm_path = resultingLocalImageFilePath.Replace(".jpg","."+imageData.export_format).Replace("yofi_",""); int tries = 3; String command = "-SelAll"; while (tries > 0) { try { log("Before executing command : " + command); rhino_wrapper.rhino_app.RunScript(command, 1); log("After command :" + command); command = "-Export _GeometryOnly=Yes " + resulting_3dm_path; if (imageData.export_format == "obj") command += " Geometry=Mesh EndOfLine=CRLF ExportRhinoObjectNames=ExportObjectsAsOBJObjects ExportRhinoGroupOrLayerNames=DoNotExportGroupNames ExportMeshTextureCoordinates=No ExportMeshVertexNormals=Yes CreateNGons=No ExportMaterialDefinitions=No YUp=No WrapLongLines=No VertexWelding=Welded WritePrecision=16 Enter Enter"; log("Before command :" + command); rhino_wrapper.rhino_app.RunScript(command, 1); log("After command :" + command); if (imageData.export_format == "obj") { String resulting_js_path = resultingLocalImageFilePath.Replace(".jpg", ".js").Replace("yofi_", ""); if (!UtilsDLL.ThreeJS.convert_from_obj_to_js(resulting_3dm_path, resulting_js_path)) { String logLine = "failed to UtilsDLL.ThreeJS.convert_from_obj_to_js(resulting_3dm_path=" + resulting_3dm_path + ", resulting_js_path=" + resulting_js_path + ")"; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } String js_fileName_on_S3 = imageData.item_id.ToString() + ".js"; String js_url; if (!UtilsDLL.S3_Utils.Write_File_To_S3(stl_bucket_name,resulting_js_path,js_fileName_on_S3,out js_url)) { String logLine = "failed to UtilsDLL.S3_Utils.Write_File_To_S3(stl_bucket_name="+stl_bucket_name+", resulting_js_path="+resulting_js_path+", js_fileName_on_S3="+js_fileName_on_S3+", out js_url=*) !!!"; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } String resulting_bin_path = resultingLocalImageFilePath.Replace(".jpg", ".bin").Replace("yofi_", ""); String bin_fileName_on_S3 = imageData.item_id.ToString() + ".bin"; String bin_url; if (!UtilsDLL.S3_Utils.Write_File_To_S3(stl_bucket_name, resulting_bin_path, bin_fileName_on_S3, out bin_url)) { String logLine = "failed to UtilsDLL.S3_Utils.Write_File_To_S3(stl_bucket_name=" + stl_bucket_name + ", resulting_bin_path=" + resulting_bin_path + ", bin_fileName_on_S3=" + bin_fileName_on_S3 + ", out bin_url=*) !!!"; lastLogMsg = logLine; log(logLine); lastResult = CycleResult.FAIL; return; } } break; } catch (Exception e) { log("Excpetion : " + e.Message); Thread.Sleep(1000); tries--; continue; } } if (tries == 0) { String logLine = "Failed after 3 times to get STL . Giving up"; log(logLine); lastLogMsg = logLine; // Send_Msg_To_ERROR_Q(imageData.item_id, logLine, beforeProcessingTime); lastResult = CycleResult.FAIL; return; } stl_timespan = DateTime.Now - beforeSTL; String stl_fileName_on_S3 = imageData.item_id.ToString() + "." + imageData.export_format; String stl_remote_url; if (imageData.export_format != "obj") { if (!S3_Utils.Write_File_To_S3(stl_bucket_name, resulting_3dm_path, stl_fileName_on_S3, out stl_remote_url)) { String logLine = "Write_File_To_S3(resulting_3dm_path=" + resulting_3dm_path + ", stl_fileName_on_S3=" + stl_fileName_on_S3 + ") failed !!!"; log(logLine); lastLogMsg = logLine; // Send_Msg_To_ERROR_Q(imageData.item_id, logLine, beforeProcessingTime); lastResult = CycleResult.FAIL; return; } } } DateTime time_Before_S3 = DateTime.Now; if (!imageData.getSTL) { String fileName_on_S3 = imageData.item_id.ToString() + ".jpg"; String jpg_remote_url; if (!S3_Utils.Write_File_To_S3(bucket_name, resultingLocalImageFilePath, fileName_on_S3, out jpg_remote_url)) { String logLine = "Write_File_To_S3(resultingImagePath=" + resultingLocalImageFilePath + ", fileName_on_S3=" + fileName_on_S3 + ") failed !!!"; log(logLine); lastLogMsg = logLine; // Send_Msg_To_ERROR_Q(imageData.item_id, logLine, beforeProcessingTime); lastResult = CycleResult.FAIL; return; } } DateTime time_Before_SQS = DateTime.Now; // Delete Msg From Queue_Requests if (!Delete_Msg_From_Req_Q(msg,useLowPrioirty_Q)) { String logLine = "Delete_Msg_From_Req_Q(item_id=" + imageData.item_id + ") failed!!!"; log(logLine); lastLogMsg = logLine; // Send_Msg_To_ERROR_Q(imageData.item_id, logLine, beforeProcessingTime); /* if (!Send_Msg_To_Readies_Q(RenderStatus.ERROR, imageData.item_id, beforeProcessingTime)) { logLine = ("Send_Msg_To_Readies_Q(status=ERROR,imageData.item_id=" + imageData.item_id + ") failed"); log(logLine); Send_Msg_To_ERROR_Q(imageData.item_id, logLine, beforeProcessingTime); } */ lastResult = CycleResult.FAIL; return; } // Add Msg to Queue_Readies duration = DateTime.Now - time_single_cycle_start; tempDict = new Dictionary<string, object>(); tempDict["item_id"] = imageData.item_id; tempDict[Constants.URL_JSON_KEY] = @"http://s3.amazonaws.com/" + bucket_name + @"/" + imageData.item_id + ".jpg"; tempDict["duration"] = Math.Round(duration.TotalSeconds, 3); tempDict["status"] = RenderStatus.FINISHED.ToString(); if (!Send_Dict_Msg_To_Readies_Q(tempDict,3)) { lastLogMsg = "Send_Dict_Msg_To_Readies_Q(status=FINISHED,imageData.item_id=" + imageData.item_id + ") failed"; log(lastLogMsg); lastResult = CycleResult.FAIL; return; } DateTime time_afterSQS = DateTime.Now; log("read msg time Time=" + (time_msg_decifered - time_single_cycle_start).TotalMilliseconds.ToString() + " millis"); log("send 1st rdy msg Time=" + (time_before_Process_Into_Image_File - time_msg_decifered).TotalMilliseconds.ToString() + " millis"); log("process into image Time=" + (time_after_Process_Into_Image_File - time_before_Process_Into_Image_File).TotalMilliseconds.ToString() + " millis"); log("empty check Time=" + (time_after_empty_check - time_after_Process_Into_Image_File).TotalMilliseconds.ToString() + " millis"); log("getSTL Time=" + (time_Before_S3 - time_after_empty_check).TotalMilliseconds.ToString() + " millis"); log("S3 Time=" + (time_Before_SQS - time_Before_S3).TotalMilliseconds.ToString() + " millis"); log("SQS Time=" + (time_afterSQS - time_Before_SQS).TotalMilliseconds.ToString() + " millis"); UtilsDLL.Win32_API.sendWindowsStringMessage(whnd, id, Constants.RENDER_CMD+" finished " + imageData.item_id); lastResult = CycleResult.SUCCESS; return; } else if (imageData.operation == Constants.GHX_ADJUSTING_CMD) { // Delete Msg From Queue_Requests if (!Delete_Msg_From_Req_Q(msg, useLowPrioirty_Q)) { String logLine = "Delete_Msg_From_Req_Q(gh_file=" + imageData.gh_fileName + ") failed!!!"; log(logLine); lastLogMsg = logLine; lastResult = CycleResult.FAIL; return; } Dictionary<String, Object> reply = new Dictionary<string,object>(); reply["server"] = external_ip.ToString(); reply["instance_id"] = id; if (!Adjust_GHX_file_S3(imageData, reply)) { log("Adjust_GHX_file_S3(imageData)"); reply[Constants.STATUS_JSON_KEY] = RenderStatus.FINISHED; } else { reply[Constants.STATUS_JSON_KEY] = RenderStatus.ERROR; } lastResult = CycleResult.SUCCESS; Send_Dict_Msg_To_Readies_Q(reply, 3); return; } else { lastLogMsg = "ERROR !!! - (" + imageData.operation + "=imageData.operation is unknown)"; log(lastLogMsg); lastResult = CycleResult.FAIL; return; } }
public static bool Process_Into_Image_File(ImageDataRequest imageData, out string resultingLocalImageFilePath) { DateTime time_Process_start = DateTime.Now; String logLine = "Starting Process_Into_Image_File()"; log(logLine); resultingLocalImageFilePath = String.Empty; if (!UtilsDLL.Rhino.DeleteAll(rhino_wrapper)) { log("ERROR!!: DeleteAll() failed !!!"); return false; } if (!UtilsDLL.Rhino.SetView(rhino_wrapper, imageData.viewName)) { log("ERROR!!: Rhino.SetView(viewName=" + imageData.viewName + ") failed !!!"); return false; } if (!Rhino.setDefaultLayer(rhino_wrapper, imageData.layerName)) { log("ERROR!!: Rhino.setDefaultLayer(layerName=" + imageData.layerName + ") failed !!!"); return false; } DateTime time_after_delete_and_layer = DateTime.Now; log("(P_into_image) deleteAll & setDefaultLayer Time=" + (time_after_delete_and_layer - time_Process_start).TotalMilliseconds.ToString() + " millis"); if (imageData.gh_fileName.EndsWith(".gh") || imageData.gh_fileName.EndsWith(".ghx")) { if (current_GH_file == imageData.gh_fileName) { logLine = "Skipping Open_GH_File(imageData[imageData.gh_filePath=" + imageData.gh_fileName + ")"; log(logLine); } else { String gh_fileName = Dirs.GH_DirPath + Path.DirectorySeparatorChar + imageData.gh_fileName; if (!File.Exists(gh_fileName)) { gh_fileName = Dirs.ghx_local_DirPath + Path.DirectorySeparatorChar + imageData.gh_fileName; if (!File.Exists(gh_fileName)) { String temp_gh_fileName = Dirs.ghx_local_DirPath + Path.DirectorySeparatorChar + rhino_wrapper.rhino_pid.ToString()+"_"+ imageData.gh_fileName; if (!S3_Utils.Download_File_From_S3(ghx_bucket_name, temp_gh_fileName, "gh_files/" + imageData.gh_fileName)) { log("ERROR!!: S3_Utils.Download_File_From_S3(" + imageData.gh_fileName + ") failed !!!"); return false; } if (!File.Exists(gh_fileName)) { File.Copy(temp_gh_fileName, gh_fileName, false); } } } if (!UtilsDLL.Rhino.Open_GH_File(rhino_wrapper, gh_fileName)) { logLine = "Open_GH_File(imageData[imageData.gh_filePath=" + imageData.gh_fileName + "); failed"; log(logLine); return false; } current_GH_file = imageData.gh_fileName; if (!UtilsDLL.Rhino.DeleteAll(rhino_wrapper)) { log("ERROR!!: DeleteAll(after new GH file) failed !!!"); return false; } } DateTime time_after_gh_open = DateTime.Now; // had to split the execution of stl_to_load to after theabove Delete_All // (of new Grasshopper files- that may write directly junk data to rhino file) // therefore LOAD_stl had to be split between GH and script options if (!String.IsNullOrWhiteSpace(imageData.stl_to_load)) { if (!load_stl_wrapper(imageData.stl_to_load)) { log("ERROR!!: load_stl(imageData.stl_to_load="+imageData.stl_to_load+") failed !!!"); return false; } } DateTime time_after_load_stl = DateTime.Now; if (!UtilsDLL.Rhino.Set_GH_Params(rhino_wrapper,imageData.propValues)) { logLine = "Set_Params(imageData=" + imageData.ToString() + "]) failed !!!"; log(logLine); return false; } DateTime time_after_Set_GH_Param = DateTime.Now; if (!UtilsDLL.Rhino.Solve_GH(rhino_wrapper)) { logLine = "Solve_And_Bake(imageData=" + imageData.ToString() + "]) failed !!!"; log(logLine); return false; } DateTime time_after_Solve_GH = DateTime.Now; if (!UtilsDLL.Rhino.Bake_GH(rhino_wrapper, imageData.bake)) { logLine = "Bake_GH(imageData=" + imageData.ToString() + "]) failed !!!"; log(logLine); return false; } DateTime time_after_Bake_GH = DateTime.Now; log("(P_into_image) gh_open Time=" + (time_after_gh_open - time_after_delete_and_layer).TotalMilliseconds.ToString() + " millis"); log("(P_into_image) load stl Time=" + (time_after_load_stl - time_after_gh_open).TotalMilliseconds.ToString() + " millis"); log("(P_into_image) Set_GH_Param Time=" + (time_after_Set_GH_Param - time_after_load_stl).TotalMilliseconds.ToString() + " millis"); log("(P_into_image) Solve_GH Time=" + (time_after_Solve_GH - time_after_Set_GH_Param).TotalMilliseconds.ToString() + " millis"); log("(P_into_image) Bake_GH Time=" + (time_after_Bake_GH - time_after_Solve_GH).TotalMilliseconds.ToString() + " millis"); } else { // had to split the execution of stl_to_load to after theabove Delete_All // (of new Grasshopper files- that may write directly junk data to rhino file) // therefore LOAD_stl had to be split between GH and script options if (!String.IsNullOrWhiteSpace(imageData.stl_to_load)) { if (!load_stl_wrapper(imageData.stl_to_load)) { log("ERROR!!: load_stl(imageData.stl_to_load=" + imageData.stl_to_load + ") failed !!!"); return false; } } DateTime time_after_load_stl = DateTime.Now; if (!UtilsDLL.Rhino.Run_Script(rhino_wrapper, imageData.gh_fileName, imageData.propValues)) { logLine = "Run_Script(imageData=" + imageData.ToString() + "]) failed !!!"; log(logLine); return false; } DateTime time_after_Run_Script = DateTime.Now; log("(P_into_image) load stl Time=" + (time_after_load_stl - time_after_delete_and_layer).TotalMilliseconds.ToString() + " millis"); log("(P_into_image) Run_Script Time=" + (time_after_Run_Script - time_after_load_stl).TotalMilliseconds.ToString() + " millis"); } DateTime time_beforeRender = DateTime.Now; String resultingImagePath = Dirs.images_DirPath + Path.DirectorySeparatorChar + "yofi_" + imageData.item_id + ".jpg"; if (!imageData.getSTL) { if (!Rhino.Render(rhino_wrapper, imageData.imageSize, resultingImagePath)) { log("Render(imageData=" + imageData.ToString() + ") failed !!!"); return false; } } DateTime time_afterRender = DateTime.Now; resultingLocalImageFilePath = resultingImagePath; log("(P_into_image) render Time=" + (time_afterRender - time_beforeRender).TotalMilliseconds.ToString() + " millis"); return true; }
public static bool deciferImageDataFromBody(String msgBody, out ImageDataRequest imageData) { imageData = new ImageDataRequest(); String jsonString = SQS_Utils.DecodeFrom64(msgBody); Console.WriteLine(jsonString); imageData.entireJSON = jsonString; JavaScriptSerializer serializer = new JavaScriptSerializer(); var jsonObject = serializer.DeserializeObject(jsonString) as Dictionary<string, object>; Dictionary<String, Object> jsonDict = (Dictionary<String, Object>)jsonObject; imageData.jsonObjParam = null; if (!jsonDict.ContainsKey(Constants.PARAM_JSON_KEY)) { Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(" + Constants.PARAM_JSON_KEY + ")"); } else { imageData.jsonObjParam = jsonDict[Constants.PARAM_JSON_KEY]; } if (!jsonDict.ContainsKey(Constants.OPERATION_JSON_KEY)) { Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(" + Constants.OPERATION_JSON_KEY + ")"); return false; } else imageData.operation = (String)jsonDict[Constants.OPERATION_JSON_KEY]; if (!jsonDict.ContainsKey(Constants.GH_FILE_JSON_KEY)) { Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(" + Constants.GH_FILE_JSON_KEY + "))"); return false; } else imageData.gh_fileName = (String)jsonDict[Constants.GH_FILE_JSON_KEY]; if (imageData.operation == Constants.GHX_ADJUSTING_CMD) return true; if (!jsonDict.ContainsKey("item_id")) { Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(\"item_id\"))"); return false; } else imageData.item_id = (String)jsonDict["item_id"]; if (jsonDict.ContainsKey("scene")) { imageData.scene = (String)jsonDict["scene"]; } else imageData.scene = null; if (!jsonDict.ContainsKey("bake")) { Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(\"bake\"))"); return false; } else imageData.bake = (String)jsonDict["bake"]; if (!jsonDict.ContainsKey("width")) { Console.WriteLine("INFO - (!jsonDict.ContainsKey(\"width\"))"); imageData.imageSize.Width = 180; } else imageData.imageSize.Width = (int)jsonDict["width"]; if (!jsonDict.ContainsKey("height")) { Console.WriteLine("INFO - (!jsonDict.ContainsKey(\"height\"))"); imageData.imageSize.Height = 180; } else imageData.imageSize.Height = (int)jsonDict["height"]; if (!jsonDict.ContainsKey("layer_name")) { imageData.layerName = "Default"; } else { imageData.layerName = (String)jsonDict["layer_name"]; } if (jsonDict.ContainsKey("getSTL")) { imageData.getSTL = (bool)jsonDict["getSTL"]; } if (!jsonDict.ContainsKey("view_name")) { imageData.viewName = "Render"; } else { String jsonViewName = ((String)jsonDict["view_name"]).Trim(); if (jsonViewName == String.Empty) { imageData.viewName = "Render"; } else { imageData.viewName = jsonViewName; } } if (!jsonDict.ContainsKey("params")) { Console.WriteLine("ERROR !!! - (!jsonDict.ContainsKey(\"params\"))"); return false; } else { Dictionary<String, Double> paramValues = new Dictionary<string, double>(); imageData.propValues = (Dictionary<String, Object>)jsonDict["params"]; } if (!jsonDict.ContainsKey("retries")) { imageData.retries = 1; } else { imageData.retries = (int)jsonDict["retries"]; } if (!jsonDict.ContainsKey("load_stl")) { imageData.stl_to_load = String.Empty; } else { imageData.stl_to_load = ((String)jsonDict["load_stl"]).Trim(); } imageData.reduceMesh = -1; if (jsonDict.ContainsKey(Constants.REDUCE_MESH_JSON_KEY)) { Object o = jsonDict[Constants.REDUCE_MESH_JSON_KEY]; int vi = (int)o; double vd = (double)vi; imageData.reduceMesh = (int)vd; } imageData.reduceBy = Constants.REDUCE_BY_PERCENTAGE; if (jsonDict.ContainsKey(Constants.REDUCE_BY_JSON_KEY)) { imageData.reduceBy = (String)jsonDict[Constants.REDUCE_BY_JSON_KEY]; } imageData.export_format = "3dm"; if (jsonDict.ContainsKey(Constants.EXPORT_FORMAT_JSON_KEY)) { imageData.export_format = (String)jsonDict[Constants.EXPORT_FORMAT_JSON_KEY]; } imageData.creationTime = DateTime.Now; return true; }
public static bool Adjust_GHX_file_S3(ImageDataRequest request, Dictionary<String,Object> reply) { try { String fileName = request.gh_fileName; reply[Constants.GH_FILE_JSON_KEY] = fileName; String local_raw_ghx_path = Path.Combine(Dirs.ghx_local_DirPath, fileName); if (!S3_Utils.Download_File_From_S3(ghx_bucket_name, local_raw_ghx_path, "gh_files/"+fileName)) { log("S3_Utils.Download_File_From_S3(ghx_bucket_name=" + ghx_bucket_name + ", local_raw_ghx_path=" + local_raw_ghx_path + ", fileName=" + fileName + ")"); return false; } String adjusted_fileName = fileName.Substring(0, fileName.Length - 4) + "_adj.ghx"; List<String> screener = null; if (request.jsonObjParam != null) { screener = new List<string>(); foreach (Object o in (Object[])request.jsonObjParam) { screener.Add((String)o); } } String local_adjusted_ghx_path = Path.Combine(Dirs.ghx_local_DirPath, adjusted_fileName); if (!Rhino.Adjust_GHX_file(local_raw_ghx_path, local_adjusted_ghx_path, reply,screener)) { log("Rhino.Adjust_GHX_file(local_raw_ghx_path=" + local_raw_ghx_path + ", local_adjusted_ghx_path=" + local_adjusted_ghx_path + ") failed!!"); return false; } /* if (!Rhino.Open_GH_File(rhino_wrapper, local_adjusted_ghx_path)) { log("Rhino.Load_GH_File(rhino_wrapper, local_adjusted_ghx_path="+local_adjusted_ghx_path+") failed!!!"); return false; } Dictionary<String, Object> currentParams = new Dictionary<string,object>(); List<Object> slidersList = (List<Object>)reply["sliders"]; foreach (Object o in slidersList) { Dictionary<String, Object> slider_values_dict = (Dictionary<String, Object>)o; String new_param_name = (String)slider_values_dict["new_name"]; currentParams[new_param_name] = slider_values_dict["current"]; } if (!Rhino.Set_GH_Params(rhino_wrapper, currentParams)) { log("Rhino.Set_GH_Params(rhino_wrapper, currentParams=" + currentParams.ToString() + ") failed!!!"); return false; } if (!Rhino.Solve_GH(rhino_wrapper)) { log("Rhino.Solve_GH(rhino_wrapper) failed!!!"); return false; } if (!Rhino.Save_GH_File(rhino_wrapper, local_adjusted_ghx_path)) { log("Rhino.Save_GH_File(rhino_wrapper, local_adjusted_ghx_path=" + local_adjusted_ghx_path + ") failed!!!"); return false; } */ String remote_url; if (!S3_Utils.Write_File_To_S3(ghx_bucket_name, local_adjusted_ghx_path,"gh_files/"+adjusted_fileName,out remote_url)) { log("S3_Utils.Write_File_To_S3(ghx_bucket=" + ghx_bucket_name + ", local_raw_ghx_path=" + local_raw_ghx_path + ", fileName=" + fileName + ")"); return false; } reply[Constants.URL_JSON_KEY] = remote_url; reply[Constants.STATUS_JSON_KEY] = RenderStatus.FINISHED; } catch (Exception e) { log("Exception in Adjust_GHX_file. e.Message=" + e.Message); return false; } return true; }