Exemplo n.º 1
0
        public override string CallBase()
        {
            var argsList = ProvidedArgs.First("keyevent");

            if (argsList == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.NullReferenceException, "Arguments cannot be null.", LineValue));
                return(null);
            }

            if (Main.AndroidDriver != null)
            {
                //FunctionHelpers.AndroidBack();
                AndroidKeyCode newcol = AndroidKeyCode.A;
                var            nofail = Enum.TryParse <AndroidKeyCode>(argsList.ToString().UnCleanString(), out newcol);
                if (!nofail)
                {
                    Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                          $"The Key Event {argsList.ToString()} could not be found.", LineValue));
                    return(null);
                }
                Commands.KeyEvent(newcol);
            }
            else
            {
                Main.IO.Print($"[DRIVERLESS] Keyevent {argsList.ToString()}");
            }
            return("");
        }
Exemplo n.º 2
0
        public override string CallBase()
        {
            if (Main.AndroidDriver == null)
            {
                Compiler.ExceptionListener.Throw("Cannot take screenshot without a connected device");
            }
            var path = ProvidedArgs.First("path");

            if (path == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.NullReferenceException, $"Path must be specified", LineValue));
                return(null);
            }
            var ss = Commands.GetScreenshot();

            try
            {
                ss.Save(path.ToString(), ImageFormat.Png);
            }
            catch
            {
                Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler(ExceptionType.CompilerException,
                                                                            $"Unexpected error saving screenshot to path {path.ToString()}", ""));
                ReturnBubble = new Token("bool", "False", "");
                return("");
            }
            ReturnBubble = new Token("bool", "True", "");
            return("");
        }
Exemplo n.º 3
0
        public override string CallBase()
        {
            var x   = (ProvidedArgs.First("intX"));
            var y   = (ProvidedArgs.First("intY"));
            var dur = (ProvidedArgs.First("duration"));

            if (x == null || y == null || dur == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.NullReferenceException,
                                                                      $"The function [{this.Name}] requires [{ExpectedArgs.Length}] TNumber arguments", LineValue));
                return(null);
            }
            double intX     = double.Parse(x.ToString());
            double intY     = double.Parse(y.ToString());
            double duration = double.Parse(dur.ToString());

            if (Main.AndroidDriver == null)
            {
                Main.IO.Print($"[DRIVERLESS] LongTouch x:{intX} y:{intY} duration:{duration}");
            }
            else
            {
                Commands.LongTap((int)intX, (int)intY, (int)duration);
            }
            double sleep = TokenParser.SleepDefaultTime;

            if (ProvidedArgs.List.Count > 3)
            {
                sleep = double.Parse((ProvidedArgs.First("sleep").ToString()));
            }
            FunctionHelpers.Sleep(sleep, Caller);
            return("");
        }
Exemplo n.º 4
0
        public override string CallBase()
        {
            var    sleep    = (ProvidedArgs.First("sleep"));
            double sleepnum = double.Parse(sleep.ToString());

            TokenParser.SleepDefaultTime = sleepnum;
            return("");
        }
Exemplo n.º 5
0
        public override string CallBase()
        {
            //find extensions
            var tryStart = Extensions.FirstOrDefault(f => f.Name == "Start") as ExtensionStart;
            var tryPrint = Extensions.FirstOrDefault(f => f.Name == "Print") as ExtensionPrint;
            var tryColor = Extensions.FirstOrDefault(f => f.Name == "Color") as ExtensionColor;
            var tryStop  = Extensions.FirstOrDefault(f => f.Name == "Stop") as ExtensionStop;

            if (tryStart != null)
            {
                _watch = Stopwatch.StartNew();
            }
            if (tryPrint != null)
            {
                if (_watch != null)
                {
                    var elapsedMs = _watch.ElapsedMilliseconds;
                    var color     = ConsoleColor.Gray;
                    if (tryColor != null)
                    {
                        var          colorParam = tryColor.Extend();
                        ConsoleColor newcol     = ConsoleColor.Gray;
                        var          nofail     = Enum.TryParse <ConsoleColor>(colorParam[0].ToString(), out newcol);
                        if (nofail)
                        {
                            color = newcol;
                        }
                    }
                    Main.IO.Print(elapsedMs, color, false);
                }
            }
            if (tryStop != null)
            {
                if (_watch != null)
                {
                    _watch.Stop();
                }
            }
            if (_watch != null)
            {
                long output  = _watch.ElapsedMilliseconds;
                var  trytype = ProvidedArgs.First("type");
                if (trytype != null)
                {
                    if (trytype.ToString() == "ticks")
                    {
                        output = _watch.ElapsedTicks;
                    }
                }

                ReturnBubble = new Tokens.Token("timems", output.ToString(), Caller.Line);
            }
            return("");
        }
