Пример #1
0
        static void Main(string[] args)
        {
            // This application demostrate the basics of ConsoleAsync

            // Create forst console
            IConsole console = ConsoleAsync.CreateConsole("Console");

            // Add commands
            console.AddCommand("quit", (writer, strings) => ConsoleAsync.Quit());
            console.AddCommand("print", (writer, strings) => strings.ForEach(s => writer.Text(s).NewLine()));

            // Execute operation on console
            console.Execute(writer =>
            {
                writer.Info("ConsoleAsync").NewLine().NewLine();
                writer.Text(@"
Available commands:

quit   : close entirely the app
print  : print in console all the arguments
").NewLine();
            });

            // Wait commands from user
            ConsoleAsync.Run();
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Create first console
            IConsole menuConsole = ConsoleAsync.CreateConsole(systemConsoleName);

            // Create a key filter for every key pressed in app
            menuConsole.AddKeyFilter((writer, info) =>
            {
                string ch = info.KeyChar.ToString(CultureInfo.InvariantCulture);

                // check if the cher is a valid commend, then refresh menu
                if (EvaluateCommand(writer, ch))
                {
                    WriteMenu(writer);
                }

                // return true only if char NOT in available chars
                // input row remains empty
                return(ConsoleAsync.AvailableInputChars.Contains(ch));
            });

            menuConsole.Execute(WriteMenu);

            ConsoleAsync.Run();
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Initialize worker collection
            workers = new List <TestWorker>();

            // create control console
            CreateControlConsole();

            // Create variuos worker console
            CreateWorkerConsole("First Worker", TimeSpan.FromMilliseconds(550), .5);
            CreateWorkerConsole("Second Worker", TimeSpan.FromMilliseconds(800), .3);
            CreateWorkerConsole("Third Worker", TimeSpan.FromMilliseconds(1100), .7);

            // Wait for user input, the true parameter starts every worker in every console
            ConsoleAsync.Run(true);
        }
Пример #4
0
        static void Main(string[] args)
        {
            // Create console
            IConsole console = ConsoleAsync.CreateConsole("Folder Browser");

            // Add quit command to console
            ConsoleAsync.AddCommandToAllConsole("quit", (writer, strings) => ConsoleAsync.Quit());

            // Add help command to console
            console.AddCommand("help", (writer, strings) => writer.Text(@"
Switch to second console with TAB button
the available command are:

dir                          show content of a current directory
cd ..                        back to parent directory
cd <directory name>          enter in specified directory
md <directory name>          create a directory
rd <directory name>          delete a directory
").NewLine().NewLine());

            // Add cd commands to console
            console.AddCommand("cd", (writer, strings) =>
            {
                // check if there at least one parameter
                if (strings.Count > 0)
                {
                    ChangeFolder(writer, strings[0]);
                }
            });

            // Add cd.. commands to console
            console.AddCommand("cd..", (writer, strings) => ChangeFolder(writer, ".."));

            // Add cd commands to console
            console.AddCommand("dir", (writer, strings) => WriteFolder(writer));

            // Add md commands to console
            console.AddCommand("md", (writer, strings) =>
            {
                // check if there at least one parameter
                if (strings.Count < 1)
                {
                    // If not throw an exception
                    WriteError(writer, new ArgumentException("makedir require a parameter"));
                    return;
                }

                try
                {
                    // Try to create directory with passed parameter
                    Directory.CreateDirectory(Path.Combine(actualFolder, strings[0]));
                    writer.Info("Directory created").NewLine();
                }
                catch (Exception ex)
                {
                    // Write exception
                    WriteError(writer, ex);
                }
            });

            console.AddCommand("rd", (writer, strings) =>
            {
                // check if there at least one parameter
                if (strings.Count < 1)
                {
                    // If not throw an exception
                    WriteError(writer, new ArgumentException("removedir require a parameter"));
                    return;
                }

                try
                {
                    // Try to delete directory with passed parameter
                    Directory.Delete(Path.Combine(actualFolder, strings[0]));
                    writer.Info("Directory deleted").NewLine();
                }
                catch (Exception ex)
                {
                    // Write exception
                    WriteError(writer, ex);
                }
            });

            // Call an execute to write initial message to console
            console.Execute(writer =>
            {
                writer.Info("Folder Explorer sample").NewLine().NewLine();
                console.SendCommand("help");
            });

            // Wait for user commands
            ConsoleAsync.Run();
        }