protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);
            CSCS_SQL.CheckConnectionString(script, m_name);
            var spName = Utils.GetSafeString(args, 0);

            return(ExecuteSP(spName, null, args));
        }
Exemple #2
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name, true);
            string filename = args[0].AsString();
            string pathname = script.GetFilePath(filename);

            return(EncodeDecode(pathname, m_encode));
        }
Exemple #3
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            var tableName = Utils.GetSafeString(args, 0);

            return(GetColsData(tableName));
        }
Exemple #4
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name, true);
            Variable arg = args[0];

            arg.Value = Math.Acos(arg.Value);
            return(arg);
        }
Exemple #5
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            int numberDigits = Utils.GetSafeInt(args, 1, 0);

            args[0].Value = Math.Round(args[0].AsDouble(), numberDigits);
            return(args[0]);
        }
Exemple #6
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            script.MoveBackIf(Constants.START_GROUP);

            if (args.Count != m_args.Length)
            {
                throw new ArgumentException("Function [" + m_name + "] arguments mismatch: " +
                                            m_args.Length + " declared, " + args.Count + " supplied");
            }

            // 1. Add passed arguments as local variables to the Parser.
            RegisterArguments(args);

            // 2. Execute the body of the function.
            Variable      result     = null;
            ParsingScript tempScript = new ParsingScript(m_body);

            tempScript.ScriptOffset = m_parentOffset;
            if (m_parentScript != null)
            {
                tempScript.Char2Line      = m_parentScript.Char2Line;
                tempScript.Filename       = m_parentScript.Filename;
                tempScript.OriginalScript = m_parentScript.OriginalScript;
            }
            tempScript.ParentScript = script;
            tempScript.InTryBlock   = script.InTryBlock;

            if (script.Debugger != null)
            {
                result = script.Debugger.StepInFunctionIfNeeded(tempScript);
            }

            while (tempScript.Pointer < m_body.Length - 1 &&
                   (result == null || !result.IsReturn))
            {
                result = tempScript.ExecuteTo();
                tempScript.GoToNextStatement();
            }

            ParserFunction.PopLocalVariables();

            if (result == null)
            {
                result = Variable.EmptyInstance;
            }
            else
            {
                result.IsReturn = false;
            }

            return(result);
        }
Exemple #7
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            string name     = Utils.GetSafeString(args, 0);
            var    objValue = Statics.GetVariableValue(name, script);

            return(new Variable(objValue.ToString()));
        }
Exemple #8
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            var      query   = Utils.GetSafeString(args, 0);
            Variable results = GetData(query);

            return(results);
        }
Exemple #9
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            var connString = Utils.GetSafeString(args, 0);

            CSCS_SQL.ConnectionString = connString;
            return(Variable.EmptyInstance);
        }
Exemple #10
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 2, m_name, true);
            Variable arg1 = args[0];
            Variable arg2 = args[1];

            arg1.Value = Math.Pow(arg1.Value, arg2.Value);
            return(arg1);
        }
Exemple #11
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name, true);
            Variable arg = args[0];

            string result = arg.AsString();

            return(new Variable(result));
        }
Exemple #12
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 2, m_name);

            string name  = Utils.GetSafeString(args, 0);
            string value = Utils.GetSafeString(args, 1);
            bool   isSet = Statics.SetVariableValue(name, value, script);

            return(new Variable(isSet));
        }
Exemple #13
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            string json = args[0].AsString();

            Variable newVariable = Utils.CreateVariableFromJsonString(json);

            return(newVariable);
        }
Exemple #14
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);
            CSCS_SQL.CheckConnectionString(script, m_name);

            var  tableName = Utils.GetSafeString(args, 0);
            bool namesOnly = Utils.GetSafeInt(args, 1, 0) == 1;

            return(GetColsData(tableName, namesOnly));
        }
Exemple #15
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);
            string data = Utils.GetSafeString(args, 0);

            string sep    = Utils.GetSafeString(args, 1, "\t");
            var    option = Utils.GetSafeString(args, 2);

            return(Tokenize(data, sep, option));
        }