Exemplo n.º 6
0
        public override string CallBase()
        {
            var argsList = ProvidedArgs.First("value");

            if (argsList == null)
            {
                Caller.CallingFunction.ReturnToTopOfBubble(new Tokens.Token("null", "null", ""));
                return("");
            }
            Caller.CallingFunction.ReturnToTopOfBubble(argsList);
            return("");
        }
Exemplo n.º 7
0
        public override string CallBase()
        {
            string printmsg = "";
            var    arg      = ProvidedArgs.First("msg");

            if (arg != null)
            {
                printmsg = arg.ToString();
            }
            Compiler.ExceptionListener.Throw(printmsg, ExceptionType.UserCreatedException);
            return("");
        }
Exemplo n.º 8
0
        public override string CallBase()
        {
            var print    = "";
            var argsList = ProvidedArgs.First("serial");

            if (argsList != null)
            {
                print = argsList.ToString();
            }
            Commands.Connect(print);

            return("");
        }
Exemplo n.º 9
0
        public override string CallBase()
        {
            Concat();
            var print    = "";
            var argsList = ProvidedArgs.First("s");

            if (argsList != null)
            {
                print = argsList.ToString();
            }
            //color extension check
            var color        = ConsoleColor.Gray;
            var findColorExt = Extensions.FirstOrDefault(f => f.Name == "Color") as ExtensionColor;

            if (findColorExt != null)
            {
                var          param  = findColorExt.Extend();
                ConsoleColor newcol = ConsoleColor.Gray;
                var          nofail = Enum.TryParse <ConsoleColor>(param[0].ToString(), out newcol);
                if (nofail)
                {
                    color = newcol;
                }
            }
            //try to escape, and if escaping fails fallback on the original string
            string output = print + String.Join("", concatStrings);

            try
            {
                output = System.Text.RegularExpressions.Regex.Unescape(print + String.Join("", concatStrings));
            }
            catch (Exception e)
            {
                if (!(e is ArgumentException) || !(e is ArgumentNullException))
                {
                    Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException, $"Unexpected input: {output}", LineValue));
                    return(null);
                }
            }
            Main.IO.Print(output.UnCleanString(), color, false);


            //clear extensions after done
            concatStrings = new List <string>();
            Extensions    = new List <EDefinition>();
            return(print);
        }
Exemplo n.º 10
0
        public override string CallBase()
        {
            var print    = "";
            var argsList = ProvidedArgs.First("app");

            if (argsList != null)
            {
                print = argsList.ToString();
            }
            if (Main.AndroidDriver == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.DriverException,
                                                                      $"Cannot set the app package without having a device connected. Please connect to a device first.", LineValue));
                return(null);
            }
            Commands.SetAppPackage(print);
            return(print);
        }
