Friday, September 11, 2015

ActiveNav Extensions

I'll be out of communication when this goes live - this post is pre-scheduled.

ActiveNav, the command-line Active Directory browser, is extensible; third parties can write DLLs that interact with it and/or the user after being loaded with the "dll" command. This post is a reference for the extension API.

Extensions must be .NET class libraries referencing ActiveNav.exe and containing exactly one type that implements IActiveNavExtension and has a public parameterless constructor. After being constructed, the object will receive an IActiveNavExtension.Load(IActiveNav) call containing an ActiveNav controller object. IActiveNav has the following methods:

  • WriteLine(String) writes some text to the console window and to the transcript file if there is one. Use this instead of Console.WriteLine.
  • SetListener(IActiveNavExtension) causes all text that would be sent to the screen or to the transcript to be first send to the provided extension (usually the calling one) via an IActiveNavExtension.ListenerLine(String) call. Returning True from that function prevents the line from being printed. Only one extension can be the listener at a time, and the listener is cleared after each command finishes.
  • PushCommand(String) enqueues the given string as a command to be executed after the current command and any other auto-commands are finished.
  • RegisterCommand(String, Command) associates the given Command object with the given command name.
IActiveNav has the following events, which can be hooked in the IActiveNavExtension.Load method:
  • Exiting() is raised when the user issues the "exit" command. It is usually not raised when the command window containing ActiveNav is closed.
  • CommandString(String, ByRef Handled) is raised when the user enters some text as a command. If Handled is True when ActiveNav regains control, no attempt is made to interpret the text as an ActiveNav command. (It is assumed that the extension did something useful.)
  • CommandParsed(String, String(), ByRef Handled) is raised after the desired command (whose name is the first parameter) is identified but before it is invoked. The second parameter (the string array) is the array of arguments that would be passed to the command. Setting Handled to True causes ActiveNav to cancel the processing of the command.
  • CommandExecuting(String, String()) is raised after it is confirmed that the command will execute as a normal ActiveNav command but before any execution actually happens.
  • CommandFinished(String, String()) is raised after the given command is completed with the given arguments.
Adding new commands is done by inheriting Command, which has only two members:
  • Description (read-only property as String) is used to describe the command in the listing provided by the "help" command.
  • Run(String()) is invoked when the user runs the command with the given set of arguments.
Implementing IHelpSupport, while not required, allows the "help" command to give more detailed information on the command:
  • Arguments (read-only property as List(Of Tuple(Of String, String))) should be a collection of command arguments (the first entry in the tuple) and their respective description (the second entry).

No comments:

Post a Comment