示例#1
0
 public void Handle(IncomingMessage message)
 {
     new Message
     {
         Text = string.Format("@{0} {1}", message.UserName, message.Text),
         Channel = message.ChannelName
     }.Send();
 }
        public void Handle(IncomingMessage message)
        {
            var verb = message.Text.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)[0];

            var msg = new Message(null, message.ChannelName);

            switch (verb.ToLower())
            {
                case "start":
                    _timers.AddOrUpdate(message.UserId, (uid) =>
                    {
                        var newWatch = new Stopwatch();
                        newWatch.Start();
                        msg.Text = string.Format("Started new timer for @{0}.", message.UserName);
                        return newWatch;
                    }, (uid, watch) =>
                    {
                        watch.Stop();
                        var newWatch = new Stopwatch();
                        newWatch.Start();
                        msg.Text = string.Format("Stopped at {0} and started new timer for @{1}.",watch.Elapsed.ToString("g"),message.UserName);
                        return newWatch;
                    });
                    break;
                case "stop":
                    Stopwatch currentWatch = null;
                    if (_timers.TryGetValue(message.UserId, out currentWatch))
                    {
                        currentWatch.Stop();
                        msg.Text = string.Format("Timer stopped at {0} for @{1}.", currentWatch.Elapsed.ToString("g"), message.UserName);
                    }
                    break;
                default:
                    msg = null;
                    break;
            }

            if(msg != null)
                msg.Send();
        }