Exemplo n.º 11
0
        public override string CallBase()
        {
            var x = (ProvidedArgs.First("intX"));
            var y = (ProvidedArgs.First("intY"));

            if (x == null || y == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.NullReferenceException,
                                                                      $"The function [{this.Name}] requires [{ExpectedArgs.Length}] arguments", LineValue));
                return("");
            }
            double intX = 0;
            bool   tryX = double.TryParse(x.ToString(), out intX);
            double intY = 0;
            bool   tryY = double.TryParse(y.ToString(), out intY);

            if (!tryX || !tryY)
            {
                Compiler.ExceptionListener.Throw($"Cannot get numbers from [{x.ToString()},{y.ToString()}]");
                return("");
            }
            if (Main.AndroidDriver == null)
            {
                Main.IO.Print($"[DRIVERLESS] Touch x:{intX} y:{intY}");
            }
            else
            {
                Commands.Tap((int)intX, (int)intY);
            }
            double sleep = TokenParser.SleepDefaultTime;

            if (ProvidedArgs.List.Count > 2)
            {
                sleep = 0;
                bool trySleep = double.TryParse(ProvidedArgs.First("sleep").ToString(), out sleep);
                if (!trySleep)
                {
                    Compiler.ExceptionListener.Throw($"Cannot get numbers from [{ProvidedArgs.First("sleep").ToString()}]");
                    return("");
                }
            }
            FunctionHelpers.Sleep(sleep, Caller);
            return("");
        }
Exemplo n.º 12
0
        public override string CallBase()
        {
            var tryBlock = ProvidedArgs.First("invoke");

            if (tryBlock == null)
            {
                Compiler.ExceptionListener.Throw("Function Try must have an invoked function");
            }
            var tryfunc = FunctionStack.First(tryBlock.ToString());

            if (tryfunc == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                      $"Cannot find the invoked function.", LineValue));
            }

            var catchExt = Extensions.FirstOrDefault(f => f.Name == "Catch") as ExtensionCatch;

            if (catchExt == null)
            {
                Compiler.ExceptionListener.Throw("Function Try must have `Catch` extension");
            }
            var catchBlock = catchExt.Extend();

            if (catchBlock.ElementAtOrDefault(0) == null)
            {
                Compiler.ExceptionListener.Throw("Invoke for Catch block cannot be null");
            }
            var catchfunc = FunctionStack.First(catchBlock[0].ToString());

            if (catchfunc == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                      $"Cannot find the invoked function.", LineValue));
            }

            Compiler.ExceptionListener.TryCatchEventStack.Add(new Exceptions.TryCatchEvent(tryfunc, catchfunc));

            tryfunc.TryParse(new TFunction(Caller.Function, new List <EDefinition>(), tryfunc.GetInvokeProperties(), Caller.CallingFunction));


            return("");
        }
Exemplo n.º 13
0
        public override string CallBase()
        {
            var argsList = ProvidedArgs.First("s");

            if (argsList == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.NullReferenceException, "Arguments cannot be null.", LineValue));
                return(null);
            }
            if (Main.AndroidDriver != null)
            {
                Commands.SendText(argsList.ToString());
            }
            else
            {
                Main.IO.Print($"[DRIVERLESS] text {argsList.ToString()}");
            }
            return("");
        }
Exemplo n.º 14
0
        public override string CallBase()
        {
            if (Main.AndroidDriver == null)
            {
                Compiler.ExceptionListener.Throw("Cannot check screen without a connected device");
                return(null);
            }
            var path = ProvidedArgs.First("path");

            if (path == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.NullReferenceException, $"Invoke function cannot be null.", LineValue));
                return(null);
            }
            var prop = CheckProperty();

            try
            {
                var ret = Commands.GetImageCoordinates(path.ToString(), prop);
                if (ret == null)
                {
                    ReturnBubble = new Tokens.Token("null", "null", "");
                    return("");
                }
                string[] ouput = new string[] { ret[0].ToString(), ret[1].ToString() };

                ReturnBubble = new TArray("arr", ouput, "");
            }
            catch (Exception e)
            {
                if (e is System.IO.FileNotFoundException)
                {
                    Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.DriverException,
                                                                          $"File could not be found: {path.ToString()}"));
                    return(null);
                }
                Console.WriteLine(e);
                Compiler.ExceptionListener.Throw(new ExceptionHandler("[73]Unexpected error with CheckScreen()"));
                return(null);
            }
            return("");
        }
