Esempio n. 1
0
    public void NoCommand()
    {
      var ctx = new Mod.Context();
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.Empty);
    }
Esempio n. 2
0
    public void CommandSingleNumberedParameter()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("cd luna");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(ctx.CurrentItem.ID, Is.EqualTo(_testContent.Axes.GetChild("Luna").ID));
    }
Esempio n. 3
0
    public void CommandMultipleNumberedParameters()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("find pwd luna");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Contains.Substring("Carme"));
      Assert.That(result.Message, Contains.Substring("Ganymede"));
      Assert.That(result.Message, Contains.Substring("Metis"));
    }
Esempio n. 4
0
    public void CommandSingleNamedParameter()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("ls -r os");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.Not.Contains("Luna"));
      Assert.That(result.Message, Contains.Substring("Deimos"));
      Assert.That(result.Message, Contains.Substring("phobos"));
      Assert.That(result.Message, Contains.Substring("Adrastea Phobos"));
    }
Esempio n. 5
0
    protected override void OnLoad(EventArgs e)
    {
      base.OnLoad(e);

      var persistContext = Settings.GetBoolSetting("Revolver.PersistContextOnDisk", true);

      NameValueCollection parameters = null;
      string sessionId = string.Empty;

      if (Sitecore.Context.ClientPage.IsEvent)
      {
        var rawParameters = Sitecore.Context.ClientPage.ClientRequest.Parameters;
        if (rawParameters.StartsWith("r:"))
          rawParameters = rawParameters.Remove(0, 2);

        parameters = StringUtil.ParseNameValueCollection(rawParameters, '&', '=');
        sessionId = parameters["sessionId"];
      }

      if (string.IsNullOrEmpty(sessionId))
      {
        sessionId = Guid.NewGuid().ToString();
        hdnSessionId.Value = sessionId;
      }

      _commandHandler = GetCommandHandler(sessionId);

      CommandResult result = null;

      if (_commandHandler != null)
      {
        if (persistContext)
        {
          var persistedContext = GetRevolverContext(sessionId);
          if (persistedContext != null)
            _commandHandler.Context = persistedContext;
        }

        if (Sitecore.Context.ClientPage.IsEvent)
        {
          var commandText = Sitecore.Context.ClientPage.Server.UrlDecode(parameters["command"]);
          result = Execute(commandText);
        }
        else
        {
          ExecuteStartup();

          // Display command prompt to user
          prompt.InnerHtml = PrintCommandPrompt();

          if (persistContext)
            PersistRevolverContext(sessionId, _commandHandler.Context);

          return;
        }
      }

#if SC62
      var jsonOutput = Newtonsoft.Json.JavaScriptConvert.SerializeObject(new
#else
      var jsonOutput = Newtonsoft.Json.JsonConvert.SerializeObject(new
#endif
        {
          prompt = PrintCommandPrompt(),
          outputBuffer = _commandHandler != null ? _commandHandler.Context.EnvironmentVariables["outputbuffer"] : null,
          output = result.Message,
          exit = result.Status == CommandStatus.Abort ? "true" : null,
          error = result.Status != CommandStatus.Success ? result.Message : null
        });
  
      SheerResponse.SetReturnValue(jsonOutput);

      if (persistContext)
        PersistRevolverContext(sessionId, _commandHandler.Context);
    }
Esempio n. 6
0
    public void CommandMixedParameterTypes()
    {
      var deimosId = _testContent.Axes.GetChild("Deimos").ID.ToString();
      var phobosId = _testContent.Axes.GetChild("phobos").ID.ToString();

      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute(string.Format("find -i {0}|{1} -a name phobos -ns (ga -a id)", deimosId, phobosId));

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(phobosId));
    }
Esempio n. 7
0
    public void AddAliasSameAsAlias()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());

      handler.AddCommandAlias("aa", "ls");

      var result = handler.AddCommandAlias("aa", "ga");
      Assert.That(result.Status, Is.EqualTo(CommandStatus.Failure));
    }
Esempio n. 8
0
    public void EscapedParameterDelimiter()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("echo lorem \\(ipsum dolor\\)");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo("lorem (ipsum dolor)"));
    }
Esempio n. 9
0
    public void AddAliasWithParameters()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());

      var result = handler.AddCommandAlias("aa", "ls", "-a", "-d");
      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));

      // Verify the alias was added
      var exResult = handler.Execute("aa");
      Assert.That(exResult.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(exResult.Message, Contains.Substring("  phobos\r\n+ Luna\r\n  Deimos\r\n  Adrastea Phobos"));
    }
Esempio n. 10
0
    public void MultipleCommandChaining()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("ga -a name > replace $~$ B c -c > split -s h $~$ (echo $current$)");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success), result.Message);
      Assert.That(result.Message, Contains.Substring("ceb"));
      Assert.That(result.Message, Contains.Substring("ionn"));
    }
Esempio n. 11
0
    public void CommandChaining()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("ga -a name > replace $~$ B c -c");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success), result.Message);
      Assert.That(result.Message, Is.EqualTo("cebhionn"));
    }
Esempio n. 12
0
    public void MultipleSubCommands()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("replace < (ga -a name) B < (echo c) -c");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo("cebhionn"));
    }
Esempio n. 13
0
    public void CommandFlagParameter()
    {
      var ctx = new Mod.Context();
      ctx.CurrentItem = _testContent;
      var handler = new Mod.CommandHandler(ctx, new TextOutputFormatter());
      var result = handler.Execute("ls -a -d");

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo("  phobos\r\n+ Luna\r\n  Deimos\r\n  Adrastea Phobos"));
    }
Esempio n. 14
0
    public CommandResult ExecuteCommand(string commandLine, ICommandFormatter formatter)
    {
      if (_commandHandler == null)
        _commandHandler = new CommandHandler(this, formatter);

      return _commandHandler.Execute(commandLine);
    }