Exemple #16
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            string strFormat = Utils.GetSafeString(args, 0, "HH:mm:ss.fff");

            Utils.CheckNotEmpty(strFormat, m_name);

            string when = DateTime.Now.ToString(strFormat);

            return(new Variable(when));
        }
Exemple #17
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            for (int i = 0; i < args.Count; i++)
            {
                Console.Write(args[i].AsString());
            }
            Console.WriteLine();

            return(Variable.EmptyInstance);
        }
Exemple #18
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            if (m_mode == Mode.START)
            {
                m_stopwatch.Restart();
                return(Variable.EmptyInstance);
            }

            string strFormat  = Utils.GetSafeString(args, 0, "secs");
            string elapsedStr = "";
            double elapsed    = -1.0;

            if (strFormat == "hh::mm:ss.fff")
            {
                elapsedStr = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}",
                                           m_stopwatch.Elapsed.Hours, m_stopwatch.Elapsed.Minutes,
                                           m_stopwatch.Elapsed.Seconds, m_stopwatch.Elapsed.Milliseconds);
            }
            else if (strFormat == "mm:ss.fff")
            {
                elapsedStr = string.Format("{0:D2}:{1:D2}.{2:D3}",
                                           m_stopwatch.Elapsed.Minutes,
                                           m_stopwatch.Elapsed.Seconds, m_stopwatch.Elapsed.Milliseconds);
            }
            else if (strFormat == "mm:ss")
            {
                elapsedStr = string.Format("{0:D2}:{1:D2}",
                                           m_stopwatch.Elapsed.Minutes,
                                           m_stopwatch.Elapsed.Seconds);
            }
            else if (strFormat == "ss.fff")
            {
                elapsedStr = string.Format("{0:D2}.{1:D3}",
                                           m_stopwatch.Elapsed.Seconds, m_stopwatch.Elapsed.Milliseconds);
            }
            else if (strFormat == "secs")
            {
                elapsed = Math.Round(m_stopwatch.Elapsed.TotalSeconds);
            }
            else if (strFormat == "ms")
            {
                elapsed = Math.Round(m_stopwatch.Elapsed.TotalMilliseconds);
            }

            if (m_mode == Mode.STOP)
            {
                m_stopwatch.Stop();
            }

            return(elapsed >= 0 ? new Variable(elapsed) : new Variable(elapsedStr));
        }
Exemple #19
0
        protected override Variable Evaluate(ParsingScript script)
        {
            // Data buffer for incoming data.
            byte[] bytes = new byte[1024];

            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 3, Constants.CONNECTSRV);
            Utils.CheckPosInt(args[1]);

            string hostname  = args[0].String;
            int    port      = (int)args[1].Value;
            string msgToSend = args[2].String;

            if (string.IsNullOrWhiteSpace(hostname) || hostname.Equals("localhost"))
            {
                hostname = Dns.GetHostName();
            }

            try
            {
                IPHostEntry ipHostInfo = Dns.GetHostEntry(hostname);
                IPAddress   ipAddress  = ipHostInfo.AddressList[0];
                IPEndPoint  remoteEP   = new IPEndPoint(ipAddress, port);

                // Create a TCP/IP  socket.
                Socket sender = new Socket(AddressFamily.InterNetwork,
                                           SocketType.Stream, ProtocolType.Tcp);

                sender.Connect(remoteEP);

                Interpreter.Instance.AppendOutput("Connected to [" + sender.RemoteEndPoint.ToString() + "]", true);

                byte[] msg = Encoding.UTF8.GetBytes(msgToSend);
                sender.Send(msg);

                // Receive the response from the remote device.
                int    bytesRec = sender.Receive(bytes);
                string received = Encoding.UTF8.GetString(bytes, 0, bytesRec);
                Interpreter.Instance.AppendOutput("Received [" + received + "]", true);

                sender.Shutdown(SocketShutdown.Both);
                sender.Close();
            }
            catch (Exception exc)
            {
                throw new ArgumentException("Couldn't connect to server: (" + exc.Message + ")");
            }

            return(Variable.EmptyInstance);
        }