Exemplo n.º 15
0
        public override string CallBase()
        {
            double time = 0;

            if (ProvidedArgs.First("time") != null)
            {
                bool tryfail = double.TryParse(ProvidedArgs.First("time").ToString(), out time);
                if (!tryfail)
                {
                    time = TokenParser.SleepDefaultTime;
                }
            }
            else
            {
                time = TokenParser.SleepDefaultTime;
            }
            //changed to utilities sleep for cancelations
            Utilities.Sleep((int)Math.Ceiling(time));
            return("");
        }
Exemplo n.º 16
0
        public override string CallBase()
        {
            var prov = ProvidedArgs.First("invoke");

            if (prov == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                      $"{this.Name } Arguments cannot be null."));
                return(null);
            }
            var func = FunctionStack.First(prov.ToString());

            if (func == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                      $"Invoke function [{prov.ToString()}] could not be found"));
                return(null);
            }
            if (!func.Async)
            {
                Compiler.ExceptionListener.Throw($"{this.Name} The invoked function must be marked async",
                                                 ExceptionType.SystemException);
                return(null);
            }
            try
            {
                Thread th = new Thread(() =>
                {
                    func.SetInvokeProperties(new string[] { }, Caller.CallingFunction.LocalVariables.List, Caller.CallingFunction.ProvidedArgs.List);
                    func.TryParse(new TFunction(Caller.Function, new List <EDefinition>(), this.GetInvokeProperties(), Caller.CallingFunction));
                });
                th.Start();
            }catch
            {
                Compiler.ExceptionListener.Throw($"Async thread reached an unexpected error.", ExceptionType.SystemException);
                return(null);
            }
            return("");
        }
Exemplo n.º 17
0
        public override string CallBase()
        {
            var x1  = (ProvidedArgs.First("intX1"));
            var y1  = (ProvidedArgs.First("intY1"));
            var x2  = (ProvidedArgs.First("intX2"));
            var y2  = (ProvidedArgs.First("intY2"));
            var dur = (ProvidedArgs.First("duration"));

            if (x1 == null || y1 == null || x2 == null || y2 == null || dur == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.NullReferenceException,
                                                                      $"The function [{this.Name}] requires [{ExpectedArgs.Length}] TNumber arguments", LineValue));
                return(null);
            }
            double intX1    = double.Parse(x1.ToString());
            double intY1    = double.Parse(y1.ToString());
            double intX2    = double.Parse(x2.ToString());
            double intY2    = double.Parse(y2.ToString());
            double duration = double.Parse(dur.ToString());

            if (Main.AndroidDriver == null)
            {
                Main.IO.Print($"[DRIVERLESS] LongTouch x1:{intX1} y1:{intY1} x2:{intX2} y2:{intY2} duration:{duration}");
            }
            else
            {
                Commands.Swipe((int)intX1, (int)intY1, (int)intX2, (int)intY2, (int)duration);
            }
            double sleep = TokenParser.SleepDefaultTime;

            if (ProvidedArgs.List.Count > 5)
            {
                sleep = double.Parse((ProvidedArgs.First("sleep")).ToString());
            }
            FunctionHelpers.Sleep(sleep, Caller);
            return("");
        }
Exemplo n.º 18
0
        public override string CallBase()
        {
            var arg = ProvidedArgs.First("arr");

            if (arg == null)
            {
                Compiler.ExceptionListener.Throw($"Arguments for {this.Name} must not be null");
                return(null);
            }
            var args = new TArray("", arg.ToString(), "");

            if (args.Arguments == null)
            {
                Compiler.ExceptionListener.Throw($"Arguments for {this.Name} must be an array");
                return(null);
            }
            var props = new List <string>();

            props.AddRange(args.Arguments);
            var ret = AnalyzeScreen.SetDefaultTemplateOptions(props.ToArray());

            ReturnBubble = new TArray("templateOptions", ret, "");
            return("");
        }
