ConsoleTool

Unofficial Content

The ConsoleTool GXextensions SDK sample uses the GeneXus BL (Business Logic) to connect to a Knowledge Base and lists Transaction names.

You can use this sample to get started with the SDK exploration.

The main program details the following:

static CommandParser cmdParser = new CommandParser();
static void Main(string[] args)
{
    if (!cmdParser.ParseArguments(args))
        return;
    string kbPath = cmdParser.KB;
    if (!Directory.Exists(kbPath))
    {
        Console.WriteLine(Messages.CouldNotFindKbAt, kbPath);
        return;
    }
    StartGxBL();
    DoWork(kbPath);
}

The CommandParser class uses a GeneXus class to automatically parse command line arguments from the sample; the expected argument is to get the path for the desired KB to open, for example

/kb:C:\Models\Xev2\SampleKB

Once the parameter is validated the GeneXus BL will be started using the genexus.exe.config configuration, notice the 10ev2 version used; so you need to specify a Xev2 KB path:

private static void StartGxBL()
{
    string configurationFile = Path.Combine(AssemblyHelper.GetAssemblyDirectory(), "genexus.exe.config");
    ExceptionManager.ConfigurationFile = configurationFile;
    CacheManager.ConfigurationFile = configurationFile;
    PathHelper.SetAssemblyInfo("Artech", "Genexus", "10Ev2");
    Artech.Core.Connector.StartBL();
}

When the StartGxBL method finishes and returns to to the main method, the DoWork method is executed:

private static void DoWork(string kbPath)
{
    try
    {
        KnowledgeBase.OpenOptions options = new KnowledgeBase.OpenOptions(cmdParser.KB);
        options.EnableMultiUser = false;

        KnowledgeBase kb = KnowledgeBase.Open(options);
        KBModel model = kb.DesignModel;

        ListTransactions(model);
    }
    catch (Exception exception)
    {
        Console.Write(exception.Message);
    }
}

Notice it opens the KB using the cmdParser.KB argument; gets the design model and executes the ListTransactions method to display Transactions names on the output:

private static void ListTransactions(KBModel model)
{
    Console.WriteLine(Messages.Transactions);

    foreach (Transaction trn in Transaction.GetAll(model))
    {
        Console.WriteLine(Messages.TransactionLine, trn.Name);
    }
}

A sample execution could be the following:

Transactions:
   Invoice
   Customer
   Product

You can use this sample to explore some of the GeneXus SDK Classes related to the KnowledgeBase, KBModel, Transaction, KBObject classes from the SDK.