static void CreateWorkerConsole(string name, TimeSpan interval, double margin) { // Create console IConsole console = ConsoleAsync.CreateConsole(name); // Create new instance of worker TestWorker worker = new TestWorker(interval, console.Name, margin); // Add worker to collection workers.Add(worker); // Add worker to newly created console IConsoleWorker workerInterface = console.AddWorker(worker); // Add command suspend console.AddCommand("suspend", (writer, list) => { // Suspend worker and write a message workerInterface.Suspend(); writer.Info("Worker suspended").NewLine(); }); // Add command resume console.AddCommand("resume", (writer, list) => { // Resume worker and write a message workerInterface.Resume(); writer.Info("Worker resumed").NewLine(); }); // Add command quit console.AddCommand("quit", (writer, list) => ConsoleAsync.Quit()); }
static void CreateControlConsole() { // Define an interval TimeSpan interval = TimeSpan.FromMilliseconds(500); // Create the console IConsole control = ConsoleAsync.CreateConsole("Control Console"); // Add quit command control.AddCommand("quit", (writer, list) => ConsoleAsync.Quit()); // Create worker from builtin type TimedWorker ConsoleWorker controlWorker = new TimedWorker(interval, (writer, span) => { // Clear console and write title and info writer.Clear(); writer.Info("CONTROL CONSOLE").NewLine(); writer.Muted("Elapsed: {0}", span).NewLine().NewLine(); // Cicle workers foreach (TestWorker worker in workers) { // Calculate percentage of success over 60 characters int success = (60 * worker.Successes + 1) / (worker.Successes + worker.Failures + 1); int failure = 60 - success; // Write worker name fitted on 16 char (to make bars aligned) writer.Text(worker.Name.Fit(16)); // Write success bar writer.Success("".Fit(success, '\u25A0')); // Write error bar writer.Error("".Fit(failure, '\u25A0')); writer.NewLine(); } // Write a message and commands help writer.NewLine().NewLine().NewLine().Info("Available commands").NewLine(); writer.Text(@" suspend : suspend worker (not in control console) resume : resume worker (not in control console) quit : close application (in any console) "); }); // Add worker to control console control.AddWorker(controlWorker); }