Exemplo n.º 19
0
        public override string CallBase()
        {
            /*
             *
             * Since u always seem to forget, Caller.CallingFunction.Extensions to get the
             * Extensions hooked to the top level function this is being called from
             *
             * */
            var prop = Extensions.FirstOrDefault(f => f.Name == "Prop") as ExtensionProp;
            var arg  = ProvidedArgs.First("type");

            if (prop == null)
            {
                if (arg == null)
                {
                    Compiler.ExceptionListener.Throw("Arguments cannot be null without a Prop extension");
                }
                switch (arg.ToString())
                {
                case ("Extension"):
                    List <string> output = new List <string>();
                    foreach (var x in Caller.CallingFunction.Extensions)
                    {
                        output.Add(x.Name);
                    }
                    ReturnBubble = new TArray("arr", output.ToArray(), "");
                    return("");

                case ("UID"):    //ReadOnly
                    ReturnBubble = new Token("uid", UID.ToString(), "");
                    return("");

                case ("IsAnonymous"):    //ReadOnly
                    ReturnBubble = new Token("isAnonymous", (IsAnonymous) ? "True" : "False", "");
                    return("");

                case ("IsOverride"):    //ReadOnly
                    ReturnBubble = new Token("isOverride", (Override) ? "True" : "False", "");
                    return("");

                case ("IsSealed"):    //ReadOnly
                    ReturnBubble = new Token("isSealed", (Sealed) ? "True" : "False", "");
                    return("");

                case ("IsObsolete"):    //ReadOnly
                    ReturnBubble = new Token("isObsolete", (Obsolete) ? "True" : "False", "");
                    return("");
                }
            }
            else
            {
                var properties = prop.Extend();
                var fprop      = properties.ElementAtOrDefault(0);
                if (fprop == null)
                {
                    Compiler.ExceptionListener.Throw("Prop extension must have arguments");
                }
                if (arg != null)
                {
                    switch (arg.ToString())
                    {
                    case ("Extension"):
                        if (fprop == "Args")
                        {
                            var sprop = properties.ElementAtOrDefault(1);
                            if (sprop == null)
                            {
                                Compiler.ExceptionListener.Throw("Prop 'Args' must have a second parameter");
                            }
                            var get = Caller.CallingFunction.Extensions.FirstOrDefault(f => f.Name == sprop);
                            if (get == null)
                            {
                                ReturnBubble = new Token("null", "null", "");
                            }
                            else
                            {
                                ReturnBubble = new TArray("arr", get.Extend(Caller.CallingFunction), "");
                            }
                        }
                        return("");
                    }
                }
            }
            return("");
        }
Exemplo n.º 20
0
        public override string CallBase()
        {
            var prov = ProvidedArgs.First("bool");

            if (prov == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                      $"Arguments cannot be null.", LineValue));
                return(null);
            }
            bool flag    = (prov.ToString() == "True" || prov.ToString() == "true") ? true : false;
            var  andFlag = Extensions.FirstOrDefault(f => f.Name == "And");
            var  orFlag  = Extensions.FirstOrDefault(f => f.Name == "Or");

            if (orFlag != null)
            {
                var orExtensions = Extensions.Where(w => w.Name == "Or");
                foreach (var o in orExtensions)
                {
                    var      or        = o as ExtensionOr;
                    string[] param     = or.Extend();
                    bool     paramFlag = (param[0].ToString() == "True" || param[0].ToString() == "true") ? true : false;
                    if (paramFlag)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (andFlag != null)
            {
                var andExtensions = Extensions.Where(w => w.Name == "And");
                foreach (var a in andExtensions)
                {
                    var      and       = a as ExtensionAnd;
                    string[] param     = and.Extend();
                    bool     paramFlag = (param[0].ToString() == "True" || param[0].ToString() == "true") ? true : false;
                    if (!paramFlag)
                    {
                        flag = false;
                        break;
                    }
                }
            }

            if (flag)
            {
                //find then extension and call it
                var findThen = Extensions.FirstOrDefault(f => f.Name == "Then") as ExtensionThen;
                if (findThen != null)
                {
                    string[] thenFunc = findThen.Extend();
                    var      func     = FunctionStack.First(thenFunc[0].ToString());
                    if (func == null)
                    {
                        Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                              $"Cannot find the invoked function.", LineValue));
                        return(null);
                    }
                    //pass in invoke properties. shouldnt break with null
                    func.SetInvokeProperties(new string[] { }, Caller.CallingFunction.LocalVariables.List, Caller.CallingFunction.ProvidedArgs.List);
                    func.TryParse(new TFunction(Caller.Function, new List <EDefinition>(), findThen.GetInvokeProperties(), Caller.CallingFunction));
                }
                else
                {
                    Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                          $"[460]If function must have a Then Extension", LineValue));
                    return(null);
                }
            }
            else
            {
                //find else extension and call it
                var findElse = Extensions.FirstOrDefault(f => f.Name == "Else") as ExtensionElse;
                if (findElse != null)
                {
                    string[] elseFunc = findElse.Extend();
                    var      func     = FunctionStack.First(elseFunc[0].ToString());
                    if (func == null)
                    {
                        Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                              $"Cannot find the invoked function.", LineValue));
                        return(null);
                    }
                    func.SetInvokeProperties(new string[] { }, Caller.CallingFunction.LocalVariables.List, Caller.CallingFunction.ProvidedArgs.List);
                    func.TryParse(new TFunction(Caller.Function, new List <EDefinition>(), findElse.GetInvokeProperties(), Caller.CallingFunction));
                }
            }
            return("");
        }
