Creating your imbACE Console Application

Introduction

The imbACE framework is all about rapid console tool applications development. The project’s goal is to provide completely automated UI/TUI/GUI generation, for multiple platforms – using data annotation and meta information from your IAceAdvancedConsole implementations. The consoles are execution context classes, where the ACE Script Operations (methods, that are interpreted also as ACE Script command) are the main construction blocks. The concept is: you should code only your scientific contribution, wasting no time on the interface and reporting side of the project. This, of course, means, constrained design of the User Interface and/or other outputs. The framework is made for scientists, researchers and technical professionals, that need custom software tools for their specific tools but can’t care less to design and packaging of the tool.

Learn more:


Tutorial: Creating imbACE Console Application

In this tutorial we will:

  1. Create a imbACE Console Application project, using template, and configure it for first build
  2. Add an ACE Script Operation, that prints “Hello World!”
  3. Demonstrate basic user input prompts

Let’s start!

1. Create new Project

using [imbACE Console Application multi-target] project template, that you’ll find under imbACE template folder. This tutorial assumes that:

imbACE Console Application Template

Name the project “MyConsole” and confirm.

MyConsole ConsoleApplication project

 

1.b Update NuGet packages

Right click on the Project > Manage NuGet Packages for the project

Update NuGet Package – imbACE.Services

imbACE.Services.Standard is the top layer of imbACE application framework. Whatever is the current version, install the latest package available.

2. Let’s review the project files

In directory console, we have three classes, “aceAdvancedConsole bundle” (btw. you can create new bundle using “Advanced Console bundle” Item Template):

  • CommandConsoleState : aceAdvancedConsoleStateBase
    • The State object keeps current and temporary data about Console‘s operation. If the Console was closed regularly, the State is saved automatically and loaded back once a console of same Type is loaded (in future, it will require sessionID as Consoles will have multi-user capability, i.e. server/client architecture).
namespace MyConsole.console
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using imbACE.Services.console;

    // place here properties with data you want to preserve during and between the sessions/app. runs

    public class CommandConsoleState:aceAdvancedConsoleStateBase
    {
        public CommandConsoleState()
        {

        }
    }
}
  • CommandConsoleWorkspace : aceAdvancedConsoleWorkspace
    • The Workspace provides access to permanent data storage, reserved for that Console implementation class (Type). Using Workspace, the Console can save or load ACE Scripts, different resources and keeep its “personal” data cache or repository.
using imbACE.Services.console;

public class CommandConsoleWorkspace : aceAdvancedConsoleWorkspace
{

    /// <summary>
    /// Initializes the workspace for the MyConsole console 
    /// </summary>
    /// <param name="console">The console using this workspace</param>
    public CommandConsoleWorkspace(CommandConsole console) : base(console)
    {

    }

    // public folderNode folderName {get; set;} // <---- uncomment if you have need for additional subdirectory in the console state project folder


    /// <summary>
    /// Gets called during workspace construction, the method should initiate any additional subdirectories that console's project uses
    /// </summary>
    public override void setAdditionalWorkspaceFolders()
    {
        // place here your additional directories for console's project subdirectory as follows:
        // folderName = folder.Add(nameof(folderName), "Caption", "Description");
    }
}
  • CommandConsole : aceAdvancedConsole<CommandConsoleState, CommandConsoleWorkspace>
    • The Console (inheriting: aceAdvancedConsole) type is bound, via generic type parameters, to its (dedicated) State and Workspace. Normally, one instance of Console, has only one State and Workspace at the time.
namespace MyConsole.console
{
    using imbACE.Services.console;
    public class CommandConsole : aceAdvancedConsole<CommandConsoleState, CommandConsoleWorkspace>
    {
        public override string consoleTitle { get { return "MyConsole Console"; } }
        public CommandConsole() : base()
        {


        }
        /// <summary>
        /// Gets the workspace.
        /// </summary>
        /// <value>
        /// The workspace.
        /// </value>
        public override CommandConsoleWorkspace workspace
        {
            get
            {
                if (_workspace == null)
                {
                    _workspace = new CommandConsoleWorkspace(this);
                }
                return _workspace;
            }
        }
        public override void onStartUp()
        {
            //
            base.onStartUp();
        }
  
        protected override void doCustomSpecialCall(aceCommandActiveInput input)
        {

        }
    }
}
  • MyConsoleApplication:ConsoleApplication:aceConsoleApplication<CommandConsole>
    • On top of hierarchy is Application<Console> (single) instance, automatically constructed with start of the application.  Although, one application can host multiple Console instances and multiple Console Types, the Main Console (class) is the one provided via generic type parameter.

 

Relationship between the declared types

namespace MyConsole
{

    using imbACE.Core.application;
    using imbACE.Services.application;
    using MyConsole.console;
    
    public class ConsoleApplication : aceConsoleApplication<CommandConsole>
    {

        public static void Main(string[] args)
        {
            var application = new ConsoleApplication();

            application.StartApplication(args);

            // here you may place code that has to be performed after user called application termination
            // ...
        }


        public override void setAboutInformation()
        {
            // Insert proper information here
            appAboutInfo = new aceApplicationInfo(); // parametarless constructor takes values from Assembly attributes 
            appAboutInfo.license = "Licensed under GNU General Public License v3.0";
            appAboutInfo.welcomeMessage = "imbACE Console Tool";
        }
    }
}

 

The structure of imbACE Console Application – main classes of our concert are: Application, Console, its Workspace and State.

Enable Windows Console Application

In Project .csproj file, you’ll find disabled block, that sets MSBuild to create Windows Console Application exe. Remove comment tags and run Debug

<PropertyGroup>
  <!-- The node below enables XML documentation build, in all build (Debug,Release) configurations-->
  <DocumentationFile>$(OutputPath)$(PackageId).xml</DocumentationFile>
  <!-- Uncomment the block below to build Console Application and not just library/package -->
  <OutputType>WinExe</OutputType>
  <StartupObject>MyConsole.MyConsoleApplication</StartupObject>
</PropertyGroup>

(btw. you could set Windows Application build from GUI but… this was fun)

 

Elements:

  • Application (ConsoleApplication:IAceAd

Ignore the error message
(in progress)

 

  • Creating your imbACE Advanced Console Plugin
  • Using data annotation to export collection of objects to Excel and CSV files
  • Using other snippets and templates

 

Spread the love