Пример #1
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 = Exp(arg.Value);
            return(arg);
        }
Пример #2
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 = System.Math.Log((1 + arg.Value) / (1 - arg.Value)) / 2;
            return(arg);
        }
Пример #3
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 = System.Math.Round(args[0].AsDouble(), numberDigits);
            return(args[0]);
        }
Пример #4
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 = System.Math.Pow(arg1.Value, arg2.Value);
            return(arg1);
        }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #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()));
        }
Пример #8
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));
        }
Пример #9
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));
        }
Пример #10
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 = System.Math.Round(m_stopwatch.Elapsed.TotalSeconds);
            }
            else if (strFormat == "ms")
            {
                elapsed = System.Math.Round(m_stopwatch.Elapsed.TotalMilliseconds);
            }

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

            return(elapsed >= 0 ? new Variable(elapsed) : new Variable(elapsedStr));
        }
Пример #11
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);
        }
Пример #12
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], script);

            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);

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

            return(Variable.EmptyInstance);
        }
Пример #13
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");
            }

            Variable result = Run(args);

            return(result);
        }
Пример #14
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));
        }
Пример #15
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));
        }
Пример #16
0
        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);
        }
Пример #17
0
        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);
        }
Пример #18
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

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

            var queryStatement = Utils.GetSafeString(args, 0).Trim();

            using (SqlConnection con = new SqlConnection(CSCS_SQL.ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand(queryStatement, con))
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            return(new Variable(true));
        }
Пример #19
0
        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));
        }
Пример #20
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);
                bool allowRemote = Utils.GetSafeInt(args, 1, 0) == 1;
                DebuggerServer.AllowedClients = Utils.GetSafeString(args, 2);

                res = DebuggerServer.StartServer(port, allowRemote);
            }
            else
            {
                DebuggerServer.StopServer();
            }

            return(new Variable(res));
        }
Пример #21
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

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

            string language = args[0].AsString();
            string funcName = args[1].AsString();

            ParserFunction function = ParserFunction.GetFunction(funcName, script);
            CustomFunction custFunc = function as CustomFunction;

            Utils.CheckNotNull(funcName, custFunc, script);

            string body       = Utils.BeautifyScript(custFunc.Body, custFunc.Header);
            string translated = Translation.TranslateScript(body, language, script);

            Utils.PrintScript(translated, script);

            return(new Variable(translated));
        }
Пример #22
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args   = script.GetFunctionArgs();
            string          result = "";

            switch (m_mode)
            {
            case DataMode.ADD:
                Collect(args);
                break;

            case DataMode.SUBSCRIBE:
                Subscribe(args);
                break;

            case DataMode.SEND:
                result = SendData(s_data.ToString());
                s_data.Clear();
                break;
            }

            return(new Variable(result));
        }
Пример #23
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);
            string source    = Utils.GetSafeString(args, 0);
            string argument  = Utils.GetSafeString(args, 1);
            string parameter = Utils.GetSafeString(args, 2, "case");
            int    startFrom = Utils.GetSafeInt(args, 3, 0);
            int    length    = Utils.GetSafeInt(args, 4, source.Length);

            StringComparison comp = StringComparison.Ordinal;

            if (parameter.Equals("nocase") || parameter.Equals("no_case"))
            {
                comp = StringComparison.OrdinalIgnoreCase;
            }

            source   = source.Replace("\\\"", "\"");
            argument = argument.Replace("\\\"", "\"");

            switch (m_mode)
            {
            case Mode.CONTAINS:
                return(new Variable(source.IndexOf(argument, comp) >= 0));

            case Mode.STARTS_WITH:
                return(new Variable(source.StartsWith(argument, comp)));

            case Mode.ENDS_WITH:
                return(new Variable(source.EndsWith(argument, comp)));

            case Mode.INDEX_OF:
                return(new Variable(source.IndexOf(argument, startFrom, comp)));

            case Mode.EQUALS:
                return(new Variable(source.Equals(argument, comp)));

            case Mode.REPLACE:
                return(new Variable(source.Replace(argument, parameter)));

            case Mode.UPPER:
                return(new Variable(source.ToUpper()));

            case Mode.LOWER:
                return(new Variable(source.ToLower()));

            case Mode.TRIM:
                return(new Variable(source.Trim()));

            case Mode.SUBSTRING:
                startFrom = Utils.GetSafeInt(args, 1, 0);
                length    = Utils.GetSafeInt(args, 2, source.Length);
                length    = System.Math.Min(length, source.Length - startFrom);
                return(new Variable(source.Substring(startFrom, length)));

            case Mode.BEETWEEN:
            case Mode.BEETWEEN_ANY:
                int index1 = source.IndexOf(argument, comp);
                int index2 = m_mode == Mode.BEETWEEN ? source.IndexOf(parameter, index1 + 1, comp) :
                             source.IndexOfAny(parameter.ToCharArray(), index1 + 1);
                startFrom = index1 + argument.Length;

                if (index1 < 0 || index2 < index1)
                {
                    throw new ArgumentException("Couldn't extract string between [" + argument +
                                                "] and [" + parameter + "] + from " + source);
                }
                string result = source.Substring(startFrom, index2 - startFrom);
                return(new Variable(result));
            }

            return(new Variable(-1));
        }