Exemplo n.º 21
0
        public override string CallBase()
        {
            if (Main.AndroidDriver == null)
            {
                Compiler.ExceptionListener.Throw("Cannot check screen without a connected device");
                return(null);
            }
            var succFunc = ProvidedArgs.First("succFunc");
            var failFunc = ProvidedArgs.First("failFunc");
            var succPath = ProvidedArgs.First("succPath");
            var failPath = ProvidedArgs.First("failPath");

            if (succFunc == null || failFunc == null || succPath == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.NullReferenceException, $"Invoke function cannot be null.", LineValue));
                return(null);
            }
            var sf = FunctionStack.First(succFunc.ToString());
            var ff = FunctionStack.First(failFunc.ToString());

            if (sf == null || ff == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                      $"[198]Invoke function cannot be found.", LineValue));
                return(null);
            }
            sf.SetInvokeProperties(new string[] { }, Caller.CallingFunction.LocalVariables.List, Caller.CallingFunction.ProvidedArgs.List);
            ff.SetInvokeProperties(new string[] { }, Caller.CallingFunction.LocalVariables.List, Caller.CallingFunction.ProvidedArgs.List);
            //check for threshold extension
            var prop = CheckProperty();

            if (failPath != null)
            {
                try
                {
                    Commands.AnalyzeScreen(succPath.ToString(), failPath.ToString(), sf, ff, prop, this.Caller);
                }
                catch (Exception e)
                {
                    if (e is System.IO.FileNotFoundException)
                    {
                        Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.DriverException,
                                                                              $"File could not be found: {succPath.ToString()}, {failPath.ToString()}"));
                        return(null);
                    }
                    Compiler.ExceptionListener.Throw(new ExceptionHandler("[57]Unexpected error with CheckScreen()"));
                    return(null);
                }
            }
            else
            {
                try
                {
                    Commands.AnalyzeScreen(succPath.ToString(), sf, ff, prop, this.Caller);
                }
                catch (Exception e)
                {
                    if (e is System.IO.FileNotFoundException)
                    {
                        Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.DriverException,
                                                                              $"File could not be found: {succPath.ToString()}"));
                        return(null);
                    }
                    Compiler.ExceptionListener.Throw(new ExceptionHandler("[73]Unexpected error with CheckScreen()"));
                    return(null);
                }
            }

            return("");
        }
