Пример #1
0
        public void ProcessEvaluateResponseWithReferenceError()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()));
            const string expression      = "hello";
            var          stackFrame      = new NodeStackFrame(0);
            var          evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame);
            Exception    exception       = null;

            // Act
            try
            {
                evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponseWithReferenceError());
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(DebuggerCommandException));
            Assert.AreEqual("ReferenceError: hello is not defined", exception.Message);
            Assert.IsNull(evaluateCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Never);
        }
Пример #2
0
        internal IEvaluateResult Evaluate(string expr, int?frameId, string context = "repl")
        {
            var cmd = new EvaluateCommand(expr, context, frameId);

            Session.Evaluate(cmd);
            return(cmd.Result);
        }
Пример #3
0
 public Task <ICommandResponse <EvaluateCommand> > EvaluateCommand(EvaluateCommand command)
 {
     return(Task.FromResult <ICommandResponse <EvaluateCommand> >(new EvaluateCommandResponse
     {
         Result = Evaluate(command.Expression)
     }));
 }
Пример #4
0
        public InteractiveConsole()
        {
            _commands              = new Dictionary <string, ICommand>();
            _commands["help"]      = new HelpCommand(this, _commands);
            _commands["magic"]     = new MagicCommand(this);
            _commands["aperft"]    = new AdvancedPerftCommand(this);
            _commands["dperft"]    = new DividedPerftCommand(this);
            _commands["perft"]     = new SimplePerftCommand(this);
            _commands["benchmark"] = new BenchmarkCommand(this);
            _commands["verify"]    = new VerifyCommand(this);
            _commands["evaluate"]  = new EvaluateCommand(this);
            _commands["tuner"]     = new TunerCommand(this);
            _commands["uci"]       = new UciCommand(this);
            _commands["quit"]      = new QuitCommand(this);

            _symbols = new List <string> {
                "%", "s", "ns", "MN/s", "ML/s"
            };

            _keywordColor = ConsoleColor.Cyan;
            _moveColor    = ConsoleColor.Red;
            _numberColor  = ConsoleColor.Yellow;
            _symbolColor  = ConsoleColor.Yellow;

            CultureInfo.CurrentCulture = new CultureInfo("en-US", false);
        }
Пример #5
0
        public void CreateEvaluateCommandWithVariableId()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();
            const int variableId        = 2;

            // Act
            var evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, variableId);

            // Assert
            Assert.AreEqual(commandId, evaluateCommand.Id);
            Assert.AreEqual(
                string.Format(
                    "{{\"command\":\"evaluate\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"expression\":\"variable.toString()\",\"frame\":0,\"global\":false,\"disable_break\":true,\"additional_context\":[{{\"name\":\"variable\",\"handle\":{1}}}],\"maxStringLength\":-1}}}}",
                    commandId, variableId),
                evaluateCommand.ToString());
        }
Пример #6
0
        public void CreateEvaluateCommand()
        {
            // Arrange
            const int    commandId         = 3;
            var          resultFactoryMock = new Mock <IEvaluationResultFactory>();
            const string expression        = "expression";

            // Act
            var evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression);

            // Assert
            Assert.AreEqual(commandId, evaluateCommand.Id);
            Assert.AreEqual(
                string.Format(
                    "{{\"command\":\"evaluate\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"expression\":\"{1}\",\"frame\":0,\"global\":false,\"disable_break\":true,\"maxStringLength\":-1}}}}",
                    commandId, expression),
                evaluateCommand.ToString());
        }
Пример #7
0
        public void ProcessEvaluateResponse()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            const string expression      = "expression";
            var          stackFrame      = new NodeStackFrame(0);
            var          evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame);

            // Act
            evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponse());

            // Assert
            Assert.AreEqual(commandId, evaluateCommand.Id);
            Assert.IsNotNull(evaluateCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Once);
        }
Пример #8
0
        /// <summary>
        /// Sends the specified command to MediaNMonkey and returns the associated command response.</summary>
        /// <param name="command">The command expression to send to MediaMonkey.</param>
        public async Task <EvaluateCommandResponse> SendCommandAsync(string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (mmSession is null)
            {
                throw new NullReferenceException("No active MediaMonkey session found.");
            }

            var cmd = new EvaluateCommand()
            {
                ObjectGroup           = "console",
                IncludeCommandLineAPI = true,
                ReturnByValue         = true,
                AwaitPromise          = true,
                Silent     = false,
                Expression = command
            };

            return(await mmSession.SendCommand(cmd).ConfigureAwait(false) as EvaluateCommandResponse);
        }
Пример #9
0
        public bool Eval(out ICommandResponse rsp, string cmd)
        {
            EvaluateCommand parameter = EvaluateCommand.Create(cmd);

            return(this.SendCommandSafe <EvaluateCommand>(out rsp, parameter));
        }
Пример #10
0
        public static void Main(string[] args)
        {
            //DateTime now = DateTime.Now;
            args = @"simulate -b 5 -n 1 -t rel -i ..\..\..\etc\$$year$$-runs.txt -j ..\..\..\etc\$$year$$-judgments.txt -e mout -p meta=..\..\..\etc\metadata.txt".Replace("$$year$$", args[0]).Split();

            if (args.Length > 0)
            {
                // Check CLI command name
                string          commandName = args[0].ToLower();
                AbstractCommand command     = null;
                switch (commandName)
                {
                case "-h":
                    Allcea.PrintMainUsage(null);
                    Environment.Exit(0);
                    break;

                case "estimate": command = new EstimateCommand(); break;

                case "evaluate": command = new EvaluateCommand(); break;

                case "next": command = new NextCommand(); break;

                case "simulate": command = new SimulateCommand(); break;

                case "features": command = new FeaturesCommand(); break;

                default:
                    Console.Error.WriteLine("'" + commandName + "' is not a valid Allcea command. See '" + Allcea.CLI_NAME_AND_VERSION + " -h'.");
                    Environment.Exit(1);
                    break;
                }
                // Parse CLI options
                Options options = command.Options;
                // help? Cannot wait to parse CLI options because it will throw exception before
                if (options.HasOption("h") && args.Contains("-h"))
                {
                    Allcea.PrintUsage(null, commandName, options, command.OptionsFooter);
                }
                else
                {
                    try {
                        Parser      parser = new BasicParser();
                        CommandLine cmd    = parser.Parse(options, args.Skip(1).ToArray());
                        // If we have extra CLI options the Parse method doesn't throw exception. Handle here
                        if (cmd.Args == null || cmd.Args.Length != 0)
                        {
                            throw new ParseException("Unused option(s): " + string.Join(",", cmd.Args));
                        }
                        // Run command
                        command.CheckOptions(cmd);
                        command.Run();
                    } catch (ParseException pe) {
                        Console.Error.WriteLine((pe.Message.EndsWith(".") ? pe.Message : pe.Message + ".")
                                                + " See '" + Allcea.CLI_NAME_AND_VERSION + " " + commandName + " -h'.");
                        Environment.Exit(1);
                    } catch (Exception ex) {
                        Console.Error.WriteLine(ex.Message);
                        Environment.Exit(1);
                    }
                }
            }
            else
            {
                // No CLI options
                Allcea.PrintMainUsage(null);
                Environment.Exit(1);
            }
            //Console.Error.WriteLine(DateTime.Now.Subtract(now).TotalMilliseconds);
        }