void Camera_OnNewFrame()
        {
            if (_isClosing)
            {
                return;
            }

            try {
                Bitmap image = _cameraControl.Camera.GetCurrentBitmap;

                var found = GetDetectedImage(image);

                if (found == UCProgramItem.ProgramItemEnum.NA)
                {
                }
                else if (_lastDetectedItem != found && found == UCProgramItem.ProgramItemEnum.Start)
                {
                    say("Running your program");

                    _currentRunningIndex = 0;

                    flowLayoutPanel1.Invoke(new Action(() => {
                        var item = (UCProgramItem)flowLayoutPanel1.Controls[_currentRunningIndex];

                        item.BackColor = Color.Green;

                        _executor.StartScriptASync(item.GetCode());
                    }));
                }
                else if (_lastDetectedItem != found)
                {
                    flowLayoutPanel1.Invoke(new Action(() => Invokers.AddControl(flowLayoutPanel1, new UCProgramItem(found))));

                    say(string.Format("Added {0} command", found));
                }

                _lastDetectedItem = found;

                // Rather than creating a new bitmap for the picturebox, we simply overwrite the bitmap data with the bmTmp data
                // This way, when the bmpTmp is destroyed from the using, the picturebox has the brand new image data
                pictureBox1.Invoke(new Action(() => EZ_B.Camera.CopyBitmapMemory(image, (Bitmap)pictureBox1.Image)));

                Invokers.SetRefresh(pictureBox1);
            } catch (Exception ex) {
                Invokers.SetAppendText(tbLog, true, ex.ToString());

                Invokers.SetEnabled(btnAttachCamera, true);
            }
        }
Пример #2
0
 public void ExecEZScript(string script)
 {
     if (script != "")
     {
         _executor_3.StartScriptASync(script);
         EZ_Builder.Invokers.SetAppendText(botConsole, true, "Script {0} started", script);
     }
     return;
 }
Пример #3
0
        // Executed when we received event from Synbot - Bot message received either as
        // a response to a query or in a raised event
        //
        string Messagereceived_processing(string message)
        {
            string EZMessage = string.Empty; string paramsay = string.Empty; string messtolog = string.Empty;

            ///If parameter script to be launched when we received a bot response
            ExecEZScript(_cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_RESPONSE_SCRIPT_VALUE].ToString());
            //Unstring bot Response to separate text response from EZB commands in several separate strings EZMessage and EZCmd []
            //Bot response can be formatted as textresponse%EZB Command1%EZBcommand2%... with the % separator delimiting the EZB Commands
            //
            // For DEBUG ONLY EZ_Builder.Invokers.SetAppendText(botConsole, true, "{0} : {1}", "DEBUG", message);
            if (message == string.Empty)
            {
                // If bot Emty response message is configured - send the corresponding message to the bot
                //
                // For DEBUG ONLY   EZ_Builder.Invokers.SetAppendText(botConsole, true, "{0}", "DEBUGEVENTNO");
                string mess1 = _cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_DEFAULT_ANSWER_MESSAGE].ToString();
                if (mess1 != string.Empty)
                {
                    flagmessageerror = true;
                    Bot_Query(mess1);
                }

                //    if (event1 != string.Empty) synbot.Bot_raiseevent(event1);
                return(string.Empty);
            }
            string[] botPart        = message.Split('%');
            bool     switchexecutor = false;
            // Purging the text message from bad caracters to avoid errors in EZ Say command
            StringBuilder sb = new StringBuilder(botPart[0].ToLower());

            sb.Replace("[", ""); sb.Replace("]", ""); sb.Replace("_", " "); sb.Replace('\t', ' ');
            sb.Replace('\n', ' '); sb.Replace('\r', ' '); sb.Replace("   ", " "); sb.Replace("  ", " ");
            EZMessage = sb.ToString();
            bool flagtosay = true;

            // If text message begin with | the message is not spoken but only displayed on Bot Console
            if (EZMessage != String.Empty)
            {
                if (sb[0] == '|')
                {
                    flagtosay = false;
                    EZMessage = EZMessage.Substring(1);
                }
            }
            // Set EZB variables
            // we need to test now content of messages and lauch cmd and sayEZB if included in options flag
            EZ_Builder.Scripting.VariableManager.SetVariable(_cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_RESPONSE_VARIABLE].ToString(), EZMessage);
            if (Convert.ToBoolean(_cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_FLAG_FULLLOG]))
            {
                messtolog = message;
            }
            else
            {
                messtolog = EZMessage;
            }
            // Message to Bot Console
            EZ_Builder.Invokers.SetAppendText(botConsole, true, "{0} : {1}", Synbot.Synbot.namebot, messtolog);
            // test content of messages and lauch cmd and sayEZB if includeded in options flag
            if (flagtosay)
            {
                if (Convert.ToBoolean(_cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_FLAG_SPEAK_RESPONSE]) && EZMessage != "")
                {
                    paramsay = "(\"" + EZMessage + "\")";
                    if (Convert.ToBoolean(_cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_FLAG_SPEAK_EZB]))
                    {
                        paramsay = "SayEZB" + paramsay;
                    }
                    else
                    {
                        paramsay = "Say" + paramsay;
                    }
                    _executor_4.StartScriptASync(paramsay);
                }
            }

            if (Convert.ToBoolean(_cf.STORAGE[ConfigurationDictionary._STORAGE_BOT_FLAG_EXEC_BOTCOMMAND]) && botPart.Length > 1)
            {
                for (int i = 1; i < botPart.Length; i++)
                {
                    if (botPart[i] != "" && botPart[i] != null)
                    {
                        // 2 executors are used for executing the EZ commands in the bot response
                        // If more than 2 commands script executing will be stopped for executing the next one
                        EZ_Builder.Invokers.SetAppendText(botConsole, true, "Commande :{0}", botPart[i]);
                        if (switchexecutor)
                        {
                            _executor_2.StartScriptASync(botPart[i].Replace("[", "(").Replace("]", ")").Replace("|", "\r\n"));
                            switchexecutor = true;
                        }
                        else
                        {
                            _executor_0.StartScriptASync(botPart[i].Replace("[", "(").Replace("]", ")").Replace("|", "\r\n"));
                            switchexecutor = true;
                        }
                    }
                }
            }
            return(messtolog);
        }