示例#1
0
文件: Main.cs 项目: txdv/ircbotdotnet
        public static void Main(string[] args)
        {
            var client = new UVIrcClient();
            var bot = new IrcBot<UVIrcClient>(client);
            bot.Client.Connect("127.0.0.1", new IrcUserRegistrationInfo() {
                NickName = "txdv-bot",
                UserName = "******",
                RealName = "txdv bot",
            });

            var adminPlugin = new AdminPlugin<UVIrcClient>("bentkus");

            bot.Plugin(adminPlugin);
            bot.Plugin(new Greeter<UVIrcClient>());
            bot.Plugin(new DatabasePlugin<UVIrcClient>(adminPlugin));
            bot.Plugin(new JoinPlugin<UVIrcClient>(adminPlugin));

            UVTimer.Once(TimeSpan.FromSeconds(1), () => client.Channels.Join("#help"));

            var stdin = new TTY(0);
            stdin.Read(Encoding.Default, (line) => {
                line = line.Trim();
                switch (line) {
                case "quit":
                    Loop.Default.Stop();
                    break;
                default:
                    break;
                }
            });
            stdin.Resume();

            Loop.Default.Run();
        }
示例#2
0
		public static void Main(string[] args)
		{
			var stdin = new TTY(0);
			stdin.Read(Encoding.ASCII, (str) => {
				str = str.TrimEnd(new char[] { '\r', '\n' });
				if (str.StartsWith("fib ")) {
					int n;
					if (!int.TryParse(str.Substring("fib ".Length), out n)) {
						Console.WriteLine("Supply an integer to the fib command");
						return;
					}
					TimeSpan span = TimeSpan.Zero;
					BigInteger res = 0;
					Console.WriteLine("{0}: fib({1}) starting", span, n);
					Loop.Default.QueueUserWorkItem(() => {
						var stopwatch = Stopwatch.StartNew();
						res = Fibonacci(n);
						stopwatch.Stop();
						span = stopwatch.Elapsed;
					}, () => {
						Console.WriteLine("{0}: fib({1}) = {2}", span, n, res);
					});
				} else if (str == "quit") {
					Loop.Default.Stop();
					stdin.Close();
				} else if (str == "help") {
					Console.WriteLine("Available commands: ");
					Console.WriteLine("fib <n:int> - start a thread which calculates fib");
					Console.WriteLine("help - displays help");
					Console.WriteLine("quit - quits the program");
				} else {
					Console.WriteLine("Unknown command");
				}
			});
			stdin.Resume();
			Loop.Default.Run();
		}
示例#3
0
		public static void Main(string[] args)
		{
			Loop.Default.Run(async () => {
				var jobs = new LinkedList<Job>();
				var stdin = new TTY(0);
				string str = null;
				while ((str = await stdin.ReadStringAsync()) != null) {
					str = str.TrimEnd(new char[] { '\r', '\n' });
					if (str == "quit") {
						Loop.Current.Stop();
						break;
					} else if (str.StartsWith("fib ")) {
						int n;
						if (!int.TryParse(str.Substring("fib ".Length), out n)) {
							Console.WriteLine("Supply an integer to the fib command");
							continue;
						}
						TrackCalculateFibonacci(jobs, n);
					} else if (str == "help") {
						Console.WriteLine("Available commands: ");
						Console.WriteLine("fib <n:int> - start a thread which calculates fib");
						Console.WriteLine("help - displays help");
						Console.WriteLine("quit - quits the program");
					} else if (str == "count") {
						Console.WriteLine("Total jobs: {0}", jobs.Count);
						int i = 0;
						foreach (var job in jobs) {
							var awaiter = job.Task.GetAwaiter();
							Console.WriteLine("{0}: {1} {2} {3}", i, job.StartTime, job.TimeRunning, job.Task.Status);
							i++;
						}
					} else {
						Console.WriteLine("Unknown command");
					}
				}
			});
		}