|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace PossibleSolution
{
class Program
{
static void printCounters1()
{
Console.WriteLine("Printing first counters");
}
static void printCounters2()
{
Console.WriteLine("Printing second counters");
}
static void printHelp()
{
Console.WriteLine("Supported: stop, print first counters (pfc), print second counters (psc)");
}
static void Main(string[] args)
{
Dictionary<string, string> domain = new Dictionary<string, string> { { "first", "value 1" }, { "second", "value 2" } };
bool shouldfinish = false;
ConsoleCommandHolder holder = new ConsoleCommandHolder();
holder.AddRange( new ConsoleCommand[]{ new SimpleCommand("Stop application", new string[]{"stop"},
(x)=>
{
Console.WriteLine("Do you really want to stop? (type 'yes' to stop)");
string acceptString = Console.ReadLine();
if (acceptString == "yes")
{
shouldfinish = true;
}
}),
new SimpleCommand("Print first command", new string[]{"print first command", "pfc"},(x)=>printCounters1() ),
new SimpleCommand("Print second command", new string[]{"print second command", "psc"},(x)=>printCounters2() ),
new SimpleCommand("Print dictionary", new string[]{"print dictionary", "pd"},
(x)=>
{
foreach (var next in domain)
Console.WriteLine("{0} -> {1}", next.Key, next.Value);
}),
new AddCommand(domain),
});
while (shouldfinish == false)
{
string command = Console.ReadLine();
ConsoleCommand toExecute = holder.Find(command);
if(toExecute != null)
toExecute.Do(command);
else Console.WriteLine(holder);
}
Console.WriteLine("Disposing domain and stopping");
Console.ReadKey();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.