Exemple #20
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);
            CSCS_SQL.CheckConnectionString(script, m_name);

            var      query   = Utils.GetSafeString(args, 0);
            var      spArgs  = Utils.GetSafeVariable(args, 1);
            var      sp      = GetParameters(spArgs);
            Variable results = GetData(query, "", sp);

            return(results);
        }
        protected override Variable Evaluate(ParsingScript script)
        {
            List<Variable> args = script.GetFunctionArgs();
            script.MoveBackIf(Constants.START_GROUP);

            if (args.Count != m_args.Length)
            {
                throw new ArgumentException("Function [" + m_name + "] arguments mismatch: " +
                                    m_args.Length + " declared, " + args.Count + " supplied");
            }

            Variable result = Run(args);
            return result;
        }
        protected override Variable Evaluate(ParsingScript script)
        {
            List<Variable> args = script.GetFunctionArgs();
            Utils.CheckArgs(args.Count, 1, m_name);

            string json = args[0].AsString();

            Dictionary<int, int> d;
            json = Utils.ConvertToScript(json, out d);

            var tempScript = script.GetTempScript(json);
            Variable result = ExtractValue(tempScript);
            return result;
        }
Exemple #23
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            if (string.IsNullOrWhiteSpace(SqlLiteFunction.DBPath))
            {
                throw new ArgumentException("DB has not been initialized.");
            }

            string query     = Utils.GetSafeString(args, 0);
            string tableName = Utils.GetSafeString(args, 1);

            return(GetData(query, tableName));
        }
Exemple #24
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 2, m_name);
            var result = args[0].Value;

            for (int i = 1; i < args.Count; i++)
            {
                if (args[i].Value > result)
                {
                    result = args[i].Value;
                }
            }
            return(new Variable(result));
        }
        protected override Variable Evaluate(ParsingScript script)
        {
            List<Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 2, m_name);
            string filename = Utils.GetSafeString(args, 0);
            string destination = Utils.GetSafeString(args, 1);

            Variable result = new Variable(Variable.VarType.ARRAY);
            result.Tuple.Add(new Variable(Constants.GET_FILE_FROM_DEBUGGER));
            result.Tuple.Add(new Variable(filename));
            result.Tuple.Add(new Variable(destination));

            result.ParsingToken = m_name;

            return result;
        }
Exemple #26
0
        protected override Variable Evaluate(ParsingScript script)
        {
            string          res  = "OK";
            List <Variable> args = script.GetFunctionArgs();

            if (m_start)
            {
                int port = Utils.GetSafeInt(args, 0, 13337);
                res = DebuggerServer.StartServer(port);
            }
            else
            {
                DebuggerServer.StopServer();
            }

            return(new Variable(res));
        }
Exemple #27
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name, true);
            string pattern = args[0].AsString();

            int MAX_PROC_NAME = 26;

            Interpreter.Instance.AppendOutput(Utils.GetLine(), true);
            Interpreter.Instance.AppendOutput(String.Format("{0} {1} {2} {3} {4} {5}",
                                                            "Process Id".PadRight(15), "Process Name".PadRight(MAX_PROC_NAME),
                                                            "Working Set".PadRight(15), "Virt Mem".PadRight(15),
                                                            "Start Time".PadRight(15), "CPU Time".PadRight(25)), true);

            Process[]       processes = Process.GetProcessesByName(pattern);
            List <Variable> results   = new List <Variable>(processes.Length);

            for (int i = 0; i < processes.Length; i++)
            {
                Process pr         = processes[i];
                int     workingSet = (int)(((double)pr.WorkingSet64) / 1000000.0);
                int     virtMemory = (int)(((double)pr.VirtualMemorySize64) / 1000000.0);
                string  procTitle  = pr.ProcessName + " " + pr.MainWindowTitle.Split(null)[0];
                string  startTime  = pr.StartTime.ToString();
                if (procTitle.Length > MAX_PROC_NAME)
                {
                    procTitle = procTitle.Substring(0, MAX_PROC_NAME);
                }
                string procTime = string.Empty;
                try
                {
                    procTime = pr.TotalProcessorTime.ToString().Substring(0, 11);
                }
                catch (Exception) { }

                results.Add(new Variable(
                                string.Format("{0,15} {1," + MAX_PROC_NAME + "} {2,15} {3,15} {4,15} {5,25}",
                                              pr.Id, procTitle,
                                              workingSet, virtMemory, startTime, procTime)));
                Interpreter.Instance.AppendOutput(results.Last().String, true);
            }
            Interpreter.Instance.AppendOutput(Utils.GetLine(), true);

            return(new Variable(results));
        }
