Beispiel #1
0
        public void Start(CycleCoins cycleCoins, Dictionary <string, Chrome> browsers)
        {
            this.Browsers    = browsers;
            this.CycleCoins  = cycleCoins;
            this.CycleResult = new CycleResult();

            new Thread(new ThreadStart(() => // Premium Thread
            {
                PremiumProcess();
                if (this.CycleResult.Count == 4)
                {
                    this.OnComplete(this, new CycleCompleteEventArgs(this.CycleResult));
                }
            })).Start();

            new Thread(new ThreadStart(() => // Discount Thread
            {
                DiscountProcess();
                if (this.CycleResult.Count == 4)
                {
                    this.OnComplete(this, new CycleCompleteEventArgs(this.CycleResult));
                }
            })).Start();
        }
Beispiel #2
0
        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 override void PassCycleResult(CycleResult result)
 {
     // Used to read values from the interpreter (i.e. output from the program)
     if (result.output != '\0') XNAGame.Instance.AddOutput(result.output);
 }
 public abstract void PassCycleResult(CycleResult result);
Beispiel #5
0
 public CycleCompleteEventArgs(CycleResult data, string message = "")
 {
     this.Message = message;
     this.Data    = data;
 }