Exemplo n.º 1
0
        public Interpreter()
        {
            var cache = System.IO.Path.Combine(Environment.CurrentDirectory, System.IO.Path.Combine("cache"));

            if (!System.IO.Directory.Exists(cache))
            {
                System.IO.Directory.CreateDirectory(cache);
            }

            var settings = new CefSettings()
            {
                CachePath = cache
            };

            Cef.Initialize(settings);

            InitializeComponent();
            //Type[] type = System.Type.GetTypes("CefPreter.Function." + Name);


            Browser          = new Browser.Browser();
            Browser.Chromium = Chromium;

            Processed  = true;
            Completed += Stop;
        }
Exemplo n.º 2
0
        public async override Task <ExpressionResult> Execute(Browser.Browser Browser, CefMemory Memory, Interpreter.CallBackEventHandler ceh = null, Action log = null)
        {
            ExpressionResult res = ExpressionResult.OK;

            if (expressions != null)
            {
                for (int i = 0; i < expressions.Count; i++)
                {
                    if (stop)
                    {
                        return(ExpressionResult.Error);
                    }
                    res = await expressions[i].Execute(Browser, Memory, ceh, log);

                    switch (res)
                    {
                    case ExpressionResult.CallBack:
                        ceh?.Invoke(Memory);
                        break;

                    case ExpressionResult.CondFalse:
                    case ExpressionResult.WhileCondFalse:
                        res = ExpressionResult.OK;
                        i++;
                        break;

                    case ExpressionResult.WhileCondTrue:
                        res = await expressions[i + 1].Execute(Browser, Memory, ceh, log);
                        i--;
                        break;

                    default:
                        break;
                    }
                }
            }


            return(res);
        }
Exemplo n.º 3
0
 public abstract Task <ExpressionResult> Execute(Browser.Browser Browser, CefMemory Memory, Interpreter.CallBackEventHandler ceh = null, Action log = null);
Exemplo n.º 4
0
        public async override Task <ExpressionResult> Execute(Browser.Browser browser, CefMemory memory, Interpreter.CallBackEventHandler ceh = null, Action log = null)
        {
            ExpressionResult res = ExpressionResult.OK;

            Types.Variable result = null;

            if (functions.Count > 0)
            {
                if (functions[0].GetType().Name == "CLBCK")
                {
                    res = ExpressionResult.CallBack;
                }

                foreach (Function.Function f in functions.OrEmptyIfNull())
                {
                    if (stop)
                    {
                        return(ExpressionResult.Error);
                    }
                    var func = f.Clone() as Function.Function;


                    if (func.GetType().Name == "AString" || func.GetType().Name == "ANumber")
                    {
                        memory.Remove(func.Parameters[0].Name, true);
                    }
                    func.Parameters = memory.UnpackAllVariables(func.Parameters);


                    result = await func.Exec(browser);

                    if (func.GetType().Name == "If")
                    {
                        if ((int)((Types.Number)result).Value == 0)
                        {
                            res = ExpressionResult.CondFalse;
                        }
                        else
                        {
                            res = ExpressionResult.CondTrue;
                        }
                    }
                    else if (func.GetType().Name == "While")
                    {
                        if ((int)((Types.Number)result).Value == 1)
                        {
                            res = ExpressionResult.WhileCondTrue;
                        }
                        else
                        {
                            res = ExpressionResult.WhileCondFalse;
                        }
                    }



                    if (result != null)
                    {
                        memory.Set(result);
                    }
                    log?.Invoke();
                }
            }
            return(res);
        }