Пример #1
0
        protected override Variable Evaluate(ParsingScript script)
        {
            string        search   = Utils.GetStringOrVarValue(script);
            List <string> patterns = Utils.GetFunctionArgs(script);

            bool ignoreCase = true;

            if (patterns.Count > 0 && patterns.Last().Equals("case"))
            {
                ignoreCase = false;
                patterns.RemoveAt(patterns.Count - 1);
            }
            if (patterns.Count == 0)
            {
                patterns.Add("*.*");
            }

            List <Variable> results = null;

            try {
                string        pwd   = Directory.GetCurrentDirectory();
                List <string> files = Utils.GetStringInFiles(pwd, search, patterns.ToArray(), ignoreCase);

                results = Utils.ConvertToResults(files.ToArray(), true);
            } catch (Exception exc) {
                throw new ArgumentException("Couldn't find pattern: " + exc.Message);
            }

            return(new Variable(results));
        }
Пример #2
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <string> patterns = Utils.GetFunctionArgs(script);

            if (patterns.Count == 0)
            {
                patterns.Add("*.*");
            }

            List <Variable> results = null;

            try
            {
                string        pwd   = Directory.GetCurrentDirectory();
                List <string> files = Utils.GetFiles(pwd, patterns.ToArray());

                results = Utils.ConvertToResults(files.ToArray(), true);
            }
            catch (Exception exc)
            {
                throw new ArgumentException("Couldn't list directory: " + exc.Message);
            }

            return(new Variable(results));
        }
Пример #3
0
        protected override Parser.Result Evaluate(string data, ref int from)
        {
            List <string> patterns = Utils.GetFunctionArgs(data, ref from);

            if (patterns.Count == 0)
            {
                patterns.Add("*.*");
            }

            List <Parser.Result> results = null;

            try
            {
                string        pwd   = Directory.GetCurrentDirectory();
                List <string> files = Utils.GetFiles(pwd, patterns.ToArray());

                //m_interpreter.AppendOutput("----- Found files with pattern [" +
                //                           string.Join(", ", patterns.ToArray()) + "] -----");
                results = new List <Parser.Result>(files.Count);
                foreach (string filename in files)
                {
                    results.Add(new Parser.Result(Double.NaN, filename));
                    //m_interpreter.AppendOutput(filename);
                }

                //m_interpreter.AppendOutput(Utils.GetLine());
            }
            catch (Exception exc)
            {
                throw new ArgumentException("Couldn't list directory: " + exc.Message);
            }

            return(new Parser.Result(Double.NaN, null, results));
        }
Пример #4
0
        protected override Parser.Result Evaluate(string data, ref int from)
        {
            string processName = Utils.GetItem(data, ref from).String;

            if (string.IsNullOrWhiteSpace(processName))
            {
                throw new ArgumentException("Couldn't extract process name");
            }

            List <string> args      = Utils.GetFunctionArgs(data, ref from);
            int           processId = -1;

            try
            {
                Process pr = Process.Start(processName, string.Join("", args.ToArray()));
                processId = pr.Id;
            }
            catch (System.ComponentModel.Win32Exception exc)
            {
                throw new ArgumentException("Couldn't start [" + processName + "]: " + exc.Message);
            }

            m_interpreter.AppendOutput("Process " + processName + " started, id: " + processId);
            return(new Parser.Result(processId));
        }
Пример #5
0
        protected override Parser.Result Evaluate(string data, ref int from)
        {
            List <string> args = Utils.GetFunctionArgs(data, ref from);

            m_interpreter.AppendOutput(string.Join("", args.ToArray()));

            return(new Parser.Result());
        }
Пример #6
0
        protected override Variable Evaluate(ParsingScript script)
        {
            string processName = Utils.GetItem(script).String;

            Utils.CheckNotEmpty(processName, "processName");

            List <string> args      = Utils.GetFunctionArgs(script);
            int           processId = -1;

            try {
                Process pr = Process.Start(processName, string.Join("", args.ToArray()));
                processId = pr.Id;
            } catch (Exception exc) {
                throw new ArgumentException("Couldn't start [" + processName + "]: " + exc.Message);
            }

            Interpreter.Instance.AppendOutput("Process " + processName + " started, id: " + processId, true);
            return(new Variable(processId));
        }
Пример #7
0
        protected override Parser.Result Evaluate(string data, ref int from)
        {
            string        search   = Utils.GetToken(data, ref from, Constants.QUOTE_ARRAY);
            List <string> patterns = Utils.GetFunctionArgs(data, ref from);

            bool ignoreCase = true;

            if (patterns.Count > 0 && patterns.Last().Equals("case"))
            {
                ignoreCase = false;
                patterns.RemoveAt(patterns.Count - 1);
            }
            if (patterns.Count == 0)
            {
                patterns.Add("*.*");
            }

            List <Parser.Result> results = null;

            try
            {
                string        pwd   = Directory.GetCurrentDirectory();
                List <string> files = Utils.GetStringInFiles(pwd, search, patterns.ToArray(), ignoreCase);

                m_interpreter.AppendOutput("----- Files containing [" + search + "] with pattern [" +
                                           string.Join(", ", patterns.ToArray()) + "] -----");
                results = new List <Parser.Result>(files.Count);
                foreach (string filename in files)
                {
                    results.Add(new Parser.Result(Double.NaN, filename));
                    m_interpreter.AppendOutput(filename);
                }
                m_interpreter.AppendOutput(Utils.GetLine());
            }
            catch (Exception exc)
            {
                throw new ArgumentException("Couldn't find pattern: " + exc.Message);
            }

            return(new Parser.Result(Double.NaN, null, results));
        }