Beispiel #1
0
        public EvaluatorResult Evaluate(string input, string sourceFile)
        {
            OnEvaluateStarted(input, sourceFile);

            var evalResult = new EvaluatorResult();
            evalResult.InputComplete = true;
            evalResult.Input = input;
            evalResult.SourceFile = sourceFile;
            evalResult.HasErrors = false;
            evalResult.HasResult = false;

            string partialCommand = null;
            object result = null;
            bool resultSet = false;
            var errorwriter = new StringWriter();

            var oldPrinter = context.Report.SetPrinter(new StreamReportPrinter(errorwriter));

            try
            {
                partialCommand = evaluator.Evaluate(input, out result, out resultSet);
            }
            catch (Exception e)
            {
                evalResult.HasErrors = true;
                evalResult.Errors = new[]{e.ToString()};
            }
            finally
            {
                context.Report.SetPrinter(oldPrinter);
            }

            //// Partial input
            if (partialCommand != null)
            {
                evalResult.InputComplete = false;
                evalResult.Input = partialCommand;
            }
            string errorMessage = errorwriter.ToString();
            if (errorMessage.Length > 0)
            {
                //split the errors according to lines and parse each line
                //check if its errors or only warnings!
                var messages = errorMessage.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                var warnings = messages.Where(msg => IsMessage(msg, "warning")).ToList();
                var errors = messages.Where(msg => IsMessage(msg, "error")).ToList();

                evalResult.HasWarnings = warnings.Any();
                evalResult.Warnings = warnings.ToArray();

                var allErrors = evalResult.Errors ?? new string[0];
                allErrors = allErrors.Concat(errors).ToArray();
                evalResult.HasErrors = allErrors.Any();
                evalResult.Errors = allErrors;
            }

            if (resultSet)
            {
                evalResult.HasResult = true;
                evalResult.Result = result;
            }
            
            //process the input for code completion later on
            if(!evalResult.HasErrors)
                codeCompletion.ProcessInput(input, sourceFile);

            OnEvaluateCompleted(new EvaluateCompletedEventArgs(evalResult, null, false, null));
            return evalResult;
        }
Beispiel #2
0
        public EvaluatorResult Evaluate(string input, string sourceFile)
        {
            OnEvaluateStarted(input, sourceFile);

            var evalResult = new EvaluatorResult();

            evalResult.InputComplete = true;
            evalResult.Input         = input;
            evalResult.SourceFile    = sourceFile;
            evalResult.HasErrors     = false;
            evalResult.HasResult     = false;

            string partialCommand = null;
            object result         = null;
            bool   resultSet      = false;
            var    errorwriter    = new StringWriter();

            var oldPrinter = context.Report.SetPrinter(new StreamReportPrinter(errorwriter));

            try
            {
                partialCommand = evaluator.Evaluate(input, out result, out resultSet);
            }
            catch (Exception e)
            {
                evalResult.HasErrors = true;
                evalResult.Errors    = new[] { e.ToString() };
            }
            finally
            {
                context.Report.SetPrinter(oldPrinter);
            }

            //// Partial input
            if (partialCommand != null)
            {
                evalResult.InputComplete = false;
                evalResult.Input         = partialCommand;
            }
            string errorMessage = errorwriter.ToString();

            if (errorMessage.Length > 0)
            {
                //split the errors according to lines and parse each line
                //check if its errors or only warnings!
                var messages = errorMessage.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                var warnings = messages.Where(msg => IsMessage(msg, "warning")).ToList();
                var errors   = messages.Where(msg => IsMessage(msg, "error")).ToList();

                evalResult.HasWarnings = warnings.Any();
                evalResult.Warnings    = warnings.ToArray();

                var allErrors = evalResult.Errors ?? new string[0];
                allErrors            = allErrors.Concat(errors).ToArray();
                evalResult.HasErrors = allErrors.Any();
                evalResult.Errors    = allErrors;
            }

            if (resultSet)
            {
                evalResult.HasResult = true;
                evalResult.Result    = result;
            }

            //process the input for code completion later on
            if (!evalResult.HasErrors)
            {
                codeCompletion.ProcessInput(input, sourceFile);
            }

            OnEvaluateCompleted(new EvaluateCompletedEventArgs(evalResult, null, false, null));
            return(evalResult);
        }