Exemplo n.º 1
0
 void OnDisconnectCallback(Connection conn)
 {
     log.InfoFormat("Connection {0} disconnected", conn.GetType().Name);
 }
Exemplo n.º 2
0
 void OnSendMessageCallback(Connection conn, InstantMessage im)
 {
     log.InfoFormat("OUTMSG ({0}) {1}: {2}", conn.GetType().Name, im.User, im.Text);
 }
Exemplo n.º 3
0
        public void OnMessageCallback(Connection conn, InstantMessage im)
        {
            lock (this)
            {
                log.InfoFormat("INMSG ({0}) << {1}: {2}", conn.GetType().Name, im.User, im.Text);

                DateTime dtStart = DateTime.Now;

                try
                {
                    ResponseChannel = new ResponseChannel(im.User, conn);

                    VBotService.RequestResult result = BotService.Instance.WhoAmI(BotService.Credentialize(ResponseChannel));
                    if (result.Code == 0)
                    {
                        LocalUser user = LocalUser.GetUser(ResponseChannel, result.RemoteUser);

                        #region if

                        if (_inputs.ContainsKey(user.LocalUserID) && _inputs[user.LocalUserID].State == InputStateEnum.Waiting)
                        { // waiting for input?

                            InputState ist = new InputState(InputStateEnum.Responded);
                            ist.PageText = im.Text;
                            _inputs[user.LocalUserID] = ist;
                        }
                        else
                        { // the user is at the 'main menu'

                            Result lastRes = new Result();
                            string[] strCommands = Regex.Split(im.Text, @"\;");

                            foreach (string strCommand in strCommands)
                            {
                                lastRes = DoCommand(strCommand, user);

                                if (lastRes.Code != ResultCode.Success)
                                {
                                    break;
                                }
                            }

                            if (lastRes != null && (lastRes.Code == ResultCode.Success || lastRes.Code == ResultCode.Error))
                            {
                                conn.SendMessage(new InstantMessage(im.User, lastRes.Message));
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        log.ErrorFormat("GetUser failed: {0}", result.Text);
                        ResponseChannel.SendMessage(ResponseChannel.FetchTemplate(result.Text));
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Something bad",ex);
                }

                if (log.IsDebugEnabled)
                {
                    TimeSpan elapsed = DateTime.Now - dtStart;

                    log.InfoFormat("Response Time: {0}.{1} seconds",elapsed.Seconds, elapsed.Milliseconds);
                }
            }
        }