protected override Variable Evaluate(ParsingScript script) { string pattern = Utils.GetItem(script).String; if (string.IsNullOrWhiteSpace(pattern)) { throw new ArgumentException("Couldn't extract process name"); } 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); if (script.TryCurrent() == Constants.NEXT_ARG) { script.Forward(); // eat end of statement semicolon } return(new Variable(results)); }
protected override Parser.Result Evaluate(string data, ref int from) { string pattern = Utils.GetItem(data, ref from).String; if (string.IsNullOrWhiteSpace(pattern)) { throw new ArgumentException("Couldn't extract process name"); } int MAX_PROC_NAME = 26; m_interpreter.AppendOutput(Utils.GetLine()); m_interpreter.AppendOutput(String.Format("{0} {1} {2} {3} {4}", "Process Id".PadRight(15), "Process Name".PadRight(MAX_PROC_NAME), "Working Set".PadRight(15), "Virt Mem".PadRight(15), "CPU Time".PadRight(25))); Process[] processes = Process.GetProcessesByName(pattern); List <Parser.Result> results = new List <Parser.Result>(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]; 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 Parser.Result(Double.NaN, string.Format("{0,15} {1," + MAX_PROC_NAME + "} {2,15} {3,15} {4,25}", pr.Id, procTitle, workingSet, virtMemory, procTime))); m_interpreter.AppendOutput(results.Last().String); } m_interpreter.AppendOutput(Utils.GetLine()); if (data.Length > from && data[from] == Constants.NEXT_ARG) { from++; // eat end of statement semicolon } return(new Parser.Result(Double.NaN, null, results)); }
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)); }
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)); }
protected override Parser.Result Evaluate(string data, ref int from) { string dirname = (data.Length <= from || data[from] == Constants.END_STATEMENT) ? Directory.GetCurrentDirectory() : Utils.GetToken(data, ref from, Constants.END_ARG_ARRAY); try { var results = Directory.EnumerateFiles(dirname); m_interpreter.AppendOutput("----- Files in [" + dirname + "] -----"); foreach (string filename in results) { m_interpreter.AppendOutput(filename); } m_interpreter.AppendOutput(Utils.GetLine()); } catch (Exception exc) { throw new ArgumentException("Could not list directory: " + exc.Message); } return(new Parser.Result()); }