public Task <ExecutionResult> Execute(IInteractiveWindow window, string arguments) { var finder = new FileFinder(arguments); var eval = window.Evaluator as BasePythonReplEvaluator; if (eval != null && eval.CurrentOptions != null) { finder.Search(eval.CurrentOptions.WorkingDirectory); finder.SearchAll(eval.CurrentOptions.SearchPaths, ';'); } finder.ThrowIfNotFound(); string commandPrefix = "$"; string lineBreak = window.TextView.Options.GetNewLineCharacter(); IEnumerable <string> lines = File.ReadLines(finder.Filename); IEnumerable <string> submissions; if (eval != null) { submissions = eval.JoinCode(lines).Where(CommentPrefixPredicate); } else { // v1 behavior, will probably never be hit, but if someone was developing their own IReplEvaluator // and using this class it would be hit. var submissionList = new List <string>(); var currentSubmission = new List <string>(); foreach (var line in lines) { if (line.StartsWith(_commentPrefix)) { continue; } if (line.StartsWith(commandPrefix)) { AddSubmission(submissionList, currentSubmission, lineBreak); submissionList.Add(line); currentSubmission.Clear(); } else { currentSubmission.Add(line); } } AddSubmission(submissionList, currentSubmission, lineBreak); submissions = submissionList; } window.Submit(submissions); return(ExecutionResult.Succeeded); }
public Task<ExecutionResult> Execute(IInteractiveWindow window, string arguments) { var finder = new FileFinder(arguments); var eval = window.Evaluator as BasePythonReplEvaluator; if (eval != null && eval.CurrentOptions != null) { finder.Search(eval.CurrentOptions.WorkingDirectory); finder.SearchAll(eval.CurrentOptions.SearchPaths, ';'); } finder.ThrowIfNotFound(); string commandPrefix = "$"; string lineBreak = window.TextView.Options.GetNewLineCharacter(); IEnumerable<string> lines = File.ReadLines(finder.Filename); IEnumerable<string> submissions; if (eval != null) { submissions = eval.JoinCode(lines).Where(CommentPrefixPredicate); } else { // v1 behavior, will probably never be hit, but if someone was developing their own IReplEvaluator // and using this class it would be hit. var submissionList = new List<string>(); var currentSubmission = new List<string>(); foreach (var line in lines) { if (line.StartsWith(_commentPrefix)) { continue; } if (line.StartsWith(commandPrefix)) { AddSubmission(submissionList, currentSubmission, lineBreak); submissionList.Add(line); currentSubmission.Clear(); } else { currentSubmission.Add(line); } } AddSubmission(submissionList, currentSubmission, lineBreak); submissions = submissionList; } window.Submit(submissions); return ExecutionResult.Succeeded; }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { List<string> submissions = new List<string>(); List<string> lines = new List<string>(); arguments = arguments.Trim(); if (arguments.StartsWith("\"") && arguments.EndsWith("\"")) { arguments = arguments.Substring(1, arguments.Length - 2); } string commandPrefix = (string)window.GetOptionValue(ReplOptions.CommandPrefix); string lineBreak = window.TextView.Options.GetNewLineCharacter(); var eval = window.Evaluator as JReplEvaluator; var debugEval = window.Evaluator as JDebugReplEvaluator; if (eval != null) { window.Submit(eval.SplitCode(File.ReadAllText(arguments)).Where(CommentPrefixPredicate)); return ExecutionResult.Succeeded; } else if (debugEval != null) { window.Submit(debugEval.SplitCode(File.ReadAllText(arguments)).Where(CommentPrefixPredicate)); return ExecutionResult.Succeeded; } else { // v1 beahvior, will probably never be hit, but if someone was developing their own IReplEvaluator // and using this class it would be hit. using (var stream = new StreamReader(arguments)) { string line; while ((line = stream.ReadLine()) != null) { if (line.StartsWith(_commentPrefix)) { continue; } if (line.StartsWith(commandPrefix)) { AddSubmission(submissions, lines, lineBreak); submissions.Add(line); lines.Clear(); } else { lines.Add(line); } } } AddSubmission(submissions, lines, lineBreak); window.Submit(submissions); return ExecutionResult.Succeeded; } }