Exemplo n.º 1
0
        public static void Reset(TCPConnection conn, Quest quest)
        {
            AdvancedAnswerInfo ins = instance.Value;

            ins.quest      = quest;
            ins.connection = conn;
        }
Exemplo n.º 2
0
        public static TCPConnection TakeConnection()
        {
            AdvancedAnswerInfo ins  = instance.Value;
            TCPConnection      conn = ins.connection;

            ins.connection = null;
            return(conn);
        }
Exemplo n.º 3
0
        public static bool Answered()
        {
            AdvancedAnswerInfo ins = instance.Value;
            bool answered          = ins.connection == null;

            ins.connection = null;
            ins.quest      = null;
            return(answered);
        }
Exemplo n.º 4
0
        //----------------[ Quest & Answer Processing ]-----------------------//

        private void RunQuestProcessor(Quest quest, QuestProcessDelegate process)
        {
            TCPConnection conn = this;

            ClientEngine.RunTask(() => {
                Answer answer      = null;
                bool asyncAnswered = false;
                AdvancedAnswerInfo.Reset(conn, quest);

                try
                {
                    answer = process(connectionId, endpoint.ToString(), quest);
                }
                catch (Exception ex)
                {
                    if (errorRecorder != null)
                    {
                        errorRecorder.RecordError("Run quest process for method: " + quest.Method(), ex);
                    }
                }
                finally
                {
                    asyncAnswered = AdvancedAnswerInfo.Answered();
                }

                if (quest.IsTwoWay() && !asyncAnswered)
                {
                    if (answer == null)
                    {
                        answer = new Answer(quest);
                        answer.FillErrorInfo(ErrorCode.FPNN_EC_CORE_UNKNOWN_ERROR, "Two way quest " + quest.Method() + " lose an answer.");
                    }
                    SendAnswer(answer);
                }
                else
                {
                    if (answer != null)
                    {
                        if (errorRecorder != null)
                        {
                            if (quest.IsOneWay())
                            {
                                errorRecorder.RecordError("Answer created for one way quest: " + quest.Method());
                            }
                            else
                            {
                                errorRecorder.RecordError("Answer created reduplicated for two way quest: " + quest.Method());
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 5
0
        public static bool SendAnswer(Answer answer)
        {
            TCPConnection conn = AdvancedAnswerInfo.TakeConnection();

            if (conn != null)
            {
                conn.SendAnswer(answer);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        public static AsyncAnswer Create()
        {
            AdvancedAnswerInfo info = AdvancedAnswerInfo.Get();

            if (info.connection == null)
            {
                return(null);
            }

            AsyncAnswer async = new AsyncAnswer();

            async.connection = info.connection;
            async.quest      = info.quest;

            info.connection = null;
            return(async);
        }