Exemple #28
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 2, m_name);

            Variable all     = Utils.GetSafeVariable(args, 0);
            string   varName = Utils.GetSafeString(args, 1);
            int      index   = Utils.GetSafeInt(args, 2);

            var      function = ParserFunction.GetFunction(varName);
            Variable mapVar   = new Variable(Variable.VarType.ARRAY);

            if (all.Tuple == null)
            {
                return(Variable.EmptyInstance);
            }

            string currentValue = "";
            int    currentCount = 0;

            int globalCount = 0;

            for (int i = 0; i < all.Tuple.Count; i++)
            {
                Variable current = all.Tuple[i];
                if (current.Tuple == null || current.Tuple.Count < index)
                {
                    break;
                }
                string newValue = current.Tuple[index].AsString();
                if (currentValue != newValue)
                {
                    currentValue = newValue;
                    currentCount = 0;
                }
                mapVar.Tuple.Add(new Variable(currentCount));
                currentCount++;
                globalCount++;
            }

            ParserFunction.AddGlobalOrLocalVariable(varName,
                                                    new GetVarFunction(mapVar));
            return(mapVar);
        }
Exemple #29
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 2, m_name);

            Variable currentValue = Utils.GetSafeVariable(args, 0);
            Variable item         = Utils.GetSafeVariable(args, 1);

            currentValue.AddVariable(item);
            if (!currentValue.ParsingToken.Contains(Constants.START_ARRAY.ToString()))
            {
                ParserFunction.AddGlobalOrLocalVariable(currentValue.ParsingToken,
                                                        new GetVarFunction(currentValue));
            }

            return(currentValue);
        }
        //public static void PrintScriptColor(string script, ParsingScript parentSript)
        //{
        //    StringBuilder item = new StringBuilder();

        //    bool inQuotes = false;

        //    for (int i = 0; i < script.Length; i++)
        //    {
        //        char ch = script[i];
        //        inQuotes = ch == Constants.QUOTE ? !inQuotes : inQuotes;

        //        if (inQuotes)
        //        {
        //            Interpreter.Instance.AppendOutput(ch.ToString());
        //            continue;
        //        }
        //        if (!Constants.TOKEN_SEPARATION.Contains(ch))
        //        {
        //            item.Append(ch);
        //            continue;
        //        }
        //        if (item.Length > 0)
        //        {
        //            string token = item.ToString();
        //            ParserFunction func = ParserFunction.GetFunction(token, parentSript);
        //            bool isNative = Translation.IsNativeWord(token);
        //            if (func != null || isNative)
        //            {
        //                ConsoleColor col = isNative || func.isNative ? ConsoleColor.Green :
        //                                               func.isGlobal ? ConsoleColor.Magenta :
        //                                                   ConsoleColor.Gray;
        //                Utils.PrintColor(token, col);
        //            }
        //            else
        //            {
        //                Interpreter.Instance.AppendOutput(token);
        //            }
        //            item.Length = 0;
        //        }
        //        Interpreter.Instance.AppendOutput(ch.ToString());
        //    }
        //}

#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
        public static Variable RunCompiled(string functionName, string argsString)
        {
            string          adjArgs   = PrepareArgs(argsString, true);
            ParsingScript   argScript = new ParsingScript(adjArgs);
            List <Variable> args      = argScript.GetFunctionArgs();

            //ParserFunction function = ParserFunction.GetFunction(functionName, null);
            //if (function is CustomCompiledFunction)
            //{
            //    CustomCompiledFunction customFunction = function as CustomCompiledFunction;
            //    Variable result = customFunction.Run(args);
            //    if (result != null)
            //    {
            //        return result;
            //    }
            //}
            return(Calculate(functionName, argsString));
        }