Exemplo n.º 22
0
        public override string CallBase()
        {
            this.IsLoop = true;
            var prov = ProvidedArgs.First("invoke");

            if (prov == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException, $"[247]Invoke function cannot be null.", LineValue));
                return(null);
            }
            var func = FunctionStack.First(prov.ToString());

            if (func == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException, $"[250]Invoke function cannot be null.", LineValue));
                return(null);
            }
            var findFor = Extensions.FirstOrDefault(f => f.Name == "For") as ExtensionFor;

            if (findFor != null && findFor.Extend() != null && findFor.Extend().ElementAtOrDefault(0) != null && findFor.Extend()[0] != "")
            {
                string[] forNumber         = findFor.Extend();
                int      forNumberAsNumber = int.Parse(forNumber[0].ToString());
                //if (forNumberAsNumber == 0)
                //    forNumberAsNumber = int.MaxValue;
                var tracer = new LoopTracer();
                Compiler.LoopTracerStack.Add(tracer);
                for (var x = 0; x <= forNumberAsNumber; x++)
                {
                    //gave a string as the parameter because number was causing srs problems
                    if (!TokenParser.Stop)
                    {
                        if (tracer.Break)
                        {
                            break;
                        }
                        if (tracer.Continue)
                        {
                            tracer.SetContinue(false);//reset continue
                        }
                        var passed = this.GetInvokeProperties();
                        if (passed != null)
                        {
                            var getFirstElement = passed.ElementAtOrDefault(0);
                            if (getFirstElement != null)
                            {
                                passed[0] = x.ToString();
                            }
                            else
                            {
                                passed = new string[] { x.ToString() };
                            }
                        }
                        else
                        {
                            passed = new string[] { x.ToString() };
                        }
                        func.SetInvokeProperties(new string[] { }, Caller.CallingFunction.LocalVariables.List, Caller.CallingFunction.ProvidedArgs.List);
                        func.TryParse(new TFunction(Caller.Function, new List <EDefinition>(), passed, this, tracer));
                    }
                    else
                    {
                        break;
                    }
                }
                Compiler.LoopTracerStack.Remove(tracer);
                tracer = null;
            }
            else
            {
                //LoopTracer tracer = new LoopTracer();
                //Compiler.LoopTracerStack.Add(tracer);
                //Tracer = tracer;
                var tracer = new LoopTracer();
                Compiler.LoopTracerStack.Add(tracer);
                var x = 0;
                while (true)
                {
                    //gave a string as the parameter because number was causing srs problems
                    if (!TokenParser.Stop)
                    {
                        if (tracer.Break)
                        {
                            break;
                        }
                        if (tracer.Continue)
                        {
                            tracer.SetContinue(false);//reset continue
                        }
                        var passed = this.GetInvokeProperties();
                        if (passed != null)
                        {
                            var getFirstElement = passed.ElementAtOrDefault(0);
                            if (getFirstElement != null)
                            {
                                passed[0] = x.ToString();
                            }
                            else
                            {
                                passed = new string[] { x.ToString() };
                            }
                        }
                        else
                        {
                            passed = new string[] { x.ToString() };
                        }
                        //Console.WriteLine(func.UID+JsonConvert.SerializeObject(tracer, Formatting.Indented));
                        func.SetInvokeProperties(new string[] { }, Caller.CallingFunction.LocalVariables.List, Caller.CallingFunction.ProvidedArgs.List);
                        func.TryParse(new TFunction(Caller.Function, new List <EDefinition>(), passed, this, tracer));
                        x++;
                        //Console.WriteLine("\t\t\t" +func.UID + ":" + string.Join(",",func.ProvidedArgs));
                        //Console.WriteLine(func.UID + JsonConvert.SerializeObject(func.ProvidedArgs, Formatting.Indented));
                    }
                    else
                    {
                        break;
                    }
                }
                //foreach (var ttt in Compiler.LoopTracerStack)
                //    Console.WriteLine("b"+func.UID + JsonConvert.SerializeObject(ttt, Formatting.Indented));
                Compiler.LoopTracerStack.Remove(tracer);
                //foreach(var ttt in Compiler.LoopTracerStack)
                //    Console.WriteLine("a"+func.UID + JsonConvert.SerializeObject(ttt, Formatting.Indented));
                tracer = null;
            }
